LUA - Detect if multiple units have been damaged or destroyed (Full Version)

All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion



Message


killjoy73au -> LUA - Detect if multiple units have been damaged or destroyed (1/21/2018 7:02:34 AM)

G'day all.

So despite my best detective work i've been unable to find a feasible way to have an action occur when multiple units have been destroyed within the same event, or find a LUA code to detect if a unit has been destroyed.

From what I gather, if you have multiple triggers in an event, the event doesn't wait for all triggers to have fired, it only requires one of the triggers to fire before an action (nothing in the conditions helps with this either) fires.

What I need is for an action to fire off only after multiple enemy units have been destroyed.

So say I have 3 enemy surface units that need to be sunk, I need a message to pop up once those 3 specific units have been sunk.

A bit of a visualisation of what I would ideally like to happen (I'm aware there is no 'and' function for triggers though):


EVENT - enemy SAG sunk

Triggers:
ship 1 destroyed
and
ship 2 destroyed
and
ship 3 destroyed

Action:
Message - enemy SAG has been sunk



Cheers.








michaelm75au -> RE: LUA - Detect if multiple units have been damaged or destroyed (1/21/2018 8:19:47 AM)

Currently multiple triggers in same event are 'OR' checks - any one of them will trigger the action.
What you need to do for the example is to create a 'counter' to keep track of how many units have been destroyed.
Basic example

Event: Unit Destroyed
Trigger: unit destroyed
Action:
lastCount = ScenEdit_GetKeyValue('ShipsSunk');
lastCountN = tonumber(lastCount);
if lastCountN == nil then
lastCountN = 0;
end
lastCountN = lastCountN +1;
ScenEdit_SetKeyValue('ShipsSunk', tostring(lastCountN));
if lastCountN > 3 then
ScenEdit_MsgBox ("SAG sunk", 1)
end




killjoy73au -> RE: LUA - Detect if multiple units have been damaged or destroyed (1/21/2018 10:10:26 AM)

Thanks very much for reply, I'm looking more to call a script to check if specific units still exist.

I tried this script that gets called every 15 seconds by a trigger...

if ScenEdit_GetUnit({side="PLAAF", unitname="Anshan DD-101"}) == nil
then ScenEdit_SpecialMessage('United States Navy','Anshan Destroyed')
ScenEdit_SetEvent('PLAN SAG - Destroyed', {IsActive= false})
end

I got this working. Now what i'm looking to do is have this script check for multiple different units, resulting in just the one msg.


Okay I got it working. Once both units are destroyed the message pops up and the trigger/event stop checking. It doesn't look overly professional but it works damnit!

if ScenEdit_GetUnit({side="PLAN", unitname="Anshan DD-101"}) == nil
and
ScenEdit_GetUnit({side="PLAN", unitname="Changchun DD-103"}) == nil
then ScenEdit_SpecialMessage('United States Navy','Anshan and Changchun Destroyed')
ScenEdit_SetEvent('PLAN SAG - Destroyed', {IsActive= false})
end




tjhkkr -> RE: LUA - Detect if multiple units have been damaged or destroyed (1/30/2018 3:27:28 PM)

Yes, this was good!




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
1.046875