Forged Alliance Forever Forged Alliance Forever Forums 2018-08-21T23:25:11+02:00 /feed.php?f=53&t=16608 2018-08-21T23:25:11+02:00 2018-08-21T23:25:11+02:00 /viewtopic.php?t=16608&p=166936#p166936 <![CDATA[Re: Detecting that a unit has changed army]]> https://github.com/FAForever/fa/blob/775b4b00ec0474dc112537c9938c081e0810cb3c/lua/SimUtils.lua#L59

BTW, the owner is stored inside "unit.oldowner" not in "unit.originalBuilder"
The variable "originalBuilder" is just the builder (engineer, ACU etc) that is building the unit and will be set on Fn "OnStartBeingBuilt" from unit.lua.

And this function returns units to its original owner at playerdead:
https://github.com/FAForever/fa/blob/28 ... n.lua#L605

Statistics: Posted by Uveso — 21 Aug 2018, 23:25


]]>
2018-08-21T20:07:10+02:00 2018-08-21T20:07:10+02:00 /viewtopic.php?t=16608&p=166933#p166933 <![CDATA[Re: Detecting that a unit has changed army]]>
Edit: wait, actually what you wrote is not correct. Units that have been gifted DO NOT have the originalBuilder field set, while those that have not been gifted do have it set. (Unless one of the things I wrote above is the case.) That does leave the question of how the unit is given back to the original owner. Could you point to the code that does that?

Statistics: Posted by EntropyWins — 21 Aug 2018, 20:07


]]>
2018-08-21T18:08:53+02:00 2018-08-21T18:08:53+02:00 /viewtopic.php?t=16608&p=166930#p166930 <![CDATA[Re: Detecting that a unit has changed army]]> It's used in case the player died and we need to give the units back to the original owner. (unitshareconditions)

So this is a helper variable because there is no other way to see who build the unit first.

Statistics: Posted by Uveso — 21 Aug 2018, 18:08


]]>
2018-08-21T16:42:21+02:00 2018-08-21T16:42:21+02:00 /viewtopic.php?t=16608&p=166924#p166924 <![CDATA[Re: Detecting that a unit has been gifted]]> ?

Statistics: Posted by FlyingThunder — 21 Aug 2018, 16:42


]]>
2018-08-21T17:28:09+02:00 2018-08-21T16:34:22+02:00 /viewtopic.php?t=16608&p=166923#p166923 <![CDATA[Detecting that a unit has changed army]]>
What I have so far is `if unit.originalBuilder == nil then`. This works to distinguish player created unit from those that changed army, though has some false positives. Units created by the map will also not have an originalBuilder and the same goes for those created via the cheating menu. The same is presumably true for captured units. Is there a more sure way to tell if a unit has changed army?

The reason I'm asking is because of /viewtopic.php?f=53&t=16598. If there is a way to detect unit creation, then I don't need to bother with detecting if a unit has changed army or not.

My unit creation event thing is using entity ids to keep track of which units are new. The problem I'm running into is that the game changes the entity id when a unit changes army, which happens because the game creates a new unit object and just copies over a bunch of stuff. So I need to be able to tell if I'm dealing with such a copied object or not

Statistics: Posted by EntropyWins — 21 Aug 2018, 16:34


]]>