PYTHON SCRIPT/SCHEME EXCHANGE

Users who are viewing this thread

It's code of DEPLETING AMMO in use. The methods is checking all weapon wielded by agents before quitting missions, if they are ammo then save the ammount into a dummy troop's slots.
Then we use the slots' value to set the troop's ammo inventory.

A dummy troop to save the array :
Code:
  ["ammo", "{!}na","{!}na",tf_hero|tf_inactive,0,reserved,fac_neutral,[],0,0,0,0], 

The slot :
Code:
slot_item_max_ammo = 101 # use another slot number if you wish

The scripts
Code:
def set_item_max_ammo():
  item_max_ammo = []
  for i_item in xrange(len(items)):
    type = items[i_item][3] & 0x000000ff 
    if (type==itp_type_bow)|(type==itp_type_crossbow)|(type==itp_type_pistol)|(type==itp_type_musket):
       item_max_ammo.append((item_set_slot, i_item, slot_item_max_ammo,  get_max_ammo(items[i_item][6])))        
  return item_max_ammo[:]

Code:
(call_script, "script_init_max_ammo"),

Code:
# Dunde's Depleted Ammo BEGIN
("init_max_ammo", set_item_max_ammo()),

("save_agent_ammo_to_slot",
 [(store_script_param_1, ":agent_no"), 
  (agent_get_troop_id, ":troop_no", ":agent_no"),
  (try_begin),
     (troop_is_hero, ":troop_no"),
     #(this_or_next|eq, ":troop_no", "trp_player"),
     #(main_party_has_troop, ":troop_no"),
     (store_and, ":troop_bits", ":troop_no", 0xFFFF),
     (val_lshift, ":troop_bits", 24),
     (try_for_range, ":slot", 0, 4),
        (agent_get_item_slot, ":item_no", ":agent_no", ":slot"),
        (gt, ":item_no", 0),
        (item_get_type, ":data", ":item_no"),
        (this_or_next|eq, ":data", itp_type_bow),          # remove any weapon you want to exclude
        (this_or_next|eq, ":data", itp_type_crossbow),
        (this_or_next|eq, ":data", itp_type_musket),
        (this_or_next|eq, ":data", itp_type_pistol),
        (this_or_next|eq, ":data", itp_type_arrows),
        (this_or_next|eq, ":data", itp_type_bolts),
        (this_or_next|eq, ":data", itp_type_bullets),
        (eq, ":data", itp_type_thrown),
        (store_and, ":item_bits", ":item_no", 0xFFFF),
        (val_lshift, ":item_bits", 8),
        (agent_get_ammo_for_slot, ":number", ":agent_no", ":slot"),
        (store_and, ":number_bits", ":number", 0xFF),
        (store_or, ":data", ":troop_bits", ":item_bits"),
        (val_or, ":data", ":number_bits"),
        (troop_get_slot, ":number", "trp_ammo", 0),
        (val_add, ":number", 1),
        (troop_set_slot, "trp_ammo", 0, ":number"),
        (troop_set_slot, "trp_ammo", ":number", ":data"),
     (try_end),
  (try_end), ]),
 
("adjust_troops_ammo",
 [(troop_get_slot, ":number_slot", "trp_ammo", 0),
  (try_begin), 
      (gt, ":number_slot", 0),
      (val_add, ":number_slot", 1),
      (try_for_range, ":slot",1, ":number_slot"),
         (troop_get_slot, ":data", "trp_ammo", ":slot"),
         (store_and, ":troop_no", ":data", 0xFFFF000000),
         (val_rshift,":troop_no", 24),
         (troop_is_hero, ":troop_no"),
         #(this_or_next|eq, ":troop_no", "trp_player"),    # uncomment these 2 lines
         #(main_party_has_troop, ":troop_no"),             # to apply only to player and companions
         (store_and, ":item_no", ":data", 0xFFFF00),
         (val_rshift,":item_no", 8),
         (gt, ":item_no", 0),
         (item_get_type, ":type", ":item_no"),
         (this_or_next|eq, ":type", itp_type_arrows),
         (this_or_next|eq, ":type", itp_type_bolts),
         (this_or_next|eq, ":type", itp_type_bullets),
         (eq, ":type", itp_type_thrown),     
         (store_and, ":number", ":data", 0xFF),
         (assign, ":found", 0),
         (try_for_range, ":inv_slot", 0, max_inventory_items),
            (eq, ":found", 0),
            (troop_get_inventory_slot, ":item_in_slot", ":troop_no", ":inv_slot"),        
            (eq, ":item_no", ":item_in_slot"),
            (troop_inventory_slot_get_item_max_amount,":max", ":troop_no", ":inv_slot"),
            (neq, ":number", ":max"),
            (troop_inventory_slot_get_item_amount, ":amount", ":troop_no", ":inv_slot"),        
            (eq, ":amount", ":max"),
            (try_begin),
               (eq, ":number", 0),
               (troop_set_inventory_slot, ":troop_no", ":inv_slot", -1),
            (else_try),
               (troop_inventory_slot_set_item_amount, ":troop_no", ":inv_slot", ":number"),
            (try_end),
            (assign, ":found", 1),
         (try_end),
         (troop_set_slot, "trp_ammo", ":slot", 0),
      (try_end),
      (try_for_range, ":slot",1, ":number_slot"),
         (troop_get_slot, ":data", "trp_ammo", ":slot"),
         (store_and, ":troop_no", ":data", 0xFFFF000000),
         (val_rshift,":troop_no", 24),
         (troop_is_hero, ":troop_no"),
         #(this_or_next|eq, ":troop_no", "trp_player"),
         #(main_party_has_troop, ":troop_no"),
         (store_and, ":item_no", ":data", 0xFFFF00),
         (val_rshift,":item_no", 8),
         (gt, ":item_no", 0),
         (item_get_type, ":weapon", ":item_no"),
         (assign, ":type", 0),
         (try_begin),
            (eq, ":weapon", itp_type_bow),
            (assign, ":type", itp_type_arrows),
         (else_try),   
            (eq, ":weapon", itp_type_crossbow),
            (assign, ":type", itp_type_bolts),
         (else_try),   
            (this_or_next|eq, ":weapon", itp_type_musket),
            (eq, ":weapon", itp_type_pistol),
            (assign, ":type", itp_type_bullets),
         (try_end),
         (neq, ":type", 0),     
         (store_and, ":ammo_left", ":data", 0xFF),
         (item_get_slot, ":max_ammo", ":item_no", slot_item_max_ammo),
         (store_sub, ":number", ":max_ammo", ":ammo_left"),
         (gt, ":number", 0),
         (try_for_range, ":inv_slot", 0, max_inventory_items),
            (gt, ":number", 0),
            (troop_get_inventory_slot, ":item_in_slot", ":troop_no", ":inv_slot"),        
            (gt, ":item_in_slot", 0),
            (item_get_type, ":type_in_slot", ":item_in_slot"),
            (eq, ":type", ":type_in_slot"),
            (troop_inventory_slot_get_item_amount, ":amount", ":troop_no", ":inv_slot"),        
            (try_begin),
               (ge, ":amount", ":number"),
               (val_sub, ":amount", ":number"),
               (assign, ":number", 0),
            (else_try),
               (val_sub, ":number", ":amount"),
               (assign, ":amount", 0),           
            (try_end),
            (try_begin),
               (eq, ":amount", 0),
               (troop_set_inventory_slot, ":troop_no", ":inv_slot", -1),
            (else_try),
               (troop_inventory_slot_set_item_amount, ":troop_no", ":inv_slot", ":amount"),
            (try_end),
         (try_end),
         (troop_set_slot, "trp_ammo", ":slot", 0),
      (try_end),
      (troop_set_slot, "trp_ammo", 0, 0),
  (try_end), ]),
  
("save_agents_ammo_to_slot",
 [(try_for_agents, ":agent"),
     (call_script, "script_save_agent_ammo_to_slot", ":agent"),
  (try_end), ]), # Dunde's Depleted Ammo END 

We must save agent's ammo just before quiting mission. for battle's mission, script_count_mission_casualties_from_agents is a good place for it has loops for all agents already.
Code:
  #script_count_mission_casualties_from_agents
  # INPUT: none
  # OUTPUT: none
  ("count_mission_casualties_from_agents",
    [(party_clear, "p_player_casualties"),
     (party_clear, "p_enemy_casualties"),
     (party_clear, "p_ally_casualties"),
     (assign, "$any_allies_at_the_last_battle", 0),
     #(assign, "$num_routed_us", 0), #these should not assign to 0 here to protect routed agents to spawn again in next turns.
     #(assign, "$num_routed_allies", 0),
     #(assign, "$num_routed_enemies", 0),

     #initialize all routed counts of troops
     (try_for_agents, ":cur_agent"),
       (agent_is_human, ":cur_agent"),
       (call_script, "script_save_agent_ammo_to_slot", ":cur_agent"), # Dunde's Depleted Ammo
       (agent_get_party_id, ":agent_party", ":cur_agent"),
It's tricky for non battle missions, we should take care of any possibile ti_on_leave_area and ti_tab_pressed,
adding this line to execute :
Code:
   (call_script, "script_save_agents_ammo_to_slot"),

Assigning the ammo values to troops :
- When on the world map.
Code:
(0, 
 [(map_free),
  (troop_slot_ge, "trp_ammo", 0, 1), 
  (call_script, "script_adjust_troops_ammo"), # Dunde's Depleted Ammo
 ]),
- And may be at menus that the mission ending jump to.
Add this line :
Code:
  (call_script, "script_adjust_troops_ammo"), # Dunde's Depleted Ammo
Don't worry about double/tripple calling of script_adjust_troops_ammo, only the 1st call has effect for it will reset the slots.

PS. It's not fix version yet for there are issues that should be fixed yet. I posted it here just to make harry's thread clean.
 
Who know the code in mod POP? It allow player take a special weapon from a king if you defeat him. Please help!! I need it
 
Lav said:
This is a wrong thread for such questions. Please post your request in the Forge Q&A.
Oh!!!"Describe your code, what it does. Interested modders will pm you for the code." You know :neutral:
 
Someone was asking about sending multiple caravans in WFaS and I decided to tackle this as my first foray into modding.  I've tested this as working with up to 4 caravans so far, but you need to add all the extra stuff for each additional caravan that you want to be able to send.

Hope someone finds this useful.

Line numbers are there as a reference and aren't exact, especially if you've got other stuff in there already.

Add quest to module_quests.py
Code:
("oim_deliver_caravan", "Deliver Caravan", 0, "{!}Do not translate"),
# Allow multiple caravans
 ("oim_deliver_caravan_2", "Deliver Caravan", 0, "{!}Do not translate"),

Add quest active check at 20623 in module_dialogs.py
Code:
(this_or_next|quest_slot_eq, "qst_oim_deliver_caravan", slot_quest_target_center, -1), 
# Multiple Caravans
      (this_or_next|neg|check_quest_active, "qst_oim_deliver_caravan"),
      (neg|check_quest_active, "qst_oim_deliver_caravan_2"),

Add quest dialog at 21030 in module_dialogs.py
Note - The initial quest is modified as such: (assign, "$oim_count_to_deliver_1", "$oim_count_to_deliver")
Code:
# First Caravan Start
      (try_begin),
         (neg|check_quest_active, "qst_oim_deliver_caravan"),

         #spawning caravan
         (set_spawn_radius,1),
         (spawn_around_party,"p_main_party", "pt_oim_merchant_caravan2"),
         (assign, ":oim_caravan", reg0),
         (assign, "$oim_count_to_deliver_1", "$oim_count_to_deliver"),
      
         (party_set_slot, ":oim_caravan", slot_party_type, spt_kingdom_caravan),
         (party_set_slot, ":oim_caravan", slot_party_ai_state, spai_undefined),

         (party_set_ai_behavior, ":oim_caravan", ai_bhvr_travel_to_party),      
         (party_set_ai_object, ":oim_caravan", "$town_suggested_to_go_to"),

         (party_set_flags, ":oim_caravan", pf_default_behavior, 0),
         (party_add_leader, ":oim_caravan", "trp_caravan_master"),
         (party_add_members, ":oim_caravan", "trp_caravan_guard", "$g_number_of_escorts"), #was fix 10 for every kind of caravan
      
         (try_begin),
              (gt, "$players_kingdom", 0),
              (party_set_faction, ":oim_caravan", "$players_kingdom"),
         (else_try),
              (party_set_faction, ":oim_caravan", "fac_player_faction"),
         (try_end),

         (troop_clear_inventory, "trp_oim_caravan_master"),
         (troop_add_items, "trp_oim_caravan_master", "$town_suggested_goods", "$oim_count_to_deliver"),

      
         (quest_set_slot, "qst_oim_deliver_caravan", slot_quest_current_state, 0),
         (quest_set_slot, "qst_oim_deliver_caravan", slot_quest_giver_troop, "trp_player"),  
         (quest_set_slot, "qst_oim_deliver_caravan", slot_quest_target_center, "$town_suggested_to_go_to"),  
         (quest_set_slot, "qst_oim_deliver_caravan", slot_quest_target_item, "$town_suggested_goods"),  
         (quest_set_slot, "qst_oim_deliver_caravan", slot_quest_target_amount, "$oim_count_to_deliver"),  
         (quest_set_slot, "qst_oim_deliver_caravan", slot_quest_target_party, ":oim_caravan"),  
         (setup_quest_text, "qst_oim_deliver_caravan"),   
         (str_store_party_name_link, s1, "$g_encountered_party"), 
         (str_store_party_name_link, s5, "$town_suggested_to_go_to"), 
         (str_store_item_name, s3, "$town_suggested_goods"), 
         (assign, reg0, "$oim_count_to_deliver"),
         (str_store_string, s2, "str_caravan_develireg_descr"),
         (call_script, "script_start_quest", "qst_oim_deliver_caravan", "trp_player"),
#First Caravan End
#Second Caravan Start
      (else_try),   
         (neg|check_quest_active, "qst_oim_deliver_caravan_2"),
         #spawning caravan
         (set_spawn_radius,1),
         (spawn_around_party,"p_main_party", "pt_oim_merchant_caravan2"),
         (assign, ":oim_caravan_2", reg0),
         (assign, "$oim_count_to_deliver_2", "$oim_count_to_deliver"),
      
         (party_set_slot, ":oim_caravan_2", slot_party_type, spt_kingdom_caravan),
         (party_set_slot, ":oim_caravan_2", slot_party_ai_state, spai_undefined),

         (party_set_ai_behavior, ":oim_caravan_2", ai_bhvr_travel_to_party),      
         (party_set_ai_object, ":oim_caravan_2", "$town_suggested_to_go_to"),

         (party_set_flags, ":oim_caravan_2", pf_default_behavior, 0),
         (party_add_leader, ":oim_caravan_2", "trp_caravan_master"),
         (party_add_members, ":oim_caravan_2", "trp_caravan_guard", "$g_number_of_escorts"), #was fix 10 for every kind of caravan
      
         (try_begin),
              (gt, "$players_kingdom", 0),
              (party_set_faction, ":oim_caravan_2", "$players_kingdom"),
         (else_try),
              (party_set_faction, ":oim_caravan_2", "fac_player_faction"),
         (try_end),

         (troop_clear_inventory, "trp_oim_caravan_master"),
         (troop_add_items, "trp_oim_caravan_master", "$town_suggested_goods", "$oim_count_to_deliver"),
         
         (quest_set_slot, "qst_oim_deliver_caravan_2", slot_quest_current_state, 0),
         (quest_set_slot, "qst_oim_deliver_caravan_2", slot_quest_giver_troop, "trp_player"),  
         (quest_set_slot, "qst_oim_deliver_caravan_2", slot_quest_target_center, "$town_suggested_to_go_to"),  
         (quest_set_slot, "qst_oim_deliver_caravan_2", slot_quest_target_item, "$town_suggested_goods"),  
         (quest_set_slot, "qst_oim_deliver_caravan_2", slot_quest_target_amount, "$oim_count_to_deliver"),  
         (quest_set_slot, "qst_oim_deliver_caravan_2", slot_quest_target_party, ":oim_caravan_2"),  
         (setup_quest_text, "qst_oim_deliver_caravan_2"),   
         (str_store_party_name_link, s1, "$g_encountered_party"), 
         (str_store_party_name_link, s5, "$town_suggested_to_go_to"), 
         (str_store_item_name, s3, "$town_suggested_goods"), 
         (assign, reg0, "$oim_count_to_deliver"),
         (str_store_string, s2, "str_caravan_develireg_descr"),
         (call_script, "script_start_quest", "qst_oim_deliver_caravan_2", "trp_player"),

#Second Caravan End

Add encounter dialog near 10003 in module_dialogs.py
Code:
#First Caravan
   (try_begin),    
      (quest_get_slot, ":party_no", "qst_oim_deliver_caravan", slot_quest_target_party),  
      (eq, ":party_no", "$g_encountered_party"),
# End First Caravan
# Second Caravan
   (else_try),
      (quest_get_slot, ":party_no", "qst_oim_deliver_caravan_2", slot_quest_target_party),
      (eq, ":party_no", "$g_encountered_party"),
(try_end),

Add encounter dialog near 10035 in module_dialogs.py

Code:
#First Caravan
   (try_begin),
      (quest_get_slot, ":party_no", "qst_oim_deliver_caravan", slot_quest_target_party),
      (eq, ":party_no", "$g_encountered_party"),      
      (quest_get_slot, ":goods", "qst_oim_deliver_caravan", slot_quest_target_item), 
      (str_store_item_name, s1, ":goods"),
      (quest_get_slot, ":count", "qst_oim_deliver_caravan", slot_quest_target_amount),
      (assign, reg1, ":count"),
      (quest_get_slot, ":target_center", "qst_oim_deliver_caravan", slot_quest_target_center),
      (str_store_party_name, s2, ":target_center"),
# End First Caravan
# Second Caravan
   (else_try),
      (quest_get_slot, ":party_no", "qst_oim_deliver_caravan_2", slot_quest_target_party),
      (eq, ":party_no", "$g_encountered_party"),
      (quest_get_slot, ":goods", "qst_oim_deliver_caravan_2", slot_quest_target_item), 
      (str_store_item_name, s1, ":goods"),
      (quest_get_slot, ":count", "qst_oim_deliver_caravan_2", slot_quest_target_amount),
      (assign, reg1, ":count"),
      (quest_get_slot, ":target_center", "qst_oim_deliver_caravan_2", slot_quest_target_center),
      (str_store_party_name, s2, ":target_center"),
   (try_end),

Add completion info at 15144 in module_game_menus.py
Note - oim_count_to_deliver_1 will again need to be set for the original quest.
Code:
# Second Caravan
(
    "oim_caravan_delivered_2",0,"All the caravan goods have been sold. After calculating all your expenses, you count a profit of {reg1} thaler.",
    "none",
    [
         #code
         (quest_get_slot, ":goods", "qst_oim_deliver_caravan_2", slot_quest_target_item), 
         (str_store_item_name, s2, ":goods"),
         (quest_get_slot, ":count", "qst_oim_deliver_caravan_2", slot_quest_target_amount),
         (quest_get_slot, ":party", "qst_oim_deliver_caravan_2", slot_quest_target_center),
         (call_script, "script_oim_get_item_base_price", ":goods"), 
         (assign, ":price", reg0),
         (assign, ":base_price", reg0),
         (try_begin), 
             (ge, ":base_price", 150), 
            (neg|check_quest_active, "qst_oim_trade_pantent"), 
            (neg|quest_slot_eq, "qst_oim_trade_pantent", slot_quest_current_state, 2),
            (quest_set_slot, "qst_oim_trade_pantent", slot_quest_current_state, 1),
            (quest_set_slot, "qst_oim_trade_pantent", slot_quest_giver_troop, "trp_player"),  
            (setup_quest_text, "qst_oim_trade_pantent"),   
            (str_store_string, s2, "str_trade_patent_text"),
            (call_script, "script_start_quest", "qst_oim_trade_pantent", "trp_player"),   
            (assign, "$g_notification_menu_var1", "str_oim_trade_troubles_descr"),
            (assign, "$g_notification_menu_var2", "mnu_oim_caravan_delivered"),
            (jump_to_menu, "mnu_notification_simple_str"),
         (else_try),          
           (call_script, "script_oim_game_get_item_buy_price_factor", ":goods", ":party"), 
           (assign, ":price_factor", reg0),
           (val_mul, ":price", ":price_factor"), 
           (val_div, ":price", 100),         

           (val_mul, ":price", ":count"), #count

           (store_sub, ":profit", ":price", "$g_total_caravan_cost_pure"),
           (try_begin),
             (get_achievement_stat, ":total_profit_till_now", ACHIEVEMENT_TRADER, 0),
            (val_add, ":total_profit_till_now", ":profit"),
            (set_achievement_stat, ACHIEVEMENT_TRADER, 0, ":total_profit_till_now"),
            (try_begin),
              (ge, ":total_profit_till_now", 100000),
              (unlock_achievement, ACHIEVEMENT_TRADER),              
            (try_end),

            (try_begin),
              (ge, ":total_profit_till_now", 1000000),
              (unlock_achievement, ACHIEVEMENT_GREAT_TRADER),              
            (try_end),

            (try_begin),
               (ge, ":profit", 3000),
              (unlock_achievement, ACHIEVEMENT_WHEELER_DEALER),            
            (try_end),
           (try_end),

           (try_begin), 
             (ge, ":base_price", 300), #if base price is more than 300 and trade patent is not yet taken, 10% of payment is taken as tax.
            (this_or_next|quest_slot_eq, "qst_oim_trade_pantent", slot_quest_current_state, 0),
            (quest_slot_eq, "qst_oim_trade_pantent", slot_quest_current_state, 1),            
            (assign, ":initial_price", ":price"),
            (val_mul, ":price", 90),
            (val_div, ":price", 100),             
            (store_sub, reg2, ":initial_price", ":price"),
            (str_store_string, s3, "str_percent_10_tax_is_paid"),
            
            (display_message, s3), 
           (else_try), 
             (ge, ":base_price", 150), #if base price is more than 200 and trade patent is not yet taken, 5% of payment is taken as tax.
            (this_or_next|quest_slot_eq, "qst_oim_trade_pantent", slot_quest_current_state, 0),
            (quest_slot_eq, "qst_oim_trade_pantent", slot_quest_current_state, 1),            
            (assign, ":initial_price", ":price"),
            (val_mul, ":price", 95),
            (val_div, ":price", 100),            
            (store_sub, reg2, ":initial_price", ":price"),
            (str_store_string, s3, "str_percent_5_tax_is_paid"),
            (display_message, s3), 
           (end_try), 
         
           (call_script, "script_troop_add_gold", "trp_player", ":price"),
           (assign, reg1, ":price"),
         
           (call_script, "script_oim_change_price_factors", ":party", ":goods", "$oim_count_to_deliver_2", 1),

           (assign, "$oim_count_to_deliver_2", 0),
            (try_end),
   ],
    [
      ("continue",[],"Continue...",[
         (call_script, "script_end_quest", "qst_oim_deliver_caravan_2"),
         (quest_set_slot, "qst_oim_deliver_caravan_2", slot_quest_target_center, -1),  
         (quest_set_slot, "qst_oim_deliver_caravan_2", slot_quest_target_item, -1),  
         (quest_set_slot, "qst_oim_deliver_caravan_2", slot_quest_target_amount, -1),  
         (quest_get_slot, ":party_no", "qst_oim_deliver_caravan_2", slot_quest_target_party),  
         (try_begin),
           (party_is_active, ":party_no"),
           (remove_party, ":party_no"),
            (try_end),
         (quest_set_slot, "qst_oim_deliver_caravan_2", slot_quest_target_party, -1),  
         (change_screen_return),
         #(jump_to_menu, "mnu_castle_outside"),
      ]),
    ],
    ),   
#End Second Caravan


&& 15362 in module_game_menus.py
Code:
#First Caravan
          (try_begin), 
         (eq, "$g_notification_menu_var2", "mnu_oim_caravan_delivered"),
         (assign, "$g_notification_menu_var2", -1),
         (jump_to_menu, "mnu_oim_caravan_delivered"),
## End First Caravan
# Second Caravan
      (else_try),
         (eq, "$g_notification_menu_var2", "mnu_oim_caravan_delivered_2"),
         (assign, "$g_notification_menu_var2", -1),
         (jump_to_menu, "mnu_oim_caravan_delivered_2"),
# End Second Caravan


Add trigger at 128 in module_simple_triggers.py
Note - oim_count_to_deliver_1 will again need to be setup for original quest
Code:
# Second Caravan
( 0,
   [
   (try_begin), 
      (check_quest_active,"qst_oim_deliver_caravan_2"),
      (quest_get_slot, ":party_no", "qst_oim_deliver_caravan_2", slot_quest_target_party),  
             (gt, ":party_no", 0),


      (assign, ":party_is_died", 0),

      (try_begin),
             (neg|party_is_active, ":party_no"),
         (assign, ":party_is_died", 1),
         (call_script, "script_cancel_quest", "qst_oim_deliver_caravan_2"),

         (quest_set_slot, "qst_oim_deliver_caravan_2", slot_quest_target_center, -1),  
         (quest_set_slot, "qst_oim_deliver_caravan_2", slot_quest_target_item, -1),  
         (quest_set_slot, "qst_oim_deliver_caravan_2", slot_quest_target_amount, -1),  
         (quest_set_slot, "qst_oim_deliver_caravan_2", slot_quest_target_party, -1),  
         (call_script, "script_add_notification_menu", "mnu_notification_simple_str", "str_oim_caravan_looted", -1),
             (try_end),
      
      (eq, ":party_is_died", 0),
 
        (quest_get_slot, ":target_center_no", "qst_oim_deliver_caravan_2", slot_quest_target_center),  

      (store_distance_to_party_from_party, ":caravan_distance_to_destination", ":target_center_no", ":party_no"),
      (assign, reg0, ":caravan_distance_to_destination"),
      (le, ":caravan_distance_to_destination", 1),
      (gt, "$oim_count_to_deliver_2", 0),
       (jump_to_menu, "mnu_oim_caravan_delivered_2"),165

   (end_try),
]),
# End Second Caravan
 
Making troop upgrade cost different amount of money depending on the path chosen.

Note this code assumes second upgrade path is not cheaper than first.

Code:
  # script_game_get_upgrade_cost_for_path
  # This script is called to determine the price of troop upgrade along the provided path (0 = first upgrade path, 1 = second upgrade path)
  # Code is just a stub, replace with whatever you need.
  # Input: arg1 = troop_id, arg2 = path
  # Output: reg0 = needed cost for upgrade
  ("game_get_upgrade_cost_for_path",
    [
      #(store_script_param_1, ":troop_id"),
      (store_script_param_2, ":path"),
      (assign, reg0, 100),
      (val_lshift, reg0, ":path"),
  ]),

  # script_game_get_upgrade_cost
  # This script is called from game engine for calculating needed troop upgrade exp
  # Input:
  # param1: troop_id,
  # Output: reg0 = needed cost for upgrade
  ("game_get_upgrade_cost",
    [
      (store_script_param_1, ":troop_id"),

      (try_begin),
        (gt, "$g_upgraded_troop_id", 0), # Last time was on a troop with more than 1 upgrade path
        (troop_get_upgrade_troop, ":tier1", "$g_upgraded_troop_id", 0),
        (troop_get_upgrade_troop, ":tier2", "$g_upgraded_troop_id", 1),
        (party_count_companions_of_type, ":tier1count", "p_main_party", ":tier1"),
        (party_count_companions_of_type, ":tier2count", "p_main_party", ":tier2"),
        (this_or_next|gt, ":tier1count", reg10),
        (gt, ":tier2count", reg11), # Number of upgraded troops increased since previous call!
        (try_begin),
          (gt, ":tier2count", reg11), # Number of upgraded troops in path2 increased since previous call!
          (call_script, "script_game_get_upgrade_cost_for_path", "$g_upgraded_troop_id", 1),
          (assign, ":price", reg0),
          (call_script, "script_game_get_upgrade_cost_for_path", "$g_upgraded_troop_id", 0),
          (val_sub, ":price", reg0),
          (store_sub, ":upgraded", ":tier2count", reg11),
          (val_mul, ":price", ":upgraded"),
          (set_show_messages, 0),
          (troop_remove_gold, "trp_player", ":price"),
          (set_show_messages, 1),
        (try_end),
        # Now cleaning up to imitate first run
        (assign, "$g_upgraded_counter", 0),
      (try_end),

      (troop_get_upgrade_troop, ":tier1", ":troop_id", 0),
      (troop_get_upgrade_troop, ":tier2", ":troop_id", 1),

      (try_begin),
        (gt, ":tier2", 0),
        (assign, "$g_upgraded_troop_id", ":troop_id"), # Set flag for next run
        (assign, ":path", "$g_upgraded_counter"),
        (store_sub, "$g_upgraded_counter", 1, "$g_upgraded_counter"), # Flip
        (party_count_companions_of_type, reg10, "p_main_party", ":tier1"), # Remember how many upgraded troops from 1st path are there
        (party_count_companions_of_type, reg11, "p_main_party", ":tier2"), # Remember how many upgraded troops from 2nd path are there
      (else_try),
        (assign, "$g_upgraded_troop_id", 0), # Reset flag
        (assign, ":path", 0),
      (try_end),
      (call_script, "script_game_get_upgrade_cost_for_path", ":troop_id", ":path"),
      (set_trigger_result, reg0),
  ]),
Code:
  (0, 0, 0, [(gt, "$g_upgraded_troop_id", 0)], [assign, "$g_upgraded_troop_id", 0]),

An important caveat: this will not detect the upgrade if the upgraded troop is at the top of the tree. This means that in order to use this code, top-level upgrades should not allow branching.
 
Can someone make a script to allow me to rob/attack barkeeper? o I could get $500, lose -5 relations with town, -1 with faction and -15 with the barkeeper?

Thanks
 
JuJu70 said:
Can someone make a script to allow me to rob/attack barkeeper? o I could get $500, lose -5 relations with town, -1 with faction and -15 with the barkeeper?

Thanks
You all the same can't add it in Brytenwalda.
 
Hunterwolf said:
JuJu70 said:
Can someone make a script to allow me to rob/attack barkeeper? o I could get $500, lose -5 relations with town, -1 with faction and -15 with the barkeeper?

Thanks
You all the same can't add it in Brytenwalda.

why not?
 
Hunterwolf said:
Because it is necessary to do it through modular system, and you to it don't have access.

This is exactly what I am asking for - a python script.
 
JuJu70 said:
Hunterwolf said:
Because it is necessary to do it through modular system, and you to it don't have access.

This is exactly what I am asking for - a python script.
A script wont help you, if you dont have access to the brytenwalda source code/module system. You cant add it without access.

This also isnt really the place to request code, its more of a place to share your code.
 
Duh said:
JuJu70 said:
Hunterwolf said:
Because it is necessary to do it through modular system, and you to it don't have access.

This is exactly what I am asking for - a python script.
A script wont help you, if you dont have access to the brytenwalda source code/module system. You cant add it without access.

This also isnt really the place to request code, its more of a place to share your code.

can't see any place to request code. Where should it be done?
 
Some WSE-enabled scripts for basic party-stack experience functions...written as close as I could get to appearing like 'native' operations.

Send an integer for the arguments that ask for a return register no: so send "0" not "reg0" if you want the value stored in register #0.
Code:
  # script_party_stack_get_xp #WSE
  # Input: arg1: return register no, arg2: party_no, arg3: stack_no
  # Output: regX: total stack XP
 ("party_stack_get_xp", 
   [
    (store_script_param, ":reg_no",   1),
    (store_script_param, ":party_no", 2),
    (store_script_param, ":stack_no", 3),
   
    (party_stack_get_troop_id, ":troop_id", ":party_no", ":stack_no"),
    (try_begin),
        (neg|troop_is_hero, ":troop_id"),
        (party_stack_get_num_upgradeable, ":num_to_upgrade", ":party_no", ":stack_no"),
        (call_script, "script_game_get_upgrade_xp", ":troop_id"),
        (val_mul, reg0, ":num_to_upgrade"),
        (party_stack_get_experience,  ":xp_to_next_upgrade", ":party_no", ":stack_no"),    
        
        (val_add, reg0, ":xp_to_next_upgrade"),    
    (else_try),
        (troop_get_xp, reg0, ":troop_id"),
    (try_end),
    (register_set, ":reg_no", reg0),
   ]),   

  # script_party_get_members_stack_no #WSE
  # Input: arg1: return register no, arg2: party_no, arg3: troop_id
  # Output: regX: total stack XP
 ("party_get_members_stack_no", 
  [
    (store_script_param, ":reg_no",   1),
    (store_script_param, ":party_no", 2),
    (store_script_param, ":troop_id", 3),
    
    (register_set, ":reg_no", -1),
    (party_get_num_companion_stacks, ":num_of_stacks", ":party_no"),
    (try_for_range, ":i", 0, ":num_of_stacks"),
        (party_stack_get_troop_id, ":stack_troop", ":party_no", ":i"),
        (eq, ":stack_troop", ":troop_id"),    
        (register_set, ":reg_no", ":i"),
        (assign, ":num_of_stacks", 0),
    (try_end),
  ]), 
  
  # script_party_stack_move_to_bottom #WSE
  # Input: arg1: party_no, arg2: stack_no, arg3: repeat times
  # Output: none  
  # adapted from Custom Commander
 ("party_stack_move_to_bottom",
   [
    (store_script_param, ":party_no", 1),
    (store_script_param, ":stack_no", 2),
    (store_script_param, ":times", 3),                                                
  
    (try_for_range, ":unused", 0, ":times"),
        (call_script, "script_party_stack_get_xp", 0, ":party_no", ":stack_no"), #WSE-enabled script that will maintain XP throughout
        (assign, ":prior_xp", reg0),
        (party_stack_get_troop_id, ":troop_id", ":party_no", ":stack_no"),
        (party_stack_get_size, ":stack_size", ":party_no", ":stack_no"),
        (party_stack_get_num_wounded, ":num_wounded", ":party_no", ":stack_no"),
        (party_remove_members, ":party_no", ":troop_id", ":stack_size"),
        (party_add_members, ":party_no", ":troop_id", ":stack_size"),
        (party_wound_members, ":party_no", ":troop_id", ":num_wounded"),
        (gt, ":prior_xp", 0),
        (call_script, "script_party_restore_members_xp", ":party_no", ":troop_id", ":prior_xp"),  #WSE-enabled script that will maintain XP throughout
    (try_end),
   ]),

  # script_party_restore_members_xp #WSE
  # Input: arg1: party_no, arg2: troop_id, arg3: prior_xp
  # Output: none
 ("party_restore_members_xp", 
   [
    (store_script_param, ":party_no", 1),
    (store_script_param, ":troop_id", 2), 
    (store_script_param, ":prior_xp", 3),
    
    (try_begin),
        (call_script, "script_party_get_members_stack_no", 0, ":party_no", ":troop_id"),
        (assign, ":stack_no", reg0),
        (neq, ":stack_no", -1),
        (call_script, "script_party_stack_get_xp", 0, ":party_no", ":stack_no"),
        (lt, reg0, ":prior_xp"),
        (store_sub, ":xp_to_add", ":prior_xp", reg0),
        (party_add_xp_to_stack, ":party_no", ":stack_no", ":xp_to_add"),
    (try_end),
   ]),
 
@ Mordchai

I used ur code in warband 1.143 into a new mode but no response..

i tried talking with prisoners and yet they repeat same words.. why?

P.S. : I am new to modding. thanks
 
This code makes it so all generals/counts in the faction use the same banner as their faction leader without having to have a ton of copies of that banner.  I needed it for my mod where the faction mattered more than the individual; and also so armies look more unified under that one banner.

Atm, I believe the banner will carry over even if they exile/defect to another faction; not sure how to fix that.  Assuming exiled generals don't get a castle or town, it won't be noticeable; and hopefully not enough lords will defect to make things odd :razz:

Code:
            #faction banners
      (faction_set_slot, "fac_kingdom_1", slot_faction_banner, "mesh_banner_f09"),
      (faction_set_slot, "fac_kingdom_2", slot_faction_banner, "mesh_banner_kingdom_f"),
      (faction_set_slot, "fac_kingdom_3", slot_faction_banner, "mesh_banner_kingdom_c"),
      (faction_set_slot, "fac_kingdom_4", slot_faction_banner, "mesh_banner_f10"),
      (faction_set_slot, "fac_kingdom_5", slot_faction_banner, "mesh_banner_kingdom_e"),
      (faction_set_slot, "fac_kingdom_6", slot_faction_banner, "mesh_banner_kingdom_a"),


##Run code start here

(try_for_range, ":cur_faction", npc_kingdoms_begin, npc_kingdoms_end),
        (faction_get_slot, ":cur_faction_king", ":cur_faction", slot_faction_leader),
        (faction_get_slot, ":cur_faction_banner", ":cur_faction", slot_faction_banner),
        (val_sub, ":cur_faction_banner", banner_meshes_begin),
        (val_add, ":cur_faction_banner", banner_scene_props_begin),
        (troop_set_slot, ":cur_faction_king", slot_troop_banner_scene_prop, ":cur_faction_banner"),
      (try_end),
  #    (assign, ":num_khergit_lords_assigned", 0),
  #    (assign, ":num_sarranid_lords_assigned", 0),
  #    (assign, ":num_other_lords_assigned", 0),

      (try_for_range, ":kingdom_hero", active_npcs_begin, active_npcs_end),
        (this_or_next|troop_slot_eq, ":kingdom_hero", slot_troop_occupation, slto_kingdom_hero),
        (troop_slot_eq, ":kingdom_hero", slot_troop_occupation, slto_inactive_pretender),

        (store_troop_faction, ":kingdom_hero_faction", ":kingdom_hero"),
        (neg|faction_slot_eq, ":kingdom_hero_faction", slot_faction_leader, ":kingdom_hero"),
#        (try_begin), 
#          (eq, ":kingdom_hero_faction", "fac_kingdom_3"), #Khergit Khanate
          #(store_add, ":kingdom_3_banners_begin", banner_scene_props_begin, khergit_banners_begin_offset),
          #(store_add, ":banner_id", ":kingdom_3_banners_begin", ":num_khergit_lords_assigned"),
#          (troop_set_slot, ":kingdom_hero", slot_troop_banner_scene_prop, ":banner_id"),
          #(val_add, ":num_khergit_lords_assigned", 1),
#        (else_try),
#          (eq, ":kingdom_hero_faction", "fac_kingdom_6"), #Sarranid Sultanate
          #(store_add, ":kingdom_6_banners_begin", banner_scene_props_begin, sarranid_banners_begin_offset),
          #(store_add, ":banner_id", ":kingdom_6_banners_begin", ":num_sarranid_lords_assigned"),
#          (troop_set_slot, ":kingdom_hero", slot_troop_banner_scene_prop, ":banner_id"),
#          (val_add, ":num_sarranid_lords_assigned", 1),
#        (else_try),
#          (assign, ":hero_offset", ":num_other_lords_assigned"),
#          (try_begin),
#            (gt, ":hero_offset", khergit_banners_begin_offset),#Do not add khergit banners to other lords
#            (val_add, ":hero_offset", khergit_banners_end_offset),
#            (val_sub, ":hero_offset", khergit_banners_begin_offset),
#          (try_end),
#          (try_begin),
#            (gt, ":hero_offset", sarranid_banners_begin_offset),#Do not add sarranid banners to other lords
#            (val_add, ":hero_offset", sarranid_banners_end_offset),
#            (val_sub, ":hero_offset", sarranid_banners_begin_offset),
#          (try_end),
#          (store_add, ":banner_id", banner_scene_props_begin, ":hero_offset"),
#          (troop_set_slot, ":kingdom_hero", slot_troop_banner_scene_prop, ":banner_id"),
#          (val_add, ":num_other_lords_assigned", 1),
#        (try_end),

        (try_begin), 
          (eq, ":kingdom_hero_faction", "fac_kingdom_1"), #Swadia
          (faction_get_slot, ":cur_faction_banner", "fac_kingdom_1", slot_faction_banner),
          (val_sub, ":cur_faction_banner", banner_meshes_begin),
          (val_add, ":cur_faction_banner", banner_scene_props_begin),
          (troop_set_slot, ":kingdom_hero", slot_troop_banner_scene_prop, ":cur_faction_banner"),
        (else_try),
          (eq, ":kingdom_hero_faction", "fac_kingdom_2"), #Vaegir
          (faction_get_slot, ":cur_faction_banner", "fac_kingdom_2", slot_faction_banner),
          (val_sub, ":cur_faction_banner", banner_meshes_begin),
          (val_add, ":cur_faction_banner", banner_scene_props_begin),
          (troop_set_slot, ":kingdom_hero", slot_troop_banner_scene_prop, ":cur_faction_banner"),
        (else_try),
          (eq, ":kingdom_hero_faction", "fac_kingdom_3"), #Khergit Khanate
          (faction_get_slot, ":cur_faction_banner", "fac_kingdom_3", slot_faction_banner),
          (val_sub, ":cur_faction_banner", banner_meshes_begin),
          (val_add, ":cur_faction_banner", banner_scene_props_begin),
          (troop_set_slot, ":kingdom_hero", slot_troop_banner_scene_prop, ":cur_faction_banner"),
        (else_try),
          (eq, ":kingdom_hero_faction", "fac_kingdom_4"), #Nords
          (faction_get_slot, ":cur_faction_banner", "fac_kingdom_4", slot_faction_banner),
          (val_sub, ":cur_faction_banner", banner_meshes_begin),
          (val_add, ":cur_faction_banner", banner_scene_props_begin),
          (troop_set_slot, ":kingdom_hero", slot_troop_banner_scene_prop, ":cur_faction_banner"),
        (else_try),
          (eq, ":kingdom_hero_faction", "fac_kingdom_5"), #Rhodok
          (faction_get_slot, ":cur_faction_banner", "fac_kingdom_5", slot_faction_banner),
          (val_sub, ":cur_faction_banner", banner_meshes_begin),
          (val_add, ":cur_faction_banner", banner_scene_props_begin),
          (troop_set_slot, ":kingdom_hero", slot_troop_banner_scene_prop, ":cur_faction_banner"),
        (else_try),
          (eq, ":kingdom_hero_faction", "fac_kingdom_6"), #Sarannid
          (faction_get_slot, ":cur_faction_banner", "fac_kingdom_6", slot_faction_banner),
          (val_sub, ":cur_faction_banner", banner_meshes_begin),
          (val_add, ":cur_faction_banner", banner_scene_props_begin),
          (troop_set_slot, ":kingdom_hero", slot_troop_banner_scene_prop, ":cur_faction_banner"),
        (try_end),

    #    (try_begin),
    #      (this_or_next|lt, ":banner_id", banner_scene_props_begin),
    #      (gt, ":banner_id", banner_scene_props_end_minus_one),
    #      (display_message, "@{!}ERROR: Not enough banners for heroes!"),
    #    (try_end),

##Run code end here

        (store_character_level, ":level", ":kingdom_hero"),
        (store_mul, ":renown", ":level", ":level"),
        (val_div, ":renown", 4), #for top lord, is about 400

		(troop_get_slot, ":age", ":kingdom_hero", slot_troop_age),
        (store_mul, ":age_addition", ":age", ":age"),
        (val_div, ":age_addition", 8), #for top lord, is about 400
		(val_add, ":renown", ":age_addition"),

It works with more than 6 factions as well, just add another

Code:
        (else_try),
          (eq, ":kingdom_hero_faction", "fac_kingdom_7"), #New Faction
          (faction_get_slot, ":cur_faction_banner", "fac_kingdom_7", slot_faction_banner),
          (val_sub, ":cur_faction_banner", banner_meshes_begin),
          (val_add, ":cur_faction_banner", banner_scene_props_begin),
          (troop_set_slot, ":kingdom_hero", slot_troop_banner_scene_prop, ":cur_faction_banner"),
        (try_end),

code section and bump up the number to 7, then paste it again for 8, etc.  Just make sure the "(try_end)," is after the last one and not after any others.
 
Okay Im a bit of a nub, and Im trying to set this up and for the life of me I cannot figure this out.
where is module_dialogs.py at?
 
Back
Top Bottom