Author Topic: PYTHON SCRIPT/SCHEME EXCHANGE  (Read 112231 times)

0 Members and 1 Guest are viewing this topic.

dunde

  • Grandmaster Knight
  • *
  • Curious Coder of The Vision
    • View Profile
  • Faction: Swadian
  • WB
Re: PYTHON SCRIPT/SCHEME EXCHANGE
« Reply #600 on: January 12, 2012, 11:34:22 AM »
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: (module_troops.py) [Select]
  ["ammo", "{!}na","{!}na",tf_hero|tf_inactive,0,reserved,fac_neutral,[],0,0,0,0],   

The slot :
Code: (module_constants.py) [Select]
slot_item_max_ammo = 101 # use another slot number if you wish

The scripts
Code: ( a python script to be placed above scripts = [ ) [Select]
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: (place it at "game_start" script for initialization) [Select]
(call_script, "script_init_max_ammo"),

Code: (new scripts) [Select]
# 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) [Select]
  #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: [Select]
   (call_script, "script_save_agents_ammo_to_slot"),

Assigning the ammo values to troops :
- When on the world map.
Code: (from simple trigger) [Select]
(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: [Select]
  (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.
« Last Edit: January 15, 2012, 11:09:28 AM by dunde »
Wujudkan Indonesia damai tanpa FPI
Vision LE Demo Movie

NewBie-BR

  • Veteran
  • *
  • Mod game like a game
    • View Profile
  • Faction: Swadian
Re: PYTHON SCRIPT/SCHEME EXCHANGE
« Reply #601 on: January 22, 2012, 02:57:32 PM »
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

  • Knight
  • *
    • View Profile
  • Faction: Vaegir
  • MP nick: Lav
  • M&BWB
Re: PYTHON SCRIPT/SCHEME EXCHANGE
« Reply #602 on: January 22, 2012, 03:53:51 PM »
This is a wrong thread for such questions. Please post your request in the Forge Q&A.

NewBie-BR

  • Veteran
  • *
  • Mod game like a game
    • View Profile
  • Faction: Swadian
Re: PYTHON SCRIPT/SCHEME EXCHANGE
« Reply #603 on: January 22, 2012, 04:32:17 PM »
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 :|

Specialist

  • Sergeant Knight at Arms
  • *
  • World War 3 Team Leader
    • View Profile
  • Faction: Neutral
  • MP nick: TheSpecialist
  • WB
Re: PYTHON SCRIPT/SCHEME EXCHANGE
« Reply #604 on: January 22, 2012, 05:10:21 PM »
Yeah...that means "If you have a code, describe what it does and interested modders that want it will pm you" :lol:

NewBie-BR

  • Veteran
  • *
  • Mod game like a game
    • View Profile
  • Faction: Swadian
Re: PYTHON SCRIPT/SCHEME EXCHANGE
« Reply #605 on: January 22, 2012, 05:13:54 PM »
Yeah...that means "If you have a code, describe what it does and interested modders that want it will pm you" :lol:
Thanks.

bobross419

  • Sergeant
  • *
    • View Profile
  • Faction: Vaegir
  • M&BWBWF&S
Re: PYTHON SCRIPT/SCHEME EXCHANGE
« Reply #606 on: January 23, 2012, 11:45:05 PM »
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: [Select]
("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: [Select]
(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: [Select]
# 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: [Select]
#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: [Select]
#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: [Select]
# 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: [Select]
#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: [Select]
# 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
« Last Edit: January 23, 2012, 11:49:28 PM by bobross419 »
Nationalism. Almost as serious a business as the internet. Some of these diatribes feel like necroposts from the 19th century... *sigh*

Lav

  • Knight
  • *
    • View Profile
  • Faction: Vaegir
  • MP nick: Lav
  • M&BWB
Re: PYTHON SCRIPT/SCHEME EXCHANGE
« Reply #607 on: January 31, 2012, 06:44:52 AM »
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: (module_scripts.py) [Select]
  # 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: (module_triggers.py) [Select]
  (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.

Hunterwolf

  • Sergeant Knight at Arms
  • *
  • Dividite,et vincere
    • View Profile
  • Faction: Vaegir
  • WB
Re: PYTHON SCRIPT/SCHEME EXCHANGE
« Reply #608 on: January 31, 2012, 03:42:02 PM »
Lav,This that that just now is necessary for me, you have written it then when it is necessary, Thanks for work. :D :D :D


JuJu70

  • Squire
  • *
    • View Profile
  • Faction: Neutral
Re: PYTHON SCRIPT/SCHEME EXCHANGE
« Reply #609 on: February 04, 2012, 06:04:25 PM »
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

Hunterwolf

  • Sergeant Knight at Arms
  • *
  • Dividite,et vincere
    • View Profile
  • Faction: Vaegir
  • WB
Re: PYTHON SCRIPT/SCHEME EXCHANGE
« Reply #610 on: February 04, 2012, 06:31:21 PM »
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.


JuJu70

  • Squire
  • *
    • View Profile
  • Faction: Neutral
Re: PYTHON SCRIPT/SCHEME EXCHANGE
« Reply #611 on: February 04, 2012, 07:43:22 PM »
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

  • Sergeant Knight at Arms
  • *
  • Dividite,et vincere
    • View Profile
  • Faction: Vaegir
  • WB
Re: PYTHON SCRIPT/SCHEME EXCHANGE
« Reply #612 on: February 04, 2012, 07:49:36 PM »
Because it is necessary to do it through modular system, and you to it don't have access.


JuJu70

  • Squire
  • *
    • View Profile
  • Faction: Neutral
Re: PYTHON SCRIPT/SCHEME EXCHANGE
« Reply #613 on: February 05, 2012, 01:22:03 AM »
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.

Duh

  • Grandmaster Knight
  • *
  • I like the way you taste.
    • View Profile
  • Faction: Rhodok
  • MP nick: Sir Simpleton
  • M&BWB
Re: PYTHON SCRIPT/SCHEME EXCHANGE
« Reply #614 on: February 05, 2012, 01:25:32 AM »
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.
Modding Wiki
Floris wants you!
Windys Tournaments summarized:
The first time you get smacked in the head for 200+ damage or catch a crossbow bolt to the grill your butthole will pucker up a little and the game becomes very exciting!