Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

Condition = Specific Unit 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 >> Condition = Specific Unit Destroyed Page: [1]
Login
Message << Older Topic   Newer Topic >>
Condition = Specific Unit Destroyed - 7/27/2021 3:42:58 PM   
BeirutDude


Posts: 2379
Joined: 4/27/2013
From: Jacksonville, FL, USA
Status: offline
Ok, guys, I'm old and stupid and I admit it but this should be simple. As a CONDITION for an event I want to test if a specific unit is destroyed. I really don't understand why this isn't a base option for conditions but it isn't.

So how do I test for...
Side = CONUS aimpoints
Specific Unit = NAS Key West
Status = Destroyed

I just want to test for it to be destroyed for subsequent actions to be taken. Sure it is simple but I'm going through the Lau docs and my head is spinning.

"One small step for a young kid who loves programing, one giant leap for a old dude who sucks at it!"

< Message edited by BeirutDude -- 7/27/2021 3:43:53 PM >


_____________________________

"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
PRESIDENT RONALD REAGAN, 1985

I was Navy, but Assigned TAD to the 24th MAU Hq in Beirut. By far the finest period of my service!
Post #: 1
RE: Condition = Specific Unit Destroyed - 7/27/2021 4:10:48 PM   
tmoilanen

 

Posts: 65
Joined: 10/19/2011
Status: offline
Hi BeirutDude - if you're just checking to see if the unit still exists the script below should work.

You can replace the AddWeaponToUnitMagazine part with whatever action you're looking to perform.


if ScenEdit_GetUnit({Side='Taiwan', Name='Kinmen AP Ammo 1',}) ~= nil then

ScenEdit_AddWeaponToUnitMagazine({unitname='Kinmen AP Ammo 1', wpn_dbid='683', number=64}) -- AGM-114K Hellfire II
ScenEdit_AddWeaponToUnitMagazine({unitname='Kinmen AP Ammo 1', wpn_dbid='1929', number=112}) -- HYDRA 70mm Rocket


end

(in reply to BeirutDude)
Post #: 2
RE: Condition = Specific Unit Destroyed - 7/27/2021 4:12:05 PM   
tmoilanen

 

Posts: 65
Joined: 10/19/2011
Status: offline
and obviously replace the side and unit name information with your info.

(in reply to tmoilanen)
Post #: 3
RE: Condition = Specific Unit Destroyed - 7/27/2021 4:35:43 PM   
BeirutDude


Posts: 2379
Joined: 4/27/2013
From: Jacksonville, FL, USA
Status: offline
I just want to check to see if the unit has been destroyed as a condition. If so in the actions I want to send a message, if not I want the event to fil.

_____________________________

"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
PRESIDENT RONALD REAGAN, 1985

I was Navy, but Assigned TAD to the 24th MAU Hq in Beirut. By far the finest period of my service!

(in reply to tmoilanen)
Post #: 4
RE: Condition = Specific Unit Destroyed - 7/27/2021 4:43:20 PM   
BeirutDude


Posts: 2379
Joined: 4/27/2013
From: Jacksonville, FL, USA
Status: offline
if ScenEdit_GetUnit({Side='CONUS Aimpoints', Name='NAS Key West (Geographic/Aimpoint)',}) == nil then
end


?????????

< Message edited by BeirutDude -- 7/27/2021 4:47:45 PM >


_____________________________

"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
PRESIDENT RONALD REAGAN, 1985

I was Navy, but Assigned TAD to the 24th MAU Hq in Beirut. By far the finest period of my service!

(in reply to tmoilanen)
Post #: 5
RE: Condition = Specific Unit Destroyed - 7/27/2021 5:04:28 PM   
BeirutDude


Posts: 2379
Joined: 4/27/2013
From: Jacksonville, FL, USA
Status: offline

quote:

if ScenEdit_GetUnit({Side='CONUS Aimpoints', Name='NAS Key West (Geographic/Aimpoint)',}) == nil then
end


No that didn't work. Thanks for the help, guess I'm just stupid!

< Message edited by BeirutDude -- 7/27/2021 5:08:28 PM >


_____________________________

"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
PRESIDENT RONALD REAGAN, 1985

I was Navy, but Assigned TAD to the 24th MAU Hq in Beirut. By far the finest period of my service!

(in reply to BeirutDude)
Post #: 6
RE: Condition = Specific Unit Destroyed - 7/27/2021 5:58:17 PM   
Kushan04


Posts: 600
Joined: 6/29/2005
Status: offline
Conditions have to return a true/false.

Example:
local mission = ScenEdit_GetMission('Test', 'Test')

if mission.isactive == true then
 return true
else
 return false
end


In your case I think it would look something like this:
local unit = ScenEdit_UnitX()

if unit.name == 'NAS Key West' then
 return true
else
 return false
end


< Message edited by Kushan04 -- 7/27/2021 6:03:05 PM >


_____________________________


(in reply to BeirutDude)
Post #: 7
RE: Condition = Specific Unit Destroyed - 7/27/2021 5:59:44 PM   
BeirutDude


Posts: 2379
Joined: 4/27/2013
From: Jacksonville, FL, USA
Status: offline
Would this work? Use a counter?

Can I set up a counter called "targetshit" in a Lua script in an action

local targetshit = 0

Then set up another Action Lua script that keeps track of each target hit when an event fires

Local targetshit = targetshit + 1


Then for each message I want to send a Lua script in the Conditions to see if the condition is met...

if targetshit == 1 then
return true
else
return false
end


< Message edited by BeirutDude -- 7/27/2021 6:47:47 PM >


_____________________________

"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
PRESIDENT RONALD REAGAN, 1985

I was Navy, but Assigned TAD to the 24th MAU Hq in Beirut. By far the finest period of my service!

(in reply to BeirutDude)
Post #: 8
RE: Condition = Specific Unit Destroyed - 7/27/2021 6:04:19 PM   
Kushan04


Posts: 600
Joined: 6/29/2005
Status: offline
Updated my post with what I think your condition would look like.

Why does using the [code] block add so many extra lines?

Edit: Instead of using a condition you could also just use a specific damaged/destroyed trigger.

< Message edited by Kushan04 -- 7/27/2021 6:06:04 PM >


_____________________________


(in reply to BeirutDude)
Post #: 9
RE: Condition = Specific Unit Destroyed - 7/27/2021 6:35:00 PM   
BeirutDude


Posts: 2379
Joined: 4/27/2013
From: Jacksonville, FL, USA
Status: offline
I so frigging confused I'm ready to trash this scenario, this should be so easy!

So look here is my problem

some time after an event (the nuclear destruction of a facility), say 5 10 or 15 minutes later I want to send the player a message. So I need to use a "condition" that somehow keeps track of the event occurring and only a Lua script will do that. I actually think just a simple counter might work better but I can't event write a frigging "if statement" and all the ones I call up online are so frigging complicated I can't follow them. That's why I gave up on coding my mind doesn't work that way!

I think I just need a simple if statement to test if the local variable 'targetshit' is equal to a certain value or not and each time an event is triggered add 1 to it.

_____________________________

"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
PRESIDENT RONALD REAGAN, 1985

I was Navy, but Assigned TAD to the 24th MAU Hq in Beirut. By far the finest period of my service!

(in reply to Kushan04)
Post #: 10
RE: Condition = Specific Unit Destroyed - 7/27/2021 6:58:28 PM   
BeirutDude


Posts: 2379
Joined: 4/27/2013
From: Jacksonville, FL, USA
Status: offline
Kushan04 Thanks for your help! I think I figured it out (I hope, man I have a headache!)

Lua Script on Scenario load to set the counter to 0 with each load

local targetshit = 0

Advance the counter by 1 with each event

targetshit = targetshit + 1

Conditional Test to see if a message should be sent...

if (targetshit == 1) then
return true
else
return false
end


I wouldn't be here without your IF statement to mimic/follow TY!!!!

BTW I think this scenario might be one you would enjoy when I am done. I've been working for weeks on just the nuclear aspect and that is just the chrome.

< Message edited by BeirutDude -- 7/27/2021 6:59:55 PM >


_____________________________

"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
PRESIDENT RONALD REAGAN, 1985

I was Navy, but Assigned TAD to the 24th MAU Hq in Beirut. By far the finest period of my service!

(in reply to Kushan04)
Post #: 11
RE: Condition = Specific Unit Destroyed - 7/27/2021 7:16:02 PM   
BeirutDude


Posts: 2379
Joined: 4/27/2013
From: Jacksonville, FL, USA
Status: offline
Nope that won't work either because the event will keep sending the message over and over.

But if each message had it's on variable (targethit01, targethit02, etc) and then when the event is triggered that variable goes back to 0 that might work. Just toggle it on for one event.


< Message edited by BeirutDude -- 7/28/2021 8:06:51 PM >


_____________________________

"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
PRESIDENT RONALD REAGAN, 1985

I was Navy, but Assigned TAD to the 24th MAU Hq in Beirut. By far the finest period of my service!

(in reply to BeirutDude)
Post #: 12
RE: Condition = Specific Unit Destroyed - 7/27/2021 8:09:59 PM   
BeirutDude


Posts: 2379
Joined: 4/27/2013
From: Jacksonville, FL, USA
Status: offline
Nope that doesn't work. I did a test and for some reason it deactivates the event. This shouldn't be this hard!

< Message edited by BeirutDude -- 7/28/2021 8:07:07 PM >


_____________________________

"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
PRESIDENT RONALD REAGAN, 1985

I was Navy, but Assigned TAD to the 24th MAU Hq in Beirut. By far the finest period of my service!

(in reply to BeirutDude)
Post #: 13
RE: Condition = Specific Unit Destroyed - 7/27/2021 9:08:34 PM   
BeirutDude


Posts: 2379
Joined: 4/27/2013
From: Jacksonville, FL, USA
Status: offline
OK, just got the toggle idea working. Defining the variable as "Local" was screwing things up. I have the messages in my test scenario firing.

< Message edited by BeirutDude -- 7/28/2021 8:07:28 PM >


_____________________________

"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
PRESIDENT RONALD REAGAN, 1985

I was Navy, but Assigned TAD to the 24th MAU Hq in Beirut. By far the finest period of my service!

(in reply to BeirutDude)
Post #: 14
RE: Condition = Specific Unit Destroyed - 7/28/2021 3:18:18 AM   
KnightHawk75

 

Posts: 1208
Joined: 11/15/2018
Status: offline
quote:

some time after an event (the nuclear destruction of a facility), say 5 10 or 15 minutes later I want to send the player a message. So I need to use a "condition" that somehow keeps track of the event occurring and only a Lua script will do that. I actually think just a simple counter might work better but I can't event write a frigging "if statement" and all the ones I call up online are so frigging complicated I can't follow them. That's why I gave up on coding my mind doesn't work that way!


Ok so using a Condition is certainly possible, as Kushan said condition's need a return value:
Setup a function for yourself called something like the following in your OnSceneLoad stuff.

--This function returns true only if a unit does not exist.
function DoesThisUnitNotExist(theSide,theName)
  local retval,u = pcall(ScenEdit_GetUnit, {Side=theSide, Name=theName}); --get the unit.
  if (retval ==true) and u ~=nil then --did the call succeed, did it return a unitwrapper?
    return false; --unit exists, call succeeded and it returned something.
  else 
    return true; --unit does not exists or the GetUnit call failed for another reason.
  end 
end


Condition Name (I'm assuming the action is a display message action): Does SomeUnitname Exist?
return DoesThisUnitNotExist("SomeSide","TheUnitName"); -- calls the function and returns for the condition what comes back from the function.


There are 1/2 a dozen different ways to do what you want, depending on how you want said message displayed, just find what works best for you\the scene, don't get frustrated we can walk you through any of this. For instance you didn't really mentioned if the message you want displayed is per-unit destroyed, depends on how many of particular units are destroyed, or only displayed when say all of a list of units are destroyed. I'm assuming it's a simple 'if unit1 destroyed then display prepared message 1' ... 'if unit2 destroyed then display prepared message 2' etc since that avoids lua.

quote:

the event will keep sending the message over and over.
-- Not if you disable it after running the first time.


quote:

OK, just got the counter idea working. Defining the variable as "Local" was screwing things up. I have the messages in my test scenario firing.

If you go that route don't forget you likely now have to save the state of those variables now upon every change to them, to the key store, and load them up\restore them on scene load, if you want saves to work reliably.

If it helps you I attached a very simple scene Red and Blue, 4 targets exist on blue, 1 sub to nuke them on Red.
It uses the above code + conditions.
Every minute it checks if each of the monitored units exist, if they do not, you will get a specific message for each one ONCE, and only ONCE. It involves NO variables that need to be tracked, and instead relies on disabling the events after the messages is displayed.
It's not how I would necessarily do things, but it does show how to avoid Lua to the maximum extent possible, and removes having to manage any state at the cost of more events, more conditions, hard coding, and otherwise unnecessary duplication. It assume you actually want a message per unit involved, and not one message only after all\some are destroyed though that is certainly doable by changing the condition and message.

MessageOnIntervalShowOnceMinLuaSample.zip (build 1147.29 | db3k 489)
Just load it and have the sub destroy the target(s) you want and watch as you get the messages and then the events involved disable themselves, make sure you watch from side red so that you actually get the messages.

quote:

Why does using the [code] block add so many extra lines?

idk but yeah it's annoying.


Attachment (1)

< Message edited by KnightHawk75 -- 7/28/2021 3:19:32 AM >

(in reply to BeirutDude)
Post #: 15
RE: Condition = Specific Unit Destroyed - 8/18/2021 6:36:23 AM   
aerosky


Posts: 16
Joined: 7/20/2021
From: Italy
Status: offline
Hi, BeirutDude
You need use the latest version of CMO first.

_____________________________


(in reply to KnightHawk75)
Post #: 16
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> Condition = Specific Unit 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.414