Hi, total aoe2 modding new guy here. (As far as this even counts as modding to begin with.)
I am looking to create a scenario in which a unit that drops dead spawns another object. Let’s say I want each villager that dies to spawn a flower or a tombstone or a berry bush on their location. I found how I can do that for one specific villager, using a trigger with the condition Object HP and the effect Replace Object. But that’s an individual villager. Is there a way to set the same effect to happen for any villager (or man at arms, or wild boar, or…) that dies, without manually copying this trigger for each individual villager in the scenario? I’d prefer an in-editor solution, but I’m open to some light coding or such if needed.
Thanks a lot in advance. The trick I have in mind would work with individual triggers, but I would need to set several thousand of them, and I’m honestly not even sure the scenario will run super smooth before I start adding that kind of a script overload.
Here’s how I would do it. So you have your villager say, and let’s say you want it to turn into a tombstone once it dies. First create a trigger, this one is for the unit you want to transform, let’s say a villager.
Now, you can’t just have it magically turn into a grave upon death, so you need to find a new unit that you aren’t using, let’s say a Condottiero.
Get the ID from the Condo, and now plug it into the quantity for the villager, then delete any other modify attributes that you aren’t using.
Now, make a new trigger, and make it loop.
Now set up an effect like this for it (you need to perform this step, or the next thing won’t work).
Now add a second effect, this time a replace object one, and set it up like this.
The reason you need to do the convert is because if you don’t, you can’t replace a player controlled object with something that only exists for Gaia usually. Now you have 2 triggers.
And here you go:
You will likely get a flash where you do see the Condo, and there are probably things you can do about it, but this should work I guess.
Wow, that was both super quick and elaborate/complete! I am going to try this out tomorrow! Lots of thanks!
Addendum to thread:
I found a cool exception. Units captured from gaia cannot be changed this way. You have to instead “modify Dead Unit ID” them as if they still belonged to gaia rather than player 1. This means you can change them directly into the object of choice, and it saves you scripts if you want multiple players to get the same transformations. The resulting object however is for some strange reason invisible through the fog of war. A wild horse changed into a gold pile acts as a normal gold pile, but a horse changed into a gold pile becomes a stealth gold pile.
I can’t decide wether the world needs more or less stealth gold piles.
EDIT: the stealth piles can’t be mined though because you still own it. Maybe I still need to try a little harder at this… (For this particular project I have a good workaround though, so all is good.)
Follow up question:
When I spawn resources this way, my villagers will often do their level best to avoid dropping these resources off at a TC. There’s no problem as long as the TC is the only point available, but ones I build a lumbercamp all my lumberjacks start hauling their wood from around the TC to the lumbercamp, no matter the distance. I can manually make them drop off at the TC, but when I click them back to work after most will continue to try and use the lumbercamp instead. It affects both the TC I placed in the editor and any new ones built during the game, but it only seems to affect the resources placed off-grid. Farmers are not bothered by it for instance.
Is there a way to force items back on the grid somehow, or another known way to prevent this bug?