Problems with a Script

正在查看此主题的用户

SkyShadowing

Sergeant
I've been working on getting a new race into the game, and so far have met with great success. However, M&B scripting, indeed Python scripting, is a new territory for me.

This script is supposed to have it set up so that if a faction made up of the new race (culture type 6) controls a town or village, it will replace the townspeople with people of said race.

The only problem is it doesn't work. Can anyone tell me what's wrong with it? Or if it's just some glitch?

插入代码块:
  ("center_set_walker_to_type",
   [
       (store_script_param, ":center_no", 1),
       (store_script_param, ":walker_no", 2),
       (store_script_param, ":walker_type", 3),
       (store_script_param, ":faction_no", 4),
       (store_add, ":type_slot", slot_center_walker_0_type, ":walker_no"),
       (party_set_slot, ":center_no", ":type_slot", ":walker_type"),
       (try_begin),
         (faction_slot_eq, ":faction_no", slot_faction_culture, "fac_culture_6"),
         (party_slot_eq, ":center_no", slot_party_type, spt_village),
         (store_random_in_range, ":walker_troop_id", dracvillage_walkers_begin, dracvillage_walkers_end),
       (else_try),
         (party_slot_eq, ":center_no", slot_party_type, spt_village),
         (store_random_in_range, ":walker_troop_id", village_walkers_begin, village_walkers_end),
       (else_try),
         (faction_slot_eq, ":faction_no", slot_faction_culture, "fac_culture_6"),
         (store_random_in_range, ":walker_troop_id", dractown_walkers_begin, dractown_walkers_end),
       (else_try),
         (store_random_in_range, ":walker_troop_id", town_walkers_begin, town_walkers_end),
       (try_end),
       (try_begin),
         (eq,":walker_type",walkert_spy),
         (assign,":original_walker",":walker_troop_id"),
         (val_add,":walker_troop_id",4), # select spy troop id

         # restore spy inventory
         (try_for_range,":item_no","itm_horse_meat","itm_wooden_stick"),
            (store_item_kind_count,":num_items",":item_no",":original_walker"),
            (ge,":num_items",1),
            (store_item_kind_count,":num_items",":item_no",":walker_troop_id"),
            (lt,":num_items",1),
            (troop_add_items,":walker_troop_id",":item_no",1),
         (try_end),
         # determine spy recognition item
         (store_random_in_range,":spy_item_type",itp_type_head_armor,itp_type_hand_armor),
         (assign,":num",0),
         (try_for_range,":item_no","itm_horse_meat","itm_wooden_stick"),
            (store_item_kind_count,":num_items",":item_no",":walker_troop_id"),
            (ge,":num_items",1),
            (item_get_type, ":itp", ":item_no"),
            (eq,":itp",":spy_item_type"),
            (val_add,":num",1),
            (troop_remove_items,":walker_troop_id",":item_no",":num_items"),
         (try_end),
         (store_random_in_range,":random_item",0,":num"),
         (assign,":num",-1),
         (try_for_range,":item_no","itm_horse_meat","itm_wooden_stick"),
            (store_item_kind_count,":num_items",":item_no",":original_walker"),
            (ge,":num_items",1),
            (item_get_type, ":itp", ":item_no"),
            (eq,":itp",":spy_item_type"),
            (val_add,":num",1),
            (eq,":num",":random_item"),
            (troop_add_items,":walker_troop_id",":item_no",1),
            (assign,":spy_item",":item_no"),
         (try_end),
         (assign,"$spy_item_worn",":spy_item"),
         (assign,"$spy_quest_troop",":walker_troop_id"),
         (troop_equip_items,":walker_troop_id"),
       (try_end),
       (store_add, ":troop_slot", slot_center_walker_0_troop, ":walker_no"),
       (party_set_slot, ":center_no", ":troop_slot", ":walker_troop_id"),
       (store_random_in_range, ":walker_dna", 0, 1000000),
       (store_add, ":dna_slot", slot_center_walker_0_dna, ":walker_no"),
       (party_set_slot, ":center_no", ":dna_slot", ":walker_dna"),
     ]),
 
插入代码块:
  ("center_set_walker_to_type",
   [
       (store_script_param_1, ":center_no",),
       (store_script_param_2, ":walker_no"),
       (store_script_param, ":walker_type", 3),
       # changed begin
       #(store_script_param, ":faction_no", 4),
       # instead of 4th parameter, I add store_faction_of_party operation
       (store_faction_of_party, ":faction_no", ":center_no"),
       (store_add, ":type_slot", slot_center_walker_0_type, ":walker_no"),
       (party_set_slot, ":center_no", ":type_slot", ":walker_type"),
       (try_begin),
         (party_slot_eq, ":center_no", slot_party_type, spt_village),
         (try_begin),
           (faction_slot_eq, ":faction_no", slot_faction_culture, "fac_culture_6"),
           (store_random_in_range, ":walker_troop_id", dracvillage_walkers_begin, dracvillage_walkers_end),
         (else_try),
           (party_slot_eq, ":center_no", slot_party_type, spt_village),
           (store_random_in_range, ":walker_troop_id", village_walkers_begin, village_walkers_end),
         (try_end),
       (else_try),
         (faction_slot_eq, ":faction_no", slot_faction_culture, "fac_culture_6"),
         (store_random_in_range, ":walker_troop_id", dractown_walkers_begin, dractown_walkers_end),
       (else_try),
         (store_random_in_range, ":walker_troop_id", town_walkers_begin, town_walkers_end),
       (try_end),
       # changed end
 
Hmm... I don't know, but it doesn't seem to be working. Does it take a long time to initialize or something? I have no idea how this game works, lol.

EDIT:
It may be knowledgable to note that this culture does not appear on the map at the beginning. It's a player-founded faction.
 
I think Foxyman's way to check the center's faction instead of using the 4th parameter is better. So we don't have to change the call_script part.
Btw, how about if there's a spy on town, what's his race?
 
I've been doing some similar work, making it so that the village walkers will change with the faction that owns it. Part of the problem is that the walkers aren't tied to the kingdom, but the culture, so you have to call another thing to get the culture.  Also, you need to call the code in the init_walkers script, here's mine:

插入代码块:
("init_town_walkers",
    [(try_begin),
       (eq, "$town_nighttime", 0),
       (try_for_range, ":walker_no", 0, num_town_walkers),
         (store_add, ":troop_slot", slot_center_walker_0_troop, ":walker_no"),
         (party_get_slot, ":walker_troop_id", "$current_town", ":troop_slot"),
         (store_faction_of_party, ":village_faction","$current_town"), # You'll be wanting to modify these three lines
        (faction_get_slot, ":culture", ":village_faction", slot_faction_culture),# this one
        (faction_get_slot, ":walker_troop_id",":culture",slot_faction_walker),# this one

         (gt, ":walker_troop_id", 0),
         (store_add, ":entry_no", town_walker_entries_start, ":walker_no"),
         (set_visitor, ":entry_no", ":walker_troop_id"),
       (try_end),
###Native has a **** load of stuff commented out here
)],

Basically, just replace the three lines I have with comments on the end with your stuff, and it should work! You should note that the new walkers probably won't behave like walkers, unless you put them in between the native walker troops in the module system.
 
When I replace that script, I get a whole lot of error messages that slot_faction_walker is not defined.

Thanks for helping. I'm still learning this whole deal, lol. I have literally no idea what I'm doing yet.

EDIT: After further playtesting, I've found that it is working to an extent (minus what you suggested above, Zarthas). My new walkers are randomly spawned in with the original walkers. Which means that should the walkers have already been spawned for said town, by a prior visit, they don't reset, and the new walkers don't roam with them.
 
后退
顶部 底部