Change soldiers into sailors (single)

Users who are viewing this thread

Hello everyone, I have a problem with a code, actually, the code works, but only half ... (a friend of Discord made me the code)
I want to convert land soldiers to sailors for naval battles, I have this code that converts them, but in the troop orders panel, the replaced soldiers appear as dead and the new sailors appear as allies, which produces at the end of the battle, in the statistics, the sum of those deaths ..., but when I attack again or leave that battle, I have the same amount of troops, it is as if there had never been a battle. since the new troops do not adhere to the origin team
There is a post with a code that I already tried, but it is from 2009 and it does not work for me.
https://forums.taleworlds.com/index.php?threads/naval-battles.78272/post-2037657
Image
https://www.pinterest.cl/pin/426223552245366288/
Any help is welcome ... thanks
Code:
(ti_on_agent_spawn, 0, 0, [],
[
        (store_trigger_param_1, ":agent_no"),
        (agent_get_troop_id, ":troop", ":agent_no"),
        (agent_get_position, pos22, ":agent_no"),
        (agent_get_team, ":team", ":agent_no"),
        (assign, ":troop_to_use", 0),
        (assign, ":spawned_agent", -1),
        (try_begin), ########## Chile
                (is_between,":troop", tropas_ch1_ini,tropas_ch1_fin),#chile 1
                (agent_fade_out, ":agent_no"),
                (agent_set_visibility, ":agent_no", 0),
                (assign, ":troop_to_use", "trp_marino_recluta"),
            (else_try),############ Virreinato del Peru
                (is_between,":troop", tropas_vp1_ini,tropas_vp1_fin),#Virreinato del Peru 1
                (agent_set_visibility, ":agent_no", 0),
                (agent_fade_out, ":agent_no"),
                (assign, ":troop_to_use", "trp_marino_recluta_esp"),
            (else_try),############ Ejercito de los Andes
                (is_between,":troop", tropas_andes1_ini,tropas_andes1_fin),#los Andes 1
                (agent_set_visibility, ":agent_no", 0),
                (agent_fade_out, ":agent_no"),
                (assign, ":troop_to_use", "trp_marino_recluta"),
            (else_try),############ Alto Peru
                (is_between,":troop", tropas_ap1_ini,tropas_ap1_fin),#Alto Peru 1
                (agent_set_visibility, ":agent_no", 0),
                (agent_fade_out, ":agent_no"),
                (assign, ":troop_to_use", "trp_marino_recluta_esp"),
            (else_try),############ Provincias Unidas
                (is_between,":troop", tropas_pu1_ini,tropas_pu1_fin),#Provincias Unidas 1
                (agent_set_visibility, ":agent_no", 0),
                (agent_fade_out, ":agent_no"),
                (assign, ":troop_to_use", "trp_marino_recluta"),
        (try_end),

        (try_begin),
            (gt, ":troop_to_use", 1),
            (set_spawn_position, pos22),
            (spawn_agent, ":troop_to_use"),
            (assign, ":spawned_agent", reg0),
            (agent_set_team, ":spawned_agent", ":team"),
        (try_end),

        (try_begin),
            (gt, ":spawned_agent", -1),
        (try_end),
]),
 
Last edited:
Solution
I marked it then as solved. If you want, you can show the scripts etc with which the switch has been done.
Well, of the 7 factions, I only took into account 6, 4 are patriots (patriotic sailors) and 2 are royalists or Spanish (royal sailors).
In the trigger, the marine type name is assigned (there are 4 types) and the items are assigned among several alternatives, in this case, for example, weapons and uniforms are assigned (by rank according to the number of alternatives ) to the troop of the lowest rank (cobin boy) taking into account the 4 factions and using the constants that house all the troops that will use those uniforms and weapons (generally recruits and militias).
Then continue with the other troops.
After all that...
Upvote 0
I marked it then as solved. If you want, you can show the scripts etc with which the switch has been done.
Well, of the 7 factions, I only took into account 6, 4 are patriots (patriotic sailors) and 2 are royalists or Spanish (royal sailors).
In the trigger, the marine type name is assigned (there are 4 types) and the items are assigned among several alternatives, in this case, for example, weapons and uniforms are assigned (by rank according to the number of alternatives ) to the troop of the lowest rank (cobin boy) taking into account the 4 factions and using the constants that house all the troops that will use those uniforms and weapons (generally recruits and militias).
Then continue with the other troops.
After all that, the changes are applied (don't ask me how it works haha)

Code:
(ti_on_agent_spawn, 0, 0, [],
[
        (store_trigger_param_1, ":agent_no"),
        (agent_is_non_player, ":agent_no"),
        (agent_is_human, ":agent_no"),
        (agent_is_alive, ":agent_no"),
        (agent_get_troop_id, ":troop", ":agent_no"),
        #first get items
        (assign, ":head", -1),
        (assign, ":body", -1),
        (assign, ":shoes", -1),
        (assign, ":weapon_melee", -1),
        (assign, ":weapon_ranged", -1),
        (assign, ":ammo", -1),
        (try_begin),
            (this_or_next|is_between,":troop", tropas_ch1_ini,tropas_ch1_fin),#chile 1
            (this_or_next|is_between,":troop", tropas_andes1_ini,tropas_andes1_fin),#Andes 1
            (this_or_next|is_between,":troop", tropas_pu1_ini,tropas_pu1_fin),#provincias unidas 1
            (is_between,":troop", tropas_lf1_ini,tropas_lf1_fin),# liga federal 1
            (troop_set_name, ":troop", "@Patriot Cobin Boy"),
            (store_random_in_range, ":r", 0, 2),
            (try_begin),# head stuff
                (eq, ":r", 0),
                (assign, ":head", "itm_cubrecabeza5"),
            (else_try),
                (eq, ":r", 1),
                (assign, ":head", "itm_cubrecabeza6"),
            (try_end),
            (store_random_in_range, ":r", 0, 2),
            (try_begin),#body stuff
                (eq, ":r", 0),
                (assign, ":body", "itm_paisano8"),
            (else_try),
                (eq, ":r", 1),
                (assign, ":body", "itm_paisano9"),
            (try_end),
            (store_random_in_range, ":r", 0, 1),
            (try_begin),# boot stuff
                (eq, ":r", 0),
                (assign, ":shoes", "itm_chalas"),
            (try_end),
            (store_random_in_range, ":r", 0, 2),
            (try_begin),#weapons
                (eq, ":r", 0),
                (assign, ":weapon_melee", "itm_butchering_knife"),
            (else_try),
                (eq, ":r", 1),
                (assign, ":weapon_melee", "itm_butchering_knife"),
                (assign, ":weapon_ranged", "itm_throwing_knives"),
            (try_end),
        (else_try),
        .
        .
        .
        # royalist troops ########################################
        (else_try),
              (this_or_next|is_between, ":troop",tropas_vp1_ini,tropas_vp1_fin),#1
              (is_between, ":troop",tropas_ap1_ini,tropas_ap1_fin),# 1
              (troop_set_name, ":troop", "@Royal Cobin Boy"),
            (store_random_in_range, ":r", 0, 2),
            (try_begin),# head stuff
                (eq, ":r", 0),
                (assign, ":head", "itm_cubrecabeza5"),
            (else_try),
                (eq, ":r", 1),
                (assign, ":head", "itm_cubrecabeza6"),
            (try_end),
            (store_random_in_range, ":r", 0, 2),
            (try_begin),#body stuff
                (eq, ":r", 0),
                (assign, ":body", "itm_paisano6"),
            (else_try),
                (eq, ":r", 1),
                (assign, ":body", "itm_paisano7"),
            (try_end),
            (store_random_in_range, ":r", 0, 1),
            (try_begin),# boot stuff
                (eq, ":r", 0),
                (assign, ":shoes", "itm_chalas"),
            (try_end),
            (store_random_in_range, ":r", 0, 2),
            (try_begin),#weapons
                (eq, ":r", 0),
                (assign, ":weapon_melee", "itm_butchering_knife"),
            (else_try),
                (eq, ":r", 1),
                (assign, ":weapon_melee", "itm_butchering_knife"),
                (assign, ":weapon_ranged", "itm_throwing_knives"),
            (try_end),
        (else_try),
        .
        .
        .
        (try_end),
    (try_for_range, ":item_slot", ek_item_0, ek_gloves),
        (try_begin),
            (eq, ":item_slot", ek_item_0),
            (gt, ":weapon_melee", -1),
            (agent_get_item_slot, ":cur_item",":agent_no", ":item_slot"),
            (try_begin),
                (gt, ":cur_item", -1),
                (agent_unequip_item, ":agent_no", ":cur_item"),
            (try_end),
            (agent_equip_item, ":agent_no",":weapon_melee",":item_slot", 0),
        (else_try),
            (eq, ":item_slot", ek_item_1),
            (gt, ":weapon_ranged", -1),
            (agent_get_item_slot, ":cur_item",":agent_no", ":item_slot"),
            (try_begin),
                (gt, ":cur_item", -1),
                (agent_unequip_item, ":agent_no", ":cur_item"),
            (try_end),
            (agent_equip_item, ":agent_no",":weapon_ranged",":item_slot", 0),
        (else_try),
            (eq, ":item_slot", ek_item_2),
            (gt, ":ammo", -1),
            (agent_get_item_slot, ":cur_item",":agent_no", ":item_slot"),
            (try_begin),
                (gt, ":cur_item", -1),
                (agent_unequip_item, ":agent_no", ":cur_item"),
            (try_end),
            (agent_equip_item, ":agent_no",":ammo",":item_slot", 0),
        (else_try),
            (eq, ":item_slot", ek_item_3),
            (agent_get_item_slot, ":cur_item",":agent_no", ":item_slot"),
            (gt, ":cur_item", -1),
            (agent_unequip_item, ":agent_no", ":cur_item"),
        (else_try),
            (eq, ":item_slot", ek_head),
            (gt, ":head", -1),
            (agent_get_item_slot, ":cur_item",":agent_no", ":item_slot"),
            (try_begin),
                (gt, ":cur_item", -1),
                (agent_unequip_item, ":agent_no", ":cur_item"),
            (try_end),
            (agent_equip_item, ":agent_no",":head",":item_slot", 0),
        (else_try),
            (eq, ":item_slot", ek_body),
            (gt, ":body", -1),
            (agent_get_item_slot, ":cur_item",":agent_no", ":item_slot"),
            (try_begin),
                (gt, ":cur_item", -1),
                (agent_unequip_item, ":agent_no", ":cur_item"),
            (try_end),
            (agent_equip_item, ":agent_no",":body",":item_slot", 0),
        (else_try),
            (eq, ":item_slot", ek_foot),
            (gt, ":shoes", -1),
            (agent_get_item_slot, ":cur_item",":agent_no", ":item_slot"),
            (try_begin),
                (gt, ":cur_item", -1),
                (agent_unequip_item, ":agent_no", ":cur_item"),
            (try_end),
            (agent_equip_item, ":agent_no",":shoes",":item_slot", 0),
        (try_end),
    (try_end),
    ]),

After that, I added a trigger in simple_trigger to change the names of the troops again after leaving the battle, because they don't come back automatically....
I did this troop by troop, starting with the first faction, corresponding to Chile....

Code:
 (ti_on_switch_to_map,
   [
(try_for_range, ":troop", soldiers_begin, soldiers_end),

    (party_get_current_terrain, ":terrain", "p_main_party"),
    (this_or_next|neq,":terrain",0),
    (neq,":terrain",8),
#### CHILE ###########################
   (try_begin),
     (eq, ":troop","trp_swadian_recruit"),
     (troop_set_name, ":troop", "@Chilean recruit"),
     (else_try),
     (eq, ":troop","trp_swadian_militia"),
     (troop_set_name, ":troop", "@Chilean Militia"),
     (else_try),
     .
     .
     .
  (try_end),
(try_end),
]),
 
Upvote 0
Solution
Back
Top Bottom