At the bottom, the ability use trigger(A) remembers the triggering player, the unit built trigger(B) will wait for the ability use trigger to finish in order to send the built unit to the correct player. The reason I did this is because (A) does not have the built unit yet, but the triggering player, and, (B) does not have the triggering player, but the built unit. In a single player condition, this should work fine because (B) will wait for (A). But in a multiplayer condition, if (A1), (A2), (B1), (B2) are created in this order, will (B1) wait for (A2), or the system is smart enough to order it (A1)(B1)(A2)(B2)? This race condition is really bothering me, and I would like to solve it before I release the map. Thanks!
The shop is a structure that will build certain units, but the shop is owned by a neutral player because I would like it to be shared control to other players. Like I described, the unit create trigger will return player neutral for the function triggering player, limiting the options to use global variable. Well, if possible, I definitely would like to know if there exists a function that returns the player integer that actually casted the ability instead of just the owner of the unit that casted the ability.
I later found an event Unit Training Progress that should be the combine of the two, but the triggering player is still just the owner of unit instead of the player that pressed the button. So I moved on by creating a shop for each player and have a trigger for each shop to capture the transaction. Thanks!
Triggering Player is the player who issued the order, at least for some events (maybe not the one you were trying to use). This was a big source of bugs in Undead Assault 3 as it assumed Triggering Player was the owning player so if you shared control and use another player's unit all manner of bugs occurred.
If there is only 1 (or a finite number) shops then maybe per player global variables might work. These are 16 sized arrays which index is the player slot number, providing unique storage for each player. I would have to see all the triggers to be able to comment further if this approach is appropriate or even needed.