Changing Armor via Script

Users who are viewing this thread

Yagababa

Regular
Hey all,

I'm trying to make a 'cursed doubloon' item--when you receive a fatal blow, it gets removed from your inventory, you're restored to full hp and become a skeleton. It all works great except for that last bit, I'm having a hard time figuring out how to switch out armor via a script. Here's what I have:

Code:
        # Cursed Doubloon Check
        (try_for_range, ":i", ek_item_0, ek_head),
            (agent_get_item_slot, ":item", ":agent_no", ":i"),
            (eq, ":item", "itm_cursed_doubloon"),
            (try_begin),
                (store_agent_hit_points, ":hp", ":agent_no", 1),
                (gt, ":damage", ":hp"),

                (agent_set_hit_points, ":agent_no", 100, 0),
                (agent_unequip_item, ":agent_no", "itm_cursed_doubloon"),

                # Problem Area
                (agent_get_item_slot, ":agent_helmet", ":agent_no", 4),
                (agent_get_item_slot, ":agent_armor", ":agent_no", 5),
                (agent_get_item_slot, ":agent_boots", ":agent_no", 6),
                (agent_get_item_slot, ":agent_gauntlets", ":agent_no", 7),

                (agent_unequip_item, ":agent_no", ":agent_helmet"),
                (agent_unequip_item, ":agent_no", ":agent_armor"),
                (agent_unequip_item, ":agent_no", ":agent_boots"),
                (agent_unequip_item, ":agent_no", ":agent_gauntlets"),

                (agent_equip_item, ":agent_no", "itm_skeleton_skull"),
                (agent_equip_item, ":agent_no", "itm_skeleton_body"),
                (agent_equip_item, ":agent_no", "itm_skeleton_feet"),
                (agent_equip_item, ":agent_no", "itm_skeleton_hands"),
                # End Problem Area

                (set_trigger_result, 0),
            (try_end),
        (try_end),

Is there a different way to force an armor change mid-fight?
 
I do armor swaps for a few characters in my mod and the script I use is fairly similar, just with item slot optional variable added to the equip operations. I wonder if the real difference is from you using WFaS and my mod being Warband.

Python:
(try_for_range, ":slot", 4, 8), # Loops through slots 4 - 7, head, body, foot then gloves
    (agent_get_item_slot, ":item", ":agent", ":slot"),
               
    (try_begin),
        (gt, ":item", 0),    # Is there an item equipped
        (agent_unequip_item, ":agent", ":item"),
    (try_end),
(try_end),

(agent_equip_item, ":agent", "itm_skeleton_skull", 4), # Head, You could use ek_*** constants for readability as well
(agent_equip_item, ":agent", "itm_skeleton_body", 5), # Body
(agent_equip_item, ":agent", "itm_skeleton_feet", 6), # Feet
(agent_equip_item, ":agent", "itm_skeleton_hands", 7), # Gloves

Actually, this is a more direct copy-paste of mine, it uses a different hero troop to copy the equipment from.
Python:
(try_for_range, ":slot", 0, 8),
    (agent_get_item_slot, ":item", ":agent", ":slot"),
   
    (try_begin),
        (gt, ":item", 0),
        (agent_unequip_item, ":agent", ":item"),
    (try_end),
   
    (troop_get_inventory_slot, ":newitem", "trp_skeleton", ":slot"),
   
    (try_begin),
        (gt, ":newitem", 0),
        (agent_equip_item, ":agent", ":newitem", ":slot"),
    (try_end),
   
(try_end),

Test it and let me know.
 
Upvote 0
I do armor swaps for a few characters in my mod and the script I use is fairly similar, just with item slot optional variable added to the equip operations. I wonder if the real difference is from you using WFaS and my mod being Warband.

Python:
(try_for_range, ":slot", 4, 8), # Loops through slots 4 - 7, head, body, foot then gloves
    (agent_get_item_slot, ":item", ":agent", ":slot"),
             
    (try_begin),
        (gt, ":item", 0),    # Is there an item equipped
        (agent_unequip_item, ":agent", ":item"),
    (try_end),
(try_end),

(agent_equip_item, ":agent", "itm_skeleton_skull", 4), # Head, You could use ek_*** constants for readability as well
(agent_equip_item, ":agent", "itm_skeleton_body", 5), # Body
(agent_equip_item, ":agent", "itm_skeleton_feet", 6), # Feet
(agent_equip_item, ":agent", "itm_skeleton_hands", 7), # Gloves

Actually, this is a more direct copy-paste of mine, it uses a different hero troop to copy the equipment from.
Python:
(try_for_range, ":slot", 0, 8),
    (agent_get_item_slot, ":item", ":agent", ":slot"),
 
    (try_begin),
        (gt, ":item", 0),
        (agent_unequip_item, ":agent", ":item"),
    (try_end),
 
    (troop_get_inventory_slot, ":newitem", "trp_skeleton", ":slot"),
 
    (try_begin),
        (gt, ":newitem", 0),
        (agent_equip_item, ":agent", ":newitem", ":slot"),
    (try_end),
 
(try_end),

Test it and let me know.

Tried it out, didn't work unfortunately. I should also mention this is for multiplayer--I looked through the script for upgrading equipment and tried this:

Code:
# Cursed Doubloon Check
cursed_doubloon = (ti_on_agent_hit, 0, 0, [(multiplayer_is_server)], [

(store_trigger_param_1, ":agent_no"),
(store_trigger_param_3, ":damage"),

(try_for_range, ":i", ek_item_0, ek_head),
    (agent_get_item_slot, ":item", ":agent_no", ":i"),
    (eq, ":item", "itm_cursed_doubloon"),
    (try_begin),
        (store_agent_hit_points, ":hp", ":agent_no", 1),
        (gt, ":damage", ":hp"),

        (agent_set_hit_points, ":agent_no", 100, 0),
        (agent_unequip_item, ":agent_no", "itm_cursed_doubloon"),

        (get_max_players, ":num_players"),
        (try_for_range, ":slot", 4, 8), # Loops through slots 4 - 7, head, body, foot then gloves
            (agent_get_item_slot, ":item", ":agent_no", ":slot"),
            (try_begin),
                (gt, ":item", 0),    # Is there an item equipped
                (agent_unequip_item, ":agent_no", ":item", ":slot"),

                (try_for_range, ":cur_player", 1, ":num_players"),
                    (player_is_active, ":cur_player"),
                    (multiplayer_send_4_int_to_player, ":cur_player", multiplayer_event_other_events, multiplayer_event_other_event_unequip_item,
                        ":agent_no", ":item", ":slot"),
                (try_end),
            (try_end),
        (try_end),

        (agent_equip_item, ":agent_no", "itm_skeleton_skull", 4), # Head, You could use ek_*** constants for readability as well
        (agent_equip_item, ":agent_no", "itm_skeleton_body", 5), # Body
        (agent_equip_item, ":agent_no", "itm_skeleton_feet", 6), # Feet
        (agent_equip_item, ":agent_no", "itm_skeleton_hands", 7), # Gloves

        (try_for_range, ":cur_player", 1, ":num_players"),
            (player_is_active, ":cur_player"),
            (multiplayer_send_3_int_to_player, ":cur_player", multiplayer_event_other_events, multiplayer_event_other_event_equip_item,
                ":agent_no", "itm_skeleton_skull"),
            (multiplayer_send_3_int_to_player, ":cur_player", multiplayer_event_other_events, multiplayer_event_other_event_equip_item,
                ":agent_no", "itm_skeleton_body"),
            (multiplayer_send_3_int_to_player, ":cur_player", multiplayer_event_other_events, multiplayer_event_other_event_equip_item,
                ":agent_no", "itm_skeleton_feet"),
            (multiplayer_send_3_int_to_player, ":cur_player", multiplayer_event_other_events, multiplayer_event_other_event_equip_item,
                ":agent_no", "itm_skeleton_hands"),
        (try_end),

        (set_trigger_result, 0),
    (try_end),
(try_end),
])

But it crashed my game. I think the doubloon was getting removed based on my initial code, and I've used agent_unequip_item for weapons before and it has worked fine without the multiplayer events so I'm not sure why it isn't working for armor.

Update: this code removes the equipment properly, but multiplayer_event_other_event_equip_item crashes the game.
 
Last edited:
Upvote 0
WSE2 was ported to WFaS by K700 some time ago and all Warband operations are available in the game with WSE2. Give it a try to make sure all tools will be at your disposal.
I'm using the WFaS build, it's a godsend. I'm just very frustrated because this command has worked before with weapons but not with armor currently.
 
Upvote 0
At the multiplayer it is working differently, you need to respawn an agent so that his inventory gets refreshed afaik. @Pitch might have ideas here in case you haven't asked him already about it.
Figured it out! Not sure why this works but it does.

Code:
# Cursed Doubloon Check
cursed_doubloon = (ti_on_agent_hit, 0, 0, [(multiplayer_is_server)], [

(store_trigger_param_1, ":agent_no"),
(store_trigger_param_3, ":damage"),

(try_for_range, ":i", ek_item_0, ek_head),
    (agent_get_item_slot, ":item", ":agent_no", ":i"),
    (eq, ":item", "itm_cursed_doubloon"),
    (try_begin),
        (store_agent_hit_points, ":hp", ":agent_no", 1),
        (gt, ":damage", ":hp"),

        (agent_set_hit_points, ":agent_no", 100, 0),
        (agent_unequip_item, ":agent_no", "itm_cursed_doubloon"),

        (get_max_players, ":num_players"),
        (try_for_range, ":slot", 4, 8), # Loops through slots 4 - 7, head, body, foot then gloves
            (agent_get_item_slot, ":item", ":agent_no", ":slot"),
            (try_begin),
                (gt, ":item", 0),    # Is there an item equipped
                (agent_unequip_item, ":agent_no", ":item", ":slot"),

                (try_for_range, ":cur_player", 1, ":num_players"),
                    (player_is_active, ":cur_player"),
                    (multiplayer_send_4_int_to_player, ":cur_player", multiplayer_event_other_events, multiplayer_event_other_event_unequip_item,
                        ":agent_no", ":item", ":slot"),
                (try_end),
            (try_end),
        (try_end),

        (agent_equip_item, ":agent_no", "itm_skeleton_skull", 4), # Head, You could use ek_*** constants for readability as well
        (agent_equip_item, ":agent_no", "itm_skeleton_body", 5), # Body
        (agent_equip_item, ":agent_no", "itm_skeleton_feet", 6), # Boots
        (agent_equip_item, ":agent_no", "itm_skeleton_hands", 7), # Gloves

        (try_for_range, ":cur_player", 1, ":num_players"),
            (player_is_active, ":cur_player"),
            (multiplayer_send_3_int_to_player, ":cur_player", multiplayer_event_other_events, multiplayer_event_other_event_equip_item,
                ":agent_no", "itm_skeleton_skull"),
            (multiplayer_send_3_int_to_player, ":cur_player", multiplayer_event_other_events, multiplayer_event_other_event_equip_item,
                ":agent_no", "itm_skeleton_body"),
            (multiplayer_send_3_int_to_player, ":cur_player", multiplayer_event_other_events, multiplayer_event_other_event_equip_item,
                ":agent_no", "itm_skeleton_hands"),
            (multiplayer_send_3_int_to_player, ":cur_player", multiplayer_event_other_events, multiplayer_event_other_event_equip_item,
                ":agent_no", "itm_skeleton_feet"),
        (try_end),

        (set_trigger_result, 0),
    (try_end),
(try_end),
])
 
Upvote 0
Back
Top Bottom