本帖最后由 战争傀儡阿格兰 于 2024-6-25 13:18 编辑
代码环境1.171。
【战团】阿格兰魔球修改器——合集https://bbs.mountblade.com.cn/thread-2097734-1-1.html
个人经验不足,若有错误感谢指正。
一旦你进入强盗老巢等场景,整个世界的代码由module_mission_templates接管,module_simple_triggers和module_triggers不起作用,其余文件零零散散地也开始生效。
module_mission_templates文件教程也不少。我争取讲的简单易懂点,首先是文件组成。
#每个任务模板都是一个元组,其中包含以下字段:
#1)任务模板id(字符串):id名字,随便起;
#2)任务模板标志(int):这个抄现成的,找准类似的就行;
#3)任务类型(int):这个抄现成的,找准类似的就行;
#4)任务描述文本(字符串):描述,随便编;
#5)派生记录列表(List):就是要生成的agent,或者叫npc,也是抄现成的;
#6)触发器列表(列表):这个是重点。类似于多功能螺丝刀,你配的螺丝刀头越多,这个螺丝刀的功能越多,比方能开酒瓶盖,能剪指甲。
这部分要有选择性地抄。我下面的分析,就像给你分析螺丝刀每个刀头是什么用处,比方这个刀头能开酒瓶盖,这个刀头能剪指甲。
但是只是告诉你功能,而不是逐行分析代码原理。就像我告诉你它能剪指甲,但是没有告诉你怎么去用铁造一对钳子,钳子合起来就能压断指甲。
总结:抄native类似的代码就行
举个强盗老巢"bandit_lair"的例子。这段代码的好处是,敌人不会立马进攻,很符合游戏副本的设定。我很喜欢,希望有人看到我的帖子,也弄个副本给我刷刷。
首先是对应上面第6条触发器的目录,触发器老外叫作triggers,汉字解释请百度,我把它类比成一个个螺丝刀头功能。怎么写触发器?也是抄抄native自带的,这个要找别人的教程了。
#触发器 头顶旗帜
#触发器 不可用物品栏
#触发器 agent生成的瞬间发布命令待在原地
#触发器 清完敌人,商人跑过来结束任务
#触发器 TAB键无法退出
#触发器 初始化增援阶段
#触发器 强盗agent的索敌代码#触发器 触发增援
#触发器 人倒了或伤了
#触发器 音乐触发器
#触发器 只剩一个队伍了(赢了)
#触发器 自带的战场地图,退格键那个
#触发器 玩家倒了,任务失败
(
"bandit_lair",mtf_battle_mode|mtf_synch_inventory,charge,
"Ambushing a bandit lair",
[
(0,mtef_team_0|mtef_use_exact_number,af_override_horse, aif_start_alarmed, 7,[]),
(1,mtef_visitor_source|mtef_team_1,af_override_horse, aif_start_alarmed,20,[]),
(2,mtef_visitor_source|mtef_team_1,af_override_horse, aif_start_alarmed,20,[]),
(3,mtef_visitor_source|mtef_team_1,af_override_horse, aif_start_alarmed,20,[]),
(4,mtef_visitor_source|mtef_team_1,af_override_horse, aif_start_alarmed,20,[]),
(5,mtef_visitor_source|mtef_team_1,af_override_horse, aif_start_alarmed,20,[]),
(6,mtef_visitor_source|mtef_team_1,af_override_horse, aif_start_alarmed,20,[]),
(7,mtef_visitor_source|mtef_team_1,af_override_horse, aif_start_alarmed,20,[]),
(8,mtef_visitor_source|mtef_team_1,af_override_horse, aif_start_alarmed,20,[]),
(9,mtef_visitor_source|mtef_team_1,af_override_horse, aif_start_alarmed,20,[]),
(10,mtef_visitor_source|mtef_team_1,af_override_horse, aif_start_alarmed,20,[]),
],
[
#触发器 头顶旗帜
common_battle_init_banner,
#触发器 不可用物品栏
common_inventory_not_available,
#触发器 agent生成的瞬间发布命令待在原地
(ti_on_agent_spawn, 0, 0, [],
[
(store_trigger_param_1, ":agent_no"),
(assign, "$relative_of_merchant_is_found", 0),
(try_begin),
(agent_is_human, ":agent_no"),
(agent_is_alive, ":agent_no"),
(agent_get_team, ":agent_team", ":agent_no"),
(eq, ":agent_team", 1),
(agent_get_position, pos4, ":agent_no"),
#这里是关键 为什么强盗会呆呆地等玩家冲过来再冲锋?是这一句起作用
(agent_set_scripted_destination, ":agent_no", pos4, 1),
(try_end),
#商人 似乎废弃了
(try_begin),
(agent_get_troop_id, ":troop_no", ":agent_no"),
(is_between, ":troop_no", "trp_relative_of_merchant", "trp_relative_of_merchants_end"),
(agent_set_team, ":agent_no", 7),
(team_set_relation, 0, 7, 0),
(try_end),
]),
#触发器 清完敌人,商人跑过来结束任务
(0, 0, 0,
[
(party_get_template_id, ":template", "$g_encountered_party"),
(eq, ":template", "pt_looter_lair"),
(check_quest_active, "qst_save_relative_of_merchant"),
(eq, "$relative_of_merchant_is_found", 0),
],
[
(get_player_agent_no, ":player_agent"),
(agent_get_position, pos0, ":player_agent"),
(try_for_agents, ":agent_no"),
(agent_get_troop_id, ":troop_no", ":agent_no"),
(is_between, ":troop_no", "trp_relative_of_merchant", "trp_relative_of_merchants_end"),
(agent_set_scripted_destination, ":agent_no", pos0),
(agent_get_position, pos1, ":agent_no"),
(get_distance_between_positions, ":dist", pos0, pos1),
(le, ":dist", 200),
#(assign, "$g_talk_troop", "trp_relative_of_merchant"),
(start_mission_conversation, "trp_relative_of_merchant"),
(try_end),
]),
#触发器 TAB键无法退出
(ti_tab_pressed, 0, 0,
[
(display_message, "str_cannot_leave_now"),
], []),
#触发器 初始化增援阶段
(1, 0, ti_once, [],
[
(assign, "$defender_reinforcement_stage", 0),
(assign, "$bandits_spawned_extra", 0),
]),
#触发器 强盗agent的索敌代码
(1, 0, 0, [],
[
(try_for_agents, ":bandit_id"),
(agent_is_alive, ":bandit_id"),
(agent_get_team, ":agent_team_1", ":bandit_id"),
(eq, ":agent_team_1", 1),
(agent_is_in_special_mode, ":bandit_id"),
(agent_is_human, ":bandit_id"),
(agent_get_position, pos0, ":bandit_id"),
(try_for_agents, ":player_team_agent_id"),
(agent_is_alive, ":player_team_agent_id"),
(agent_get_team, ":agent_team_2", ":player_team_agent_id"),
(eq, ":agent_team_2", 0),
(agent_is_human, ":player_team_agent_id"),
(store_agent_hit_points, ":bandit_hit_points", ":bandit_id"),
(assign, ":continue", 0),
(try_begin),
(lt, ":bandit_hit_points", 100),
(try_for_agents, ":bandit_2_id"),
(agent_is_alive, ":bandit_2_id"),
(agent_get_team, ":bandit_2_team", ":bandit_2_id"),
(eq, ":bandit_2_team", 1),
(neq, ":bandit_id", ":bandit_2_id"),
(agent_is_in_special_mode, ":bandit_2_id"),
(agent_is_human, ":bandit_2_id"),
(agent_get_position, pos1, ":bandit_id"),
(agent_get_position, pos2, ":bandit_2_id"),
(get_distance_between_positions, ":distance", pos1, pos2),
(le, ":distance", 1000),
(agent_clear_scripted_mode, ":bandit_2_id"),
(try_end),
(assign, ":continue", 1),
(else_try),
(agent_get_position, pos1, ":bandit_id"),
(agent_get_position, pos2, ":player_team_agent_id"),
(get_distance_between_positions, ":distance", pos1, pos2),
(le, ":distance", 4000),
(try_for_agents, ":bandit_2_id"),
(agent_is_alive, ":bandit_2_id"),
(agent_get_team, ":bandit_2_team", ":bandit_2_id"),
(eq, ":bandit_2_team", 1),
(neq, ":bandit_id", ":bandit_2_id"),
(agent_is_in_special_mode, ":bandit_2_id"),
(agent_is_human, ":bandit_2_id"),
(agent_get_position, pos1, ":bandit_id"),
(agent_get_position, pos2, ":bandit_2_id"),
(get_distance_between_positions, ":distance", pos1, pos2),
(le, ":distance", 1000),
(agent_clear_scripted_mode, ":bandit_2_id"),
(try_end),
(assign, ":continue", 1),
(try_end),
(eq, ":continue", 1),
(agent_clear_scripted_mode, ":bandit_id"),
(try_end),
(try_end),
]),
#触发器 触发增援
(30, 0, 0,
[
(le, "$defender_reinforcement_stage", 1),
],
[
(store_character_level, ":player_level", "trp_player"),
(store_add, ":number_of_bandits_will_be_spawned_at_each_period", 5, ":player_level"),
(val_div, ":number_of_bandits_will_be_spawned_at_each_period", 3),
(lt, "$bandits_spawned_extra", ":number_of_bandits_will_be_spawned_at_each_period"),
(val_add, "$bandits_spawned_extra", 1),
(party_get_template_id, ":template", "$g_encountered_party"),
(store_random_in_range, ":random_value", 0, 2),
(try_begin),
(eq, ":template", "pt_sea_raider_lair"),
(eq, ":random_value", 0),
(assign, ":bandit_troop", "trp_sea_raider"),
(else_try),
(eq, ":template", "pt_forest_bandit_lair"),
(eq, ":random_value", 0),
(assign, ":bandit_troop", "trp_forest_bandit"),
(else_try),
(eq, ":template", "pt_desert_bandit_lair"),
(eq, ":random_value", 0),
(assign, ":bandit_troop", "trp_desert_bandit"),
(else_try),
(eq, ":template", "pt_mountain_bandit_lair"),
(eq, ":random_value", 0),
(assign, ":bandit_troop", "trp_mountain_bandit"),
(else_try),
(eq, ":template", "pt_taiga_bandit_lair"),
(eq, ":random_value", 0),
(assign, ":bandit_troop", "trp_taiga_bandit"),
(else_try),
(eq, ":template", "pt_steppe_bandit_lair"),
(eq, ":random_value", 0),
(assign, ":bandit_troop", "trp_steppe_bandit"),
(else_try),
(this_or_next|eq, ":template", "pt_looter_lair"),
(neq, ":random_value", 0),
(assign, ":bandit_troop", "trp_looter"),
(try_end),
(store_current_scene, ":cur_scene"),
(modify_visitors_at_site, ":cur_scene"),
(store_random_in_range, ":random_entry_point", 2, 11),
(add_visitors_to_current_scene, ":random_entry_point", ":bandit_troop", 1),
]),
#触发器 人倒了或伤了
(ti_on_agent_killed_or_wounded, 0, 0, [],
[
(store_trigger_param_1, ":dead_agent_no"),
#(store_trigger_param_2, ":killer_agent_no"),
(store_trigger_param_3, ":is_wounded"),
(try_begin),
(ge, ":dead_agent_no", 0),
(agent_is_human, ":dead_agent_no"),
(agent_get_troop_id, ":dead_agent_troop_id", ":dead_agent_no"),
(str_store_troop_name, s6, ":dead_agent_troop_id"),
(try_begin),
(neg|agent_is_ally, ":dead_agent_no"),
(party_add_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1), #addition_to_p_total_enemy_casualties
(try_begin),
(eq, ":is_wounded", 1),
(party_wound_members, "p_total_enemy_casualties", ":dead_agent_troop_id", 1),
(try_end),
(try_end),
(party_add_members, "p_temp_casualties", ":dead_agent_troop_id", 1), #addition_to_p_total_enemy_casualties
(eq, ":is_wounded", 1),
(party_wound_members, "p_temp_casualties", ":dead_agent_troop_id", 1),
(try_end),
(assign, ":number_of_enemies", 0),
(try_for_agents, ":cur_agent"),
(agent_is_non_player, ":cur_agent"),
(agent_is_human, ":cur_agent"),
(agent_is_alive, ":cur_agent"),
(neg|agent_is_ally, ":cur_agent"),
(val_add, ":number_of_enemies", 1),
(try_end),
(try_begin),
(le, ":number_of_enemies", 2),
(le, "$defender_reinforcement_stage", 1),
(val_add, "$defender_reinforcement_stage", 1),
(store_character_level, ":player_level", "trp_player"),
(store_add, ":number_of_bandits_will_be_spawned_at_each_period", 5, ":player_level"),
(val_div, ":number_of_bandits_will_be_spawned_at_each_period", 3),
(try_begin),
(ge, "$defender_reinforcement_stage", 2),
(val_sub, ":number_of_bandits_will_be_spawned_at_each_period", "$bandits_spawned_extra"),
(try_end),
(party_get_template_id, ":template", "$g_encountered_party"),
(store_random_in_range, ":random_value", 0, 2),
(try_begin),
(eq, ":template", "pt_sea_raider_lair"),
(eq, ":random_value", 0),
(assign, ":bandit_troop", "trp_sea_raider"),
(else_try),
(eq, ":template", "pt_forest_bandit_lair"),
(eq, ":random_value", 0),
(assign, ":bandit_troop", "trp_forest_bandit"),
(else_try),
(eq, ":template", "pt_desert_bandit_lair"),
(eq, ":random_value", 0),
(assign, ":bandit_troop", "trp_desert_bandit"),
(else_try),
(eq, ":template", "pt_mountain_bandit_lair"),
(eq, ":random_value", 0),
(assign, ":bandit_troop", "trp_mountain_bandit"),
(else_try),
(eq, ":template", "pt_taiga_bandit_lair"),
(eq, ":random_value", 0),
(assign, ":bandit_troop", "trp_taiga_bandit"),
(else_try),
(eq, ":template", "pt_steppe_bandit_lair"),
(eq, ":random_value", 0),
(assign, ":bandit_troop", "trp_steppe_bandit"),
(else_try),
(this_or_next|eq, ":template", "pt_looter_lair"),
(neq, ":random_value", 0),
(assign, ":bandit_troop", "trp_looter"),
(try_end),
(store_current_scene, ":cur_scene"),
(modify_visitors_at_site, ":cur_scene"),
(try_for_range, ":unused", 0, ":number_of_bandits_will_be_spawned_at_each_period"),
(store_random_in_range, ":random_entry_point", 2, 11),
(add_visitors_to_current_scene, ":random_entry_point", ":bandit_troop", 1),
(try_end),
(try_end),
#no need to adjust courage in bandit lair for now
#(call_script, "script_apply_death_effect_on_courage_scores", ":dead_agent_no", ":killer_agent_no"),
]),
#触发器 音乐触发器
(0, 0, ti_once, [],
[
(call_script, "script_music_set_situation_with_culture", mtf_sit_ambushed),
(set_party_battle_mode),
]),
#触发器 只剩一个队伍了(赢了)
(2, 0, ti_once,
[
(neg|main_hero_fallen),
(num_active_teams_le, 1),
],
[
(party_get_template_id, ":template", "$g_encountered_party"),
(try_begin),
(eq, ":template", "pt_looter_lair"),
(check_quest_active, "qst_save_relative_of_merchant"),
(store_faction_of_party, ":starting_town_faction", "$g_starting_town"),
(try_begin),
(eq, ":starting_town_faction", "fac_kingdom_1"),
(assign, ":troop_of_merchant", "trp_relative_of_merchant"),
(else_try),
(eq, ":starting_town_faction", "fac_kingdom_2"),
(assign, ":troop_of_merchant", "trp_relative_of_merchant"),
(else_try),
(eq, ":starting_town_faction", "fac_kingdom_3"),
(assign, ":troop_of_merchant", "trp_relative_of_merchant"),
(else_try),
(eq, ":starting_town_faction", "fac_kingdom_4"),
(assign, ":troop_of_merchant", "trp_relative_of_merchant"),
(else_try),
(eq, ":starting_town_faction", "fac_kingdom_5"),
(assign, ":troop_of_merchant", "trp_relative_of_merchant"),
(else_try),
(eq, ":starting_town_faction", "fac_kingdom_6"),
(assign, ":troop_of_merchant", "trp_relative_of_merchant"),
(try_end),
(get_player_agent_no, ":player_agent"),
(agent_get_position, pos0, ":player_agent"),
(assign, ":minimum_distance", 100000),
(try_for_range, ":entry_no", 1, 10),
(entry_point_get_position, pos1, ":entry_no"),
(get_distance_between_positions, ":dist", pos0, pos1),
(le, ":dist", ":minimum_distance"),
(ge, ":dist", 1000),
(assign, ":nearest_entry_point", ":entry_no"),
(assign, ":minimum_distance", ":dist"),
(try_end),
(add_visitors_to_current_scene, ":nearest_entry_point", ":troop_of_merchant", 1, 0),
(try_end),
]),
#触发器 自带的战场地图,退格键那个
common_battle_order_panel,
common_battle_order_panel_tick,
#触发器 玩家倒了,任务失败
(1, 4, ti_once,
[
(assign, ":continue", 0),
(party_get_template_id, ":template", "$g_encountered_party"),
(try_begin),
(eq, ":template", "pt_looter_lair"),
(check_quest_active, "qst_save_relative_of_merchant"),
(this_or_next|main_hero_fallen),
(eq, "$relative_of_merchant_is_found", 1),
(assign, ":continue", 1),
(else_try),
(this_or_next|neq|eq, ":template", "pt_looter_lair"),
(neg|check_quest_active, "qst_save_relative_of_merchant"),
(store_mission_timer_a,":cur_time"),
(ge, ":cur_time", 5),
(this_or_next|main_hero_fallen),
(num_active_teams_le, 1),
(assign, ":continue", 1),
(try_end),
(eq, ":continue", 1),
],
[
(try_begin),
(main_hero_fallen),
(else_try),
(party_set_slot, "$g_encountered_party", slot_party_ai_substate, 2),
(try_end),
(finish_mission),
]),
]),
|