MadGuarang said:It surely has to do something with number of parties on the world map and unoptimized triggers.
What's the average savegame size of your mod?
Garedyr - You probably do not remember, but you were the first person that introduced me into a warband coding, and cannibalism kit was my first code I have applied to my mod. You're 1st on my credit list
1. Average save is around 7-10 MB.
2. Yes, I have a lot of parties on my map, but same I did in previous stutter-free version. I also reduced amount of parties just to see would that help and I still had that issue.
3. Triggers - I have added some triggers for town's improvement's but they are mostly 7*24 or 30*24. Is there any way to track how do they affect game performance? Then again my issue is that 1.00 with more parties on world map worked a lot better, than less parties in 1.20 of mod version.
I am opened for any suggestions, really!
Ruthven said:Check if you have any triggers/scripts with nested try_for_parties loops. That is what causes map lag 99.9999% of the time.
Avareee said:Hello people, I have a question,
So I almost finished modding and wanted to start the game for a test and I get this..:
When the game tries to load the textures.https://imgur.com/g1CYgYF
Does anyone know how I can fix that?...
Avareee said:Hello people, I have a question,
So I almost finished modding and wanted to start the game for a test and I get this..:
When the game tries to load the textures.https://imgur.com/g1CYgYF
Does anyone know how I can fix that?...
Garedyr said:MadGuarang said:It surely has to do something with number of parties on the world map and unoptimized triggers.
What's the average savegame size of your mod?
Garedyr - You probably do not remember, but you were the first person that introduced me into a warband coding, and cannibalism kit was my first code I have applied to my mod. You're 1st on my credit list
1. Average save is around 7-10 MB.
2. Yes, I have a lot of parties on my map, but same I did in previous stutter-free version. I also reduced amount of parties just to see would that help and I still had that issue.
3. Triggers - I have added some triggers for town's improvement's but they are mostly 7*24 or 30*24. Is there any way to track how do they affect game performance? Then again my issue is that 1.00 with more parties on world map worked a lot better, than less parties in 1.20 of mod version.
I am opened for any suggestions, really!
That savegame file size is fine so it eliminates any potential hard to fix problems as a potential cause of map stuttering.
Keep in mind that the more parties and slots for them you have, the more data needs to be stored and processed by the CPU when specific triggers are called. That leads us directly to what Ruthven said:
Ruthven said:Check if you have any triggers/scripts with nested try_for_parties loops. That is what causes map lag 99.9999% of the time.
You should try to avoid using try_for_parties if possible and replace it with try_for_range instead.
# Attach Lord Parties to the town they are in
(0.1,
[
(try_for_range, ":troop_no", heroes_begin, heroes_end),
(troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
(troop_get_slot, ":troop_party_no", ":troop_no", slot_troop_leaded_party),
(ge, ":troop_party_no", 1),
(party_is_active, ":troop_party_no"),
(party_get_attached_to, ":cur_attached_town", ":troop_party_no"),
(lt, ":cur_attached_town", 1),
(party_get_cur_town, ":destination", ":troop_party_no"),
(is_between, ":destination", centers_begin, centers_end),
(call_script, "script_get_relation_between_parties", ":destination", ":troop_party_no"),
(try_begin),
(ge, reg0, 0),
(party_attach_to_party, ":troop_party_no", ":destination"),
(else_try),
(party_set_ai_behavior, ":troop_party_no", ai_bhvr_hold),
(try_end),
(try_begin),
(this_or_next|party_slot_eq, ":destination", slot_party_type, spt_town),
(party_slot_eq, ":destination", slot_party_type, spt_castle),
(store_faction_of_party, ":troop_faction_no", ":troop_party_no"),
(store_faction_of_party, ":destination_faction_no", ":destination"),
(eq, ":troop_faction_no", ":destination_faction_no"),
(party_get_num_prisoner_stacks, ":num_stacks", ":troop_party_no"),
(gt, ":num_stacks", 0),
(assign, "$g_move_heroes", 1),
(call_script, "script_party_prisoners_add_party_prisoners", ":destination", ":troop_party_no"),#Moving prisoners to the center
(assign, "$g_move_heroes", 1),
(call_script, "script_party_remove_all_prisoners", ":troop_party_no"),
(try_end),
(try_end),
[color=red](try_for_parties, ":bandit_camp"), ##!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! try for parties!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!![/color]
(gt, ":bandit_camp", "p_spawn_points_end"),
#Can't have party is active here, because it will fail for inactive parties
(party_get_template_id, ":template", ":bandit_camp"),
(ge, ":template", "pt_steppe_bandit_lair"),
(store_distance_to_party_from_party, ":distance", "p_main_party", ":bandit_camp"),
(lt, ":distance", 3),
(party_set_flags, ":bandit_camp", pf_disabled, 0),
(party_set_flags, ":bandit_camp", pf_always_visible, 1),
(try_end),
]),
(3, #check to see if player's court has been captured
[
(try_begin), #The old court has been lost
(is_between, "$g_player_court", centers_begin, centers_end),
(store_faction_of_party, ":court_faction", "$g_player_court"),
(neq, ":court_faction", "fac_player_supporters_faction"),
(call_script, "script_add_notification_menu", "mnu_notification_court_lost", 0, 0),
(else_try), #At least one new court has been found
(lt, "$g_player_court", centers_begin),
#Will by definition not active until a center is taken by the player faction
#Player minister must have been appointed at some point
(this_or_next|faction_slot_eq, "fac_player_supporters_faction", slot_faction_leader, "trp_player"),
(gt, "$g_player_minister", 0),
(assign, ":center_found", 0),
(try_for_range, ":walled_center", walled_centers_begin, walled_centers_end),
(eq, ":center_found", 0),
(store_faction_of_party, ":court_faction", ":walled_center"),
(eq, ":court_faction", "fac_player_supporters_faction"),
(assign, ":center_found", ":walled_center"),
(try_end),
(ge, ":center_found", 1),
(call_script, "script_add_notification_menu", "mnu_notification_court_lost", 0, 0),
(try_end),
#Also, piggy-backing on this -- having bandits go to lairs and back
(try_for_parties, ":bandit_party"), ##!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! try for parties!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
(gt, ":bandit_party", "p_spawn_points_end"),
(party_get_template_id, ":bandit_party_template", ":bandit_party"),
(is_between, ":bandit_party_template", "pt_steppe_bandits", "pt_deserters"),
(party_template_get_slot, ":bandit_lair", ":bandit_party_template", slot_party_template_lair_party),
(try_begin),#If party is active and bandit is far away, then move to location
(gt, ":bandit_lair", "p_spawn_points_end"),
(store_distance_to_party_from_party, ":distance", ":bandit_party", ":bandit_lair"), #this is the cause of the error
(gt, ":distance", 30),
#All this needs checking
(party_set_ai_behavior, ":bandit_party", ai_bhvr_travel_to_point),
(party_get_position, pos5, ":bandit_lair"),
(party_set_ai_target_position, ":bandit_party", pos5),
(else_try), #Otherwise, act freely
(get_party_ai_behavior, ":behavior", ":bandit_party"),
(eq, ":behavior", ai_bhvr_travel_to_point),
(try_begin),
(gt, ":bandit_lair", "p_spawn_points_end"),
(store_distance_to_party_from_party, ":distance", ":bandit_party", ":bandit_lair"),
(lt, ":distance", 3),
(party_set_ai_behavior, ":bandit_party", ai_bhvr_patrol_party),
(party_template_get_slot, ":spawnpoint", ":bandit_party_template", slot_party_template_lair_spawnpoint),
(party_set_ai_object, ":bandit_party", ":spawnpoint"),
(party_set_ai_patrol_radius, ":bandit_party", 45),
(else_try),
(lt, ":bandit_lair", "p_spawn_points_end"),
(party_set_ai_behavior, ":bandit_party", ai_bhvr_patrol_party),
(party_template_get_slot, ":spawnpoint", ":bandit_party_template", slot_party_template_lair_spawnpoint),
(party_set_ai_object, ":bandit_party", ":spawnpoint"),
(party_set_ai_patrol_radius, ":bandit_party", 45),
(try_end),
(try_end),
(try_end),
#Piggybacking on trigger:
(try_begin),
(troop_get_slot, ":betrothed", "trp_player", slot_troop_betrothed),
(gt, ":betrothed", 0),
(neg|check_quest_active, "qst_wed_betrothed"),
(neg|check_quest_active, "qst_wed_betrothed_female"),
(str_store_troop_name, s5, ":betrothed"),
(display_message, "@Betrothal to {s5} expires"),
(troop_set_slot, "trp_player", slot_troop_betrothed, -1),
(troop_set_slot, ":betrothed", slot_troop_betrothed, -1),
(try_end),
]),
Cozur said:What part of the code controls companions appearing in taverns? In case you'd rather have them appear in the castle hall instead?
("town_tavern",[
(party_slot_eq,"$current_town",slot_party_type, spt_town),
(this_or_next|eq,"$entry_to_town_forbidden",0),
(eq, "$sneaked_into_town",1),
# (party_get_slot, ":scene", "$current_town", slot_town_tavern),
# (scene_slot_eq, ":scene", slot_scene_visited, 1), #check if scene has been visited before to allow entry from menu. Otherwise scene will only be accessible from the town center.
]
,"Visit the tavern.",
[
(try_begin),
(eq,"$all_doors_locked",1),
(display_message,"str_door_locked",0xFFFFAAAA),
(else_try),
(call_script, "script_cf_enter_center_location_bandit_check"),
(else_try),
(assign, "$town_entered", 1),
(set_jump_mission, "mt_town_default"),
(mission_tpl_entry_set_override_flags, "mt_town_default", 0, af_override_horse),
(try_begin),
(eq, "$sneaked_into_town",1),
(mission_tpl_entry_set_override_flags, "mt_town_default", 0, af_override_all),
(try_end),
(party_get_slot, ":cur_scene", "$current_town", slot_town_tavern),
(jump_to_scene, ":cur_scene"),
(scene_set_slot, ":cur_scene", slot_scene_visited, 1),
(assign, "$talk_context", tc_tavern_talk),
(call_script, "script_initialize_tavern_variables"),
(store_random_in_range, ":randomize_attacker_placement", 0, 4),
(modify_visitors_at_site, ":cur_scene"),
(reset_visitors),
(assign, ":cur_entry", 17),
#this is just a cheat right now
#(troop_set_slot, "trp_belligerent_drunk", slot_troop_cur_center, "$g_encountered_party"),
(try_begin),
(eq, "$cheat_mode", 1),
(troop_get_slot, ":drunk_location", "trp_belligerent_drunk", slot_troop_cur_center),
(try_begin),
(eq, "$cheat_mode", 0),
(else_try),
(is_between, ":drunk_location", centers_begin, centers_end),
(str_store_party_name, s4, ":drunk_location"),
(display_message, "str_belligerent_drunk_in_s4"),
(else_try),
(display_message, "str_belligerent_drunk_not_found"),
(try_end),
(troop_get_slot, ":promoter_location", "trp_fight_promoter", slot_troop_cur_center),
(try_begin),
(eq, "$cheat_mode", 0),
(else_try),
(is_between, ":promoter_location", centers_begin, centers_end),
(str_store_party_name, s4, ":promoter_location"),
(display_message, "str_roughlooking_character_in_s4"),
(else_try),
(display_message, "str_roughlooking_character_not_found"),
(try_end),
(try_end),
#this determines whether or not a lord who dislikes you will commission an assassin
(try_begin),
(store_current_hours, ":hours"),
(store_sub, ":hours_since_last_attempt", ":hours", "$g_last_assassination_attempt_time"),
(gt, ":hours_since_last_attempt", 168),
(try_for_range, ":lord", active_npcs_begin, active_npcs_end),
(troop_slot_eq, ":lord", slot_lord_reputation_type, lrep_debauched),
(troop_get_slot, ":led_party", ":lord", slot_troop_leaded_party),
(party_is_active, ":led_party"),
(party_get_attached_to, ":led_party_attached", ":led_party"),
(eq, ":led_party_attached", "$g_encountered_party"),
(call_script, "script_troop_get_relation_with_troop", "trp_player", ":lord"),
(lt, reg0, -20),
(assign, "$g_last_assassination_attempt_time", ":hours"),
# (assign, "$g_last_assassination_attempt_location", "$g_encountered_party"),
# (assign, "$g_last_assassination_attempt_perpetrator", ":lord"),
(troop_set_slot, "trp_hired_assassin", slot_troop_cur_center, "$g_encountered_party"),
(try_end),
(try_end),
(try_begin),
(eq, ":randomize_attacker_placement", 0),
(call_script, "script_setup_tavern_attacker", ":cur_entry"),
(val_add, ":cur_entry", 1),
(try_end),
(try_begin),
(eq, 1, 0),
(troop_slot_eq, "trp_fight_promoter", slot_troop_cur_center, "$current_town"),
(set_visitor, ":cur_entry", "trp_fight_promoter"),
(val_add, ":cur_entry", 1),
(try_end),
(party_get_slot, ":mercenary_troop", "$current_town", slot_center_mercenary_troop_type),
(party_get_slot, ":mercenary_amount", "$current_town", slot_center_mercenary_troop_amount),
(try_begin),
(gt, ":mercenary_troop", 0),
(gt, ":mercenary_amount", 0),
(set_visitor, ":cur_entry", ":mercenary_troop"),
(val_add, ":cur_entry", 1),
(try_end),
(try_begin),
(eq, ":randomize_attacker_placement", 1),
(call_script, "script_setup_tavern_attacker", ":cur_entry"),
(val_add, ":cur_entry", 1),
(try_end),
(try_for_range, ":companion_candidate", companions_begin, companions_end),
(troop_slot_eq, ":companion_candidate", slot_troop_occupation, 0),
(troop_slot_eq, ":companion_candidate", slot_troop_cur_center, "$current_town"),
(neg|troop_slot_ge, ":companion_candidate", slot_troop_prisoner_of_party, centers_begin),
(set_visitor, ":cur_entry", ":companion_candidate"),
(val_add, ":cur_entry", 1),
(try_end),
(try_begin),
(eq, ":randomize_attacker_placement", 2),
(call_script, "script_setup_tavern_attacker", ":cur_entry"),
(val_add, ":cur_entry", 1),
(try_end),
(try_begin), #this doubles the incidence of ransom brokers and (below) minstrels
(party_get_slot, ":ransom_broker", "$current_town", slot_center_ransom_broker),
(gt, ":ransom_broker", 0),
(assign, reg0, ":ransom_broker"),
(assign, reg1, "$current_town"),
(set_visitor, ":cur_entry", ":ransom_broker"),
(val_add, ":cur_entry", 1),
(else_try),
(is_between, "$g_talk_troop", ransom_brokers_begin, ransom_brokers_end),
(store_add, ":alternative_town", "$current_town", 9),
(try_begin),
(ge, ":alternative_town", towns_end),
(val_sub, ":alternative_town", 22),
(try_end),
(try_begin),
(eq, "$cheat_mode", 1),
(str_store_party_name, s3, "$current_town"),
(str_store_party_name, s4, ":alternative_town"),
(display_message, "@{!}DEBUG - Current town is {s3}, but also checking {s4}"),
(try_end),
(party_get_slot, ":ransom_broker", ":alternative_town", slot_center_ransom_broker),
(gt, ":ransom_broker", 0),
(set_visitor, ":cur_entry", ":ransom_broker"),
(val_add, ":cur_entry", 1),
(try_end),
(try_begin),
(party_get_slot, ":tavern_traveler", "$current_town", slot_center_tavern_traveler),
(gt, ":tavern_traveler", 0),
(set_visitor, ":cur_entry", ":tavern_traveler"),
(val_add, ":cur_entry", 1),
(try_end),
(assign,":bard",0),#dedal
(try_begin),
(party_get_slot, ":tavern_minstrel", "$current_town", slot_center_tavern_minstrel),
(gt, ":tavern_minstrel", 0),
(assign,":bard",1),#dedal
(set_visitor, ":cur_entry", ":tavern_minstrel"),
(val_add, ":cur_entry", 1),
(else_try),
(store_add, ":alternative_town", "$current_town", 9),
(try_begin),
(ge, ":alternative_town", towns_end),
(val_sub, ":alternative_town", 22),
(try_end),
(party_get_slot, ":tavern_minstrel", ":alternative_town", slot_center_tavern_minstrel),
(gt, ":tavern_minstrel", 0),
(assign,":bard",1),#dedal
(set_visitor, ":cur_entry", ":tavern_minstrel"),
(val_add, ":cur_entry", 1),
(try_end),
(try_begin),
(party_get_slot, ":tavern_bookseller", "$current_town", slot_center_tavern_bookseller),
(gt, ":tavern_bookseller", 0),
(set_visitor, ":cur_entry", ":tavern_bookseller"),
(val_add, ":cur_entry", 1),
(try_end),
(try_begin),
(eq, ":randomize_attacker_placement", 3),
(call_script, "script_setup_tavern_attacker", ":cur_entry"),
(val_add, ":cur_entry", 1),
(try_end),
(try_begin),
(neg|check_quest_active, "qst_eliminate_bandits_infesting_village"),
(neg|check_quest_active, "qst_deal_with_bandits_at_lords_village"),
(assign, ":end_cond", villages_end),
(try_for_range, ":cur_village", villages_begin, ":end_cond"),
(party_slot_eq, ":cur_village", slot_village_bound_center, "$current_town"),
(party_slot_ge, ":cur_village", slot_village_infested_by_bandits, 1),
(neg|party_slot_eq, ":cur_village", slot_town_lord, "trp_player"),
(set_visitor, ":cur_entry", "trp_farmer_from_bandit_village"),
(val_add, ":cur_entry", 1),
(assign, ":end_cond", 0),
(try_end),
(try_end),
(try_begin),
(eq, "$g_starting_town", "$current_town"),
(this_or_next|neg|check_quest_finished, "qst_collect_men"),
(this_or_next|neg|check_quest_finished, "qst_learn_where_merchant_brother_is"),
(this_or_next|neg|check_quest_finished, "qst_save_relative_of_merchant"),
(this_or_next|neg|check_quest_finished, "qst_save_town_from_bandits"),
(eq, "$g_do_one_more_meeting_with_merchant", 1),
(assign, ":troop_of_merchant", 0),
(try_begin),
(eq, "$g_encountered_party_faction", "fac_kingdom_1"),
(assign, ":troop_of_merchant", "trp_swadian_merchant"),
(else_try),
(eq, "$g_encountered_party_faction", "fac_kingdom_2"),
(assign, ":troop_of_merchant", "trp_vaegir_merchant"),
(else_try),
(eq, "$g_encountered_party_faction", "fac_kingdom_3"),
(assign, ":troop_of_merchant", "trp_khergit_merchant"),
(else_try),
(eq, "$g_encountered_party_faction", "fac_kingdom_4"),
(assign, ":troop_of_merchant", "trp_nord_merchant"),
(else_try),
(eq, "$g_encountered_party_faction", "fac_kingdom_5"),
(assign, ":troop_of_merchant", "trp_rhodok_merchant"),
(else_try),
(eq, "$g_encountered_party_faction", "fac_kingdom_6"),
(assign, ":troop_of_merchant", "trp_sarranid_merchant"),
(try_end),
(gt, ":troop_of_merchant", 0),
(set_visitor, ":cur_entry", ":troop_of_merchant"),
(val_add, ":cur_entry", 1),
(try_end),
#then at the end of the tavern menu add this lines :
#dedal begin
(try_for_range,":entry",32,41),
(store_random_in_range,":r",0,100),
(gt,":r",50),#random chance of spawning
(try_begin),
(eq,":bard",0),
(store_random_in_range,":r",0,15),
(gt,":r",13),
(mission_tpl_entry_clear_override_items,"mt_town_default",":entry"),
(store_random_in_range,":r",0,2),
(try_begin),
(eq,":r",0),
(mission_tpl_entry_add_override_item,"mt_town_default",":entry","itm_dedal_lutnia"),
(else_try),
(mission_tpl_entry_add_override_item,"mt_town_default",":entry","itm_dedal_lira"),
(try_end),
(store_random_in_range,":dna",0,1000),
(store_random_in_range,":troop","trp_musican_male","trp_musican_female"),
(set_visitor,":entry",":troop",":dna"),
(assign,":bard",1),
(else_try),
(store_random_in_range,":town_walker",town_walkers_begin,town_walkers_end),
(store_random_in_range,":dna",0,1000),
(mission_tpl_entry_clear_override_items,"mt_town_default",":entry"),
(store_random_in_range,":r",0,10),
(try_begin),
(gt,":r",2),
(mission_tpl_entry_add_override_item,"mt_town_default",":entry","itm_dedal_kufel"),
(try_end),
(set_visitor,":entry",":town_walker",":dna"),
(try_end),
(try_end),
#dedal end
(change_screen_mission),
(try_end),
],"Door to the tavern."),
(try_for_range, ":companion_candidate", companions_begin, companions_end),
(troop_slot_eq, ":companion_candidate", slot_troop_occupation, 0),
(troop_slot_eq, ":companion_candidate", slot_troop_cur_center, "$current_town"),
(neg|troop_slot_ge, ":companion_candidate", slot_troop_prisoner_of_party, centers_begin),
(set_visitor, ":cur_entry", ":companion_candidate"),
(val_add, ":cur_entry", 1),
sphere said:The short version:
Is there a trigger/simple_trigger/other methods that can run a script/operation block once immediately after a game is loaded.
The longer version:
Attempting to come up with a work-flow that enables auto-upgrading of mod variables/structures/data in existing save-games that will hopefully improve chances of save-game compatibility. Now thinking of a way to run this upgrading script after every loading of game (new game should be ok since it uses the current mod from the start), so that it can compare some stored global of the last modded version vs the current version, and do white-box upgrading of supported old versions.
Currently, I am thinking of using a trigger with 0 interval and no rearming, but I am not sure whether triggers that won't get rearmed will execute on a game load (as opposed to new game?), as similar trigger (same trigger index but different script content from previous mod versions) may have executed before that particular save-game.
The other alternative is a simple_trigger that executes regularly, but it has the problem of unneeded checking after the first execution. Also have the problem of not executing before other dependent scripts uses the older mod version's data.
Thanks in advance for any help renderable.
0.5, 0, 0, [],
[
(set_fixed_point_multiplier, 1000),
(try_for_agents, ":agent_no"),
(agent_is_alive, ":agent_no"),
(agent_is_human, ":agent_no"),
(agent_is_non_player, ":agent_no"),
(neg|agent_slot_eq, ":agent_no", 1003, 1),
(agent_get_horse, ":horse_no", ":agent_no"),
(assign, ":melee_weapon", -1),
(try_begin),
(agent_slot_eq, ":agent_no", slot_agent_is_running_away, 0),
(gt, ":horse_no", -1),
(agent_get_team, ":team_no", ":agent_no"),
(agent_get_division, ":class_no", ":agent_no"),
(team_get_weapon_usage_order, ":weapon_usage_order", ":team_no", ":class_no"),
(team_get_movement_order, ":movement_order", ":team_no", ":class_no"),
(team_get_hold_fire_order, ":hold_fire", ":team_no", ":class_no"),
(assign, ":thrown_ammo", 0),
(assign, ":ranged_weapon", -1),
(try_for_range, ":item", 0, 4),
(agent_get_item_slot, ":item_weapon", ":agent_no", ":item"),
(gt, ":item_weapon", 0),
(item_get_type, ":item_weapon_type", ":item_weapon"),
(try_begin),
(eq, ":item_weapon_type", itp_type_thrown),
(agent_get_ammo_for_slot, ":ammo_for_slot", ":agent_no", ":item"),
(val_add, ":thrown_ammo", ":ammo_for_slot"),
(else_try),
(this_or_next|eq, ":item_weapon_type", itp_type_bow),
(this_or_next|eq, ":item_weapon_type", itp_type_pistol),
(eq, ":item_weapon_type", itp_type_musket),
(assign, ":ranged_weapon", ":item_weapon"),
(else_try),
(this_or_next|eq, ":item_weapon_type", itp_type_one_handed_wpn),
(this_or_next|eq, ":item_weapon_type", itp_type_two_handed_wpn),
(eq, ":item_weapon_type", itp_type_polearm),
(assign, ":melee_weapon", ":item_weapon"),
(try_end),
(try_end),
(gt, ":ranged_weapon", -1),
(neg|item_has_property, ":ranged_weapon", itp_cant_reload_on_horseback),
(neg|item_has_property, ":ranged_weapon", itp_cant_use_on_horseback),
(agent_get_ammo, ":ammo", ":agent_no", 0),
(val_sub, ":ammo", ":thrown_ammo"),
(gt, ":ammo", 0),
(agent_set_slot, ":agent_no", 1003, 2),
(neg|eq, ":hold_fire", aordr_hold_your_fire),
(neg|eq, ":weapon_usage_order", wordr_use_melee_weapons),
(eq, ":movement_order", mordr_charge),
(agent_get_position, pos50, ":agent_no"),
(agent_get_speed, pos31, ":agent_no"),
(position_get_y,":speed_y",pos31),
(assign, ":distance_closest", 100000),#1000m
(assign, ":enemies_closest", -1),
(try_for_agents, ":enemies"),
(agent_is_alive, ":enemies"),
(agent_is_human, ":enemies"),
(agent_get_position, pos36, ":enemies"),
(agent_get_team, ":enemies_team", ":enemies"),
(teams_are_enemies, ":team_no", ":enemies_team"),
(get_distance_between_positions, ":distance", pos50, pos36),
(try_begin),
(agent_slot_eq, ":enemies", slot_agent_is_running_away, 1),
(val_add, ":distance", 10000),
(try_end),
(try_begin),
(agent_get_horse, ":enemies_horse", ":enemies"),
(gt, ":enemies_horse", -1),
(agent_get_speed, pos32, ":enemies"),
(position_get_y,":speed_y_enemies",pos32),
(val_sub, ":speed_y_enemies", ":speed_y"),
(store_div, ":distance_cavalry", ":speed_y_enemies",5),
(val_max, ":distance_cavalry", 0),
(val_add, ":distance_cavalry", 500),
(val_sub, ":distance", ":distance_cavalry"),
(else_try),
(agent_get_wielded_item, ":weapon_hold", ":enemies", 1),
(neg|gt, ":weapon_hold", 1),
(val_sub, ":distance", 500),
(try_end),
(lt, ":distance", ":distance_closest"),
(assign, ":distance_closest", ":distance"),
(assign, ":enemies_closest", ":enemies"),
(try_end),
(neq, ":enemies_closest", -1),
(agent_get_position, pos51, ":enemies_closest"),
(get_distance_between_positions, ":distance_true", pos50, pos51),
(try_begin),
(agent_slot_eq, ":enemies_closest", slot_agent_is_running_away, 0),
(gt,":distance_true",200),
(agent_set_wielded_item, ":agent_no", ":ranged_weapon"),
(else_try),
(le, ":distance_true", 200),
(gt, ":melee_weapon", -1),
(agent_set_wielded_item, ":agent_no", ":melee_weapon"),
(try_end),
(assign, ":speed_limit", 1000),
(try_begin),
(agent_get_wielded_item, ":weapon_hold", ":agent_no", 0),
(gt, ":weapon_hold", 0),
(item_get_type, ":weapon_type", ":weapon_hold"),
(this_or_next|eq, ":weapon_type", itp_type_bow),
(this_or_next|eq, ":weapon_type", itp_type_pistol),
(eq, ":weapon_type", itp_type_musket),
(agent_get_bone_position, pos53, ":agent_no", 8, 1),
(agent_get_bone_position, pos54, ":enemies_closest", 9, 1),
(position_has_line_of_sight_to_position, pos53, pos54),
(agent_set_look_target_agent, ":agent_no", ":enemies_closest"),
(try_begin),
(assign, ":shoot_distance", 4000),
(agent_get_attack_action, ":attack_action", ":agent_no"),
(eq, ":attack_action", 1),
(try_begin),
(gt, ":distance_closest", 700),
(le, ":distance_closest", ":shoot_distance"),
(store_div, ":speed_limit", ":speed_y",2000),#
(val_max, ":speed_limit", 0),
(try_end),
(eq, ":weapon_type", itp_type_bow),
(try_begin),
(le, ":distance_true", ":shoot_distance"),
(agent_set_defend_action, ":agent_no", -2, 1),
(agent_set_attack_action, ":agent_no", 3, 0),
(else_try),
(gt, ":distance_true", ":shoot_distance"),
(agent_set_attack_action, ":agent_no", -2, 1),
(agent_set_defend_action, ":agent_no", 3, 1),
(try_end),
(else_try),
(eq, ":weapon_type", itp_type_bow),
(le, ":distance_true", ":shoot_distance"),#
(agent_get_combat_state, ":combat_state", ":agent_no"),
(neq, ":combat_state",,
(agent_set_attack_action, ":agent_no", 3, 1),
(try_end),
(try_end),
(agent_set_speed_limit, ":agent_no", ":speed_limit"),
(try_begin),
(agent_slot_eq, ":enemies_closest", slot_agent_is_running_away, 0),
(lt, ":distance_closest", 10000),
(try_begin),
(get_scene_boundaries, pos2, pos3),
(position_transform_position_to_local, pos4, pos2,pos50),
(position_get_x, ":left", pos4),
(position_get_y, ":down", pos4),
(position_transform_position_to_local, pos4, pos2,pos3),
(position_get_x, ":map_width", pos4),
(position_get_y, ":map_height", pos4),
(store_sub, ":right", ":map_width", ":left"),
(store_sub, ":up", ":map_height", ":down"),
(position_transform_position_to_local, pos4, pos50, pos51),
(position_get_x, ":enemies_x", pos4),
(position_get_y, ":enemies_y", pos4),
(assign, ":effect", 0),
(try_begin),
(neg|gt, ":distance_closest", 1000),
(assign, ":effect", -78000),
(else_try),
(gt, ":distance_closest", 2000),#
(store_sub,":effect", ":distance_closest", 0),
(val_mul, ":effect", 5),
(val_clamp, ":effect", 35000, 90000),
(try_end),
(assign, ":distance_to_boundary", 30000),
(val_min, ":distance_to_boundary", ":left"),
(val_min, ":distance_to_boundary", ":up"),
(val_min, ":distance_to_boundary", ":right"),
(val_min, ":distance_to_boundary", ":down"),
(try_begin),
(lt, ":distance_to_boundary", 30000),
(agent_slot_eq, ":enemies_closest", slot_agent_is_running_away, 0),
(store_div, ":map_middle_x", ":map_width", 20),
(store_div, ":map_middle_y", ":map_height", 20),
(position_copy_origin, pos4, pos2),
(position_move_x, pos4, ":map_middle_x", 1),
(position_move_y, pos4, ":map_middle_y", 1),
(get_distance_between_positions,":distance_middle", pos4, pos50),
(position_transform_position_to_local, pos4, pos50, pos4),
(position_get_x, ":map_middle_x", pos4),
(position_get_y, ":map_middle_y", pos4),
(val_mul, ":map_middle_x", 100),
(val_mul, ":map_middle_y", 100),
(val_mul, ":enemies_x", 100),
(val_mul, ":enemies_y", 100),
(store_div,":cos_middle",":map_middle_x",":distance_middle"),
(store_div,":sin_middle",":map_middle_y",":distance_middle"),
(store_div,":cos_enemies",":enemies_x",":distance_true"),
(store_div,":sin_enemies",":enemies_y",":distance_true"),
(store_acos, ":angle_cos", ":cos_middle"),
(store_asin, ":angle_sin", ":sin_middle"),
(store_acos, ":angle_cos_enemies", ":cos_enemies"),
(store_asin, ":angle_sin_enemies", ":sin_enemies"),
(try_begin),
(lt, ":angle_sin", 0),
(val_mul,":angle_cos", -1),
(val_add,":angle_cos", 360000),
(try_end),
(try_begin),
(lt, ":angle_sin_enemies", 0),
(val_mul,":angle_cos_enemies", -1),
(val_add,":angle_cos_enemies", 360000),
(try_end),
(store_sub, ":k2", ":angle_cos", ":angle_cos_enemies"),
(val_sub, ":k2", 270000),
(val_sub, ":k2", ":effect"),
(store_add, ":effect", ":k2", ":effect"),
(try_begin),
(lt, ":angle_cos", ":angle_cos_enemies"),
(val_add, ":effect", 360000),
(try_end),
(val_clamp,":effect",-210000, 15000),
(agent_set_attack_action, ":agent_no", -2, 1),
(agent_set_defend_action, ":agent_no", 3, 1),
(try_end),
(store_cos, ":cos", ":effect"),
(store_sin, ":sin", ":effect"),
(store_mul, ":k_x1", ":cos", ":enemies_y",),
(store_mul, ":k_x2", ":sin", ":enemies_x",),
(store_mul, ":k_y1", ":sin", ":enemies_y",),
(store_mul, ":k_y2", ":cos", ":enemies_x",),
(store_add, ":move_x",":k_x1", ":k_x2"),
(store_sub, ":move_y",":k_y1", ":k_y2"),
(position_move_x, pos50, ":move_x", 0),
(position_move_y, pos50, ":move_y", 0),
(try_end),
(agent_set_scripted_destination, ":agent_no", pos50, 1),
(else_try),
(agent_clear_scripted_mode, ":agent_no"),
(agent_force_rethink, ":agent_no"),
(try_end),
(else_try),
(try_begin),
(agent_slot_eq, ":agent_no", 1003, 0),
(agent_set_slot, ":agent_no", 1003, 1),
(else_try),
(agent_slot_eq, ":agent_no", 1003, 2),
(this_or_next|agent_slot_eq, ":agent_no", slot_agent_is_running_away, 1),
(this_or_next|lt, ":horse_no", 0),
(this_or_next|eq, ":ammo", 0),
(this_or_next|eq, ":hold_fire", aordr_hold_your_fire),
(this_or_next|eq, ":weapon_usage_order", wordr_use_melee_weapons),
(neq, ":movement_order", mordr_charge),
(agent_clear_scripted_mode, ":agent_no"),
(agent_set_speed_limit, ":agent_no", 100),
(agent_force_rethink, ":agent_no"),
(agent_set_slot, ":agent_no", 1003, 3),
(this_or_next|eq, ":hold_fire", aordr_hold_your_fire),
(eq, ":ammo", 0),
(gt, ":melee_weapon", -1),
(agent_set_wielded_item, ":agent_no", ":melee_weapon"),
(try_end),
(try_end),
(try_end),
])
Barabashenko said:Okay, I have rather simple question.
how to change the direction of movement of mounted archers?
(agent_set_scripted_destination, ":agent_no", pos50, 1),
JhonBrazil said:Where in module_scripts is it defined how many items of a certain class a troop carry?
kalarhan said:Code:(agent_set_scripted_destination, ":agent_no", pos50, 1),
you need to review the math behind calculation for pos50 used on this line, as it is how it calculates based on the map, agent position, enemy position, etc the point where to run to. If in doubt check header_operations.py for the operations descriptions, as it also uses trigonometry operations.
Give us the edited code snippet too, so we can have a look at itmarkfamily said:I am hoping someone can help me with the following problem.
I have been trying to make my own module which has been going ok up until now.
I have tried to add a sixth tier to the troop tree, just started off with one troop to see how it works but i have this error.
If someone could help me with this i would be greatful.
Initializing...
Compiling all global variables...
Exporting strings...
Exporting skills...
Exporting tracks...
Exporting animations...
Exporting meshes...
Exporting sounds...
Exporting skins...
Exporting map icons...
Creating new tag_uses.txt file...
Creating new quick_strings.txt file...
Exporting faction data...
Exporting item data...
Exporting scene data...
Exporting troops data
Traceback (most recent call last):
File "process_troops.py", line 107, in <module>
save_troops()
File "process_troops.py", line 34, in save_troops
file.write("\ntrp_%s %s %s %s %d %d %d %d %d %d\n "%(convert_to_identifier(troop[0]),replace_spaces(troop[1]),replace_spaces(troop[2]), replace_spaces(str(troop[13])), troop[3],troop[4],troop[5], troop[6], troop[14], troop[15]))
File "H:\mb_warband_module_system_1171\Module_system 1.171\process_common.py", line 30, in replace_spaces
return string.replace(string.replace(s0,"\t","_")," ","_")
File "C:\Python27\lib\string.py", line 521, in replace
return s.replace(old, new, maxreplace)
AttributeError: 'int' object has no attribute 'replace'
Exporting particle data...
Exporting scene props...
Exporting tableau materials data...
Exporting presentations...
Exporting party_template data...
Exporting parties
Exporting quest data...
Exporting info_page data...
Exporting scripts...
Exporting mission_template data...
Exporting game menus data...
exporting simple triggers...
exporting triggers...
exporting dialogs...
Checking global variable usages...
Exporting postfx_params...
______________________________
Script processing has ended.
Press any key to exit. . .
markfamily said:File "process_troops.py", line 107, in <module>
save_troops()
File "process_troops.py", line 34, in save_troops
file.write("\ntrp_%s %s %s %s %d %d %d %d %d %d\n "%(convert_to_identifier(troop[0]),replace_spaces(troop[1]),replace_spaces(troop[2]), replace_spaces(str(troop[13])), troop[3],troop[4],troop[5], troop[6], troop[14], troop[15]))
File "H:\mb_warband_module_system_1171\Module_system 1.171\process_common.py", line 30, in replace_spaces
return string.replace(string.replace(s0,"\t","_")," ","_")
File "C:\Python27\lib\string.py", line 521, in replace
return s.replace(old, new, maxreplace)
AttributeError: 'int' object has no attribute 'replace'
upgrade(troops,"swadian_knight","swadian_noble"),