Today I saw a script that was meant to track the unit that placed a structure. It was doing so using a unit variable of string type, then looping through all players in the game and comparing the name.
Not only does this require additional script actions, it’s also inefficient because it does a loop every time the script is run.
So I made an example that properly tracks the owner of a spawned structure. Just like the inspiration fort this demo, it uses an item to spawn the structures.
Included in demo:
- properly tracking the owner player of a unit with an entity variable
- keep track of how many units a player unit has placed (incl. updating on destroy)
- compare distance between entity and mouse cursor position
Here’s the demo game, enjoy!