Need a bit of help with triggers: replace crossbowmen with longbowmen after the crossbowmen research

Need a bit of help with triggers.

Trying to use triggers to replace crossbowmen with longbowmen after the crossbowmen research, but it doesn’t work, despite the E#0 is “add training location”. What did I do wrong?

image1

image2

image3

Disabling archer line after crossbowmen is researched still doesn’t work,
The only way it would work is for me to “enable” longbowman, but then it will replace your UU in castle.

How much do you know about XS? Maybe try with

Hey there.

You got multiple ways of reaching your goal.

First method is attempting to detect when the player research the upgrade, and then apply something. But in pure trigger, it will requiere a lot of tricky things to make sure that units are replaced. The reason is that technology upgrading units are “translating” a unit to another without replacing it for real. See that more as a…How to say…Transformation.
To understand that, when you place an archer unit from feudal age on the map, and then in the player tab you change your current player Age, the same unit will change to the upgraded one. Once you understood that mechanics you can see why detecting vanilla tech isn’t the best way to do in pure trigger. It would requiere some XS scripting so I don’t recommand it.

The second method, the one I recommand, is to replace the vanilla tech that upgrade to crossbowmen by a custom blank tech in trigger. You change the train location of the vanilla tech, not disabling it, just putting it on let’s say a Yurt so the player will never see it.
To avoid issues, you only activate that new custom blank tech to be on the archery range after the player researched previous tech, either it be an age-up or a unit pre-upgrade version it doesn’t matter as the only goal is here to determine when the player should have access to the tech you want to use.
Then, that blank tech, you just give it the price, the description, the icon, and the search time of the tech you wwanted to replace.
Now you can detect when this blank tech is researched by the player in trigger, and on completion, you use a trigger to replace crossbowmen by longbowmen on the map, and you change the training location of the crossbowmen to the same yurt you’ve used to “move away” the vanilla upgrade. Then you make the train location of the longbowmen where the vanilla crossbowmen was.
BUT, you can have a unit trained only at one place. If you make them trainable in the archery range, the longbowmen, they won’t be able to be trained at the castle anymore. That’s why there is some hidden units duplicates for huskarl on barracks, spearman and serjeant on dungeon, etc.
However with custom scenario you can eventually reskin objects to have multiple version but it become abit complexe.

The first step is to detect the condition, the tech research, and then apply the change. Letting the player do the vanilla upgrade and then apply a replace object, plus changing the unit trained at the building by the longbowmen is as valid as using a custom tech to do the job.
The reason why I recommand the blank tech is because you can do the swap Before the vanilla upgrade process occuring.

However, remember to also check about garrisoned unit, you may have to force unload every tower / castle / towncenter / transport ships / archery range that have garrisoned units before the replacement trigger occuring.