Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

LUA - Detect if multiple units have been damaged or destroyed

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> LUA - Detect if multiple units have been damaged or destroyed Page: [1]
Login
Message << Older Topic   Newer Topic >>
LUA - Detect if multiple units have been damaged or des... - 1/21/2018 7:02:34 AM   
killjoy73au


Posts: 26
Joined: 7/10/2017
Status: offline
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.




Post #: 1
RE: LUA - Detect if multiple units have been damaged or... - 1/21/2018 8:19:47 AM   
michaelm75au


Posts: 13500
Joined: 5/5/2001
From: Melbourne, Australia
Status: offline
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


_____________________________

Michael

(in reply to killjoy73au)
Post #: 2
RE: LUA - Detect if multiple units have been damaged or... - 1/21/2018 10:10:26 AM   
killjoy73au


Posts: 26
Joined: 7/10/2017
Status: offline
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

< Message edited by killjoy73au -- 1/21/2018 10:29:35 AM >

(in reply to michaelm75au)
Post #: 3
RE: LUA - Detect if multiple units have been damaged or... - 1/30/2018 3:27:28 PM   
tjhkkr


Posts: 2428
Joined: 6/3/2010
Status: offline
Yes, this was good!

_____________________________

Remember that the evil which is now in the world will become yet more powerful, and that it is not evil which conquers evil, but only love -- Olga Romanov.

(in reply to killjoy73au)
Post #: 4
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> LUA - Detect if multiple units have been damaged or destroyed Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

0.906