Page 1 of 1
Lua - Trigger Altitude AND in inside Area
Posted: Sun Jul 23, 2017 12:46 pm
by kevinkins
Helicopter passes into a small area to "drop passengers" (rappel) but only < 100 feet triggers a scoring event. Any ideas for a code snippet? Right now the player would get points at any altitude. Need some sort of if then code.
Thanks
Kevin
RE: Lua - Trigger Altitude AND in inside Area
Posted: Sun Jul 23, 2017 3:26 pm
by somi83
Hi,
Set up event as
1. Trigger: Unit inside area
2. Condition: lua script:
Code: Select all
local unit = ScenEdit_GetUnit({guid='82528034-b846-4200-b5f9-069b207db6f1'})
x = (unit.altitude)
if x < 100
then return true
elseif x > 100
then return false
end
local unit = ScenEdit_GetUnit({guid='82528034-b846-4200-b5f9-069b207db6f1'}), ({guid = 'guid'}) 'guid' you can get it from sbr script, or you can use ({side = "name of the side", unitname = "name of the unit"})
3. Action lua script:
Code: Select all
local sc1=ScenEdit_GetScore("US")
ScenEdit_SetScore('US',sc1 + 50,'Viper #1 took off from Nellis AFB')
sc1=ScenEdit_GetScore("US"), instead of "US" type the side of the unit
ScenEdit_SetScore('US',sc1 + 50,'Viper #1 took off from Nellis AFB')('side you want to add points', sc1 + 'number of points you want to add to the score', 'description why you get the points')
RE: Lua - Trigger Altitude AND in inside Area
Posted: Sun Jul 23, 2017 4:41 pm
by ExNusquam
Instead of using the GUID, you could use
to make the condition work more generally.
RE: Lua - Trigger Altitude AND in inside Area
Posted: Mon Jul 24, 2017 1:01 pm
by kevinkins
UnitX() works well ...
Event = "Test"
Trigger = "SealsEnterArea"
Action = lua
alt=UnitX().altitude
if alt < 40 then
ScenEdit_MsgBox('GOOD Job 10 points awarded !!!', 1)
score = ScenEdit_GetScore("USAJapan")
score = score + 10
ScenEdit_SetScore ("USAJapan",score,"GOOD Job")
end
Note: lua altitude is in meters not feet.
RE: Lua - Trigger Altitude AND in inside Area
Posted: Tue Jul 25, 2017 5:41 am
by butch4343
ORIGINAL: kevinkin
UnitX() works well ...
Event = "Test"
Trigger = "SealsEnterArea"
Action = lua
alt=UnitX().altitude
if alt < 40 then
ScenEdit_MsgBox('GOOD Job 10 points awarded !!!', 1)
score = ScenEdit_GetScore("USAJapan")
score = score + 10
ScenEdit_SetScore ("USAJapan",score,"GOOD Job")
end
Note: lua altitude is in meters not feet.
Outstanding!
I was pondering how to score based on a units height just the other week mate, so thanks for that!
Cue 20 posts on where I have gone wrong in the next few days lol
Butch
RE: Lua - Trigger Altitude AND in inside Area
Posted: Wed Jan 31, 2018 12:52 pm
by butch4343
Guys,
Can I ask for some help on this one?
Im dead interested in this script, but I want to make it work for a slighlty different outcome, I wonder if someone can explain some LUA magic to me.
So I have a scenario where I have a SAM battery thats sitting in East Germany, its an SA-5 Site, so its got a far reach into the FRG, I wanted to set a script for so that NATO aircraft will trigger a SAM engagement if the aircraft is above say 5500 feet.
So my thinking is that I would have a trigger that specifically is tripped when NATO aircraft enter the area.
Then the action would be LUA script
alt=UnitX().altitude
if alt < 1500 then
So am i right in thinking this is the part of the script that would "check" the height of the aircraft that tripped the trigger?
So the next part would be the bit I kinda need explaining to get my head around, I was thinking that I could use.
ScenEdit_AttackContact(attackerID, contactId ,{mode='1', mount=438, weapon=1413, qty=10}) -- alloc 10 gunfire
I got this from the Command LUA documentation.
The attacker ID, is that just the name of the unit in my case, SAM1?
Contact ID, how would I know the contactID as I dont know what aircraft the player will choose to use?
The mount and weapon numbers that will be available in the database viewer?
So the script should look something like
alt=UnitX().altitude
if alt < 1500 then
ScenEdit_AttackContact(attackerID, contactId ,{mode='1', mount=XXX, weapon=XXX, qty=X})
Do I need a script such as : unit = ScenEdit_UnitX() in order to get the contact ID for the engagement?
Sorry if this seems dumb, but Im trying to understand LUA better.
Regards
Butch
RE: Lua - Trigger Altitude AND in inside Area
Posted: Fri Feb 02, 2018 1:36 am
by michaelm75au
Contact ID is how the other side sees the unit triggering the event.
Sample how it is used.
-- the side doing the detecting
local u = UnitY()
-- unit that triggered event
local contact = UnitX()
-- this unit seen as a contact by others
local con = contact.ascontact
-- not generated as a contact yet
if #con ~= 0 then
-- listed as a contact by some side
-- what is the side id for the base unit
local side = ScenEdit_GetSideOptions({side=u.side}).guid
-- find the side's entry in the triggering unit's contact list
for x = 1, #con do
if con[x].side == side then
-- contact on my side
local mycontact = con[x].guid
-- distance between my base unit and the contact
local dist = u:rangetotarget( mycontact)
if dist < 10 then
print('target in range (' .. dist ..'NM)')
ScenEdit_SetSidePosture( ScenEdit_GetSideOptions({side=contact.side}).guid, side ,'H')
answer=true
else
print('target not in range (' .. dist ..'NM)')
end
end
end
end
This is from my notes. Hope it is useful...I haven't tried this for awhile and not able to validate exactly at the moment. But it should give you idea on how to get the unit as a contact for the side that want to shoot it.
RE: Lua - Trigger Altitude AND in inside Area
Posted: Thu Feb 08, 2018 7:07 am
by butch4343
Michael
Thanks so much for this, this really helsps me get to grips with it.
Thanks
Butch