Forged Alliance Forever Forged Alliance Forever Forums 2018-09-15T21:25:01+02:00 /feed.php?f=53&t=16598 2018-09-15T21:25:01+02:00 2018-09-15T21:25:01+02:00 /viewtopic.php?t=16598&p=167557#p167557 <![CDATA[Re: Running code when a unit is created]]> The second if clause is a leftover from when the first if clause was a bit wider (before I learned that "categories._" can contain an actual name of a unit, not strictly categories themselves ;) and I didn't then delete the second, now redundant if clause, because...if it works why touch it. Also because i went so far and wide with my map script (multiple different survival waves depending on numerous variables, for example like above if Paragon is built, lot's of tweaking on boss units etc)...was no time to beautify the well working pieces of code - leave it if it works, move on to the next thing. Also cause I am a noob learn-it-yourself coder.

As for double negations, I had some trouble running non - negation script, for example a simple "if a mod is present -then" would not be detected for some reason, but "if if not (a mod is not present) - then" would work. No idea why.
Again, if the double negative works...if it ain't broken, don't fix it ;)

Anyways...enough rant.

Statistics: Posted by DDDX — 15 Sep 2018, 21:25


]]>
2018-09-15T13:33:07+02:00 2018-09-15T13:33:07+02:00 /viewtopic.php?t=16598&p=167546#p167546 <![CDATA[Re: Running code when a unit is created]]>
Looks like you have a double negation in your inner if predicate. And is the one above really needed given you already filter on categories.xab1401? Finally, if you do not use the key in a for loop, I believe it is convention to name it _.

Statistics: Posted by EntropyWins — 15 Sep 2018, 13:33


]]>
2018-09-03T16:01:31+02:00 2018-09-03T16:01:31+02:00 /viewtopic.php?t=16598&p=167231#p167231 <![CDATA[Re: Running code when a unit is created]]>
Code:
for x, army in ListArmies() do                               
                 if (army == "ARMY_1" or army == "ARMY_2" or army == "ARMY_3" or army == "ARMY_4" or army == "ARMY_5" or army == "ARMY_6") then
                     List = GetArmyBrain(army):GetListOfUnits(categories.xab1401, false, true)
                         for k, unit in List do      
                           if (unit:GetUnitId() == 'xab1401') then
                               if not (unit:GetFractionComplete() ~= 1) then


the last segment is to let the map know the unit is completed and not merely being built ;)

Statistics: Posted by DDDX — 03 Sep 2018, 16:01


]]>
2018-08-21T23:38:01+02:00 2018-08-21T23:38:01+02:00 /viewtopic.php?t=16598&p=166937#p166937 <![CDATA[Re: Running code when a unit is created]]> Statistics: Posted by Uveso — 21 Aug 2018, 23:38


]]>
2018-08-21T18:43:40+02:00 2018-08-21T18:43:40+02:00 /viewtopic.php?t=16598&p=166932#p166932 <![CDATA[Re: Running code when a unit is created]]> Statistics: Posted by EntropyWins — 21 Aug 2018, 18:43


]]>
2018-08-21T18:27:17+02:00 2018-08-21T18:27:17+02:00 /viewtopic.php?t=16598&p=166931#p166931 <![CDATA[Re: Running code when a unit is created]]>
Unitblueprints are initalized inside blueprint.lua and will be registered inside the c-engine there.

if you now change the blueprint in your mapscript, it will not be registered inside the c-engine.

And woops desync...

[Edit]
(all c-engine commands will get the old unit data, but if you read the blueprint itself you will get the new data.
And this is only working local, not in multiplayer)

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


]]>
2018-08-21T17:49:17+02:00 2018-08-21T17:49:17+02:00 /viewtopic.php?t=16598&p=166928#p166928 <![CDATA[Re: Running code when a unit is created]]> Statistics: Posted by EntropyWins — 21 Aug 2018, 17:49


]]>
2018-08-21T17:40:29+02:00 2018-08-21T17:40:29+02:00 /viewtopic.php?t=16598&p=166927#p166927 <![CDATA[Re: Running code when a unit is created]]> Statistics: Posted by speed2 — 21 Aug 2018, 17:40


]]>
2018-08-21T17:17:26+02:00 2018-08-21T17:17:26+02:00 /viewtopic.php?t=16598&p=166925#p166925 <![CDATA[Re: Running code when a unit is created]]>
The lua script I linked in my post also has a number of issues, with one of them maybe not fixable. Hence all the more reason to have a sane existing way to react to unit creation.

Statistics: Posted by EntropyWins — 21 Aug 2018, 17:17


]]>
2018-08-18T09:06:03+02:00 2018-08-18T09:06:03+02:00 /viewtopic.php?t=16598&p=166883#p166883 <![CDATA[Re: Running code when a unit is created]]> https://github.com/FAForever/fa/blob/de ... t.lua#L155

Statistics: Posted by speed2 — 18 Aug 2018, 09:06


]]>
2018-08-18T12:36:48+02:00 2018-08-18T08:16:03+02:00 /viewtopic.php?t=16598&p=166882#p166882 <![CDATA[Running code when a unit is created]]>
oncreated.png

I've been looking through quite a lot of the FA/FAF lua code and have not found anything providing such functionality. Is there really no way of doing this?

Of course there is one way... which is what I did here https://pastebin.com/KBM72wBv . Having to loop through all units and seeing if there is a new one every tick is quite stupid though, especially if the game already provides a more sane way of reacting to the unit creation event.

Statistics: Posted by EntropyWins — 18 Aug 2018, 08:16


]]>