Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

Using UnitX() In Conditions

 
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 >> Using UnitX() In Conditions Page: [1]
Login
Message << Older Topic   Newer Topic >>
Using UnitX() In Conditions - 10/20/2017 8:25:29 PM   
TitaniumTrout


Posts: 374
Joined: 10/20/2014
From: Michigan
Status: offline
Hello!

I'm working with Conditions in the Event Editor and can get it to pass a true or false depending on a variable. Working example here :

local mission = ScenEdit_GetMission('OPFOR', 'Test')

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


Now when I try to get some unit info on the triggering plane I just get a false return. Does UnitX() not work within the Condition field?

local unit = ScenEdit_UnitX()

if unit.altitude > '1000' then
 return true
else
 return false
end


Also, are multiple conditions AND or OR with each other?



_____________________________

Post #: 1
RE: Using UnitX() In Conditions - 10/21/2017 11:12:22 AM   
michaelm75au


Posts: 13500
Joined: 5/5/2001
From: Melbourne, Australia
Status: offline
Yes, you can use UnitX in a condition.
If any condition is FALSE, then condition fails.

Useful thing is that you can include a print in the Lua scripts, and they will print to a file 'LuaHistory' in folder 'logs'for the day.


_____________________________

Michael

(in reply to TitaniumTrout)
Post #: 2
RE: Using UnitX() In Conditions - 10/21/2017 3:43:06 PM   
TitaniumTrout


Posts: 374
Joined: 10/20/2014
From: Michigan
Status: offline
Excellent! I wasn't aware of the lua log, that'll be very helpful for troubleshooting. I was comparing an integer with a string.

local unit = ScenEdit_UnitX()
print(unit.altitude)
local minAlt = 3000

if unit.altitude < minAlt then
 return true
else
 return false
end


< Message edited by TitaniumTrout -- 10/21/2017 3:45:46 PM >


_____________________________


(in reply to michaelm75au)
Post #: 3
RE: Using UnitX() In Conditions - 10/22/2017 3:15:29 AM   
michaelm75au


Posts: 13500
Joined: 5/5/2001
From: Melbourne, Australia
Status: offline
Another useful tidbit:
To see what scripts are executing in events, open the Lua console and run the following.
_lua_event = true

This will list out the script executed to the history file. eg
quote:

22/10/2017 2:03:07 PM -- B976 --
Script:Within range
local x,y
local answer = false
-- unit base range on
local u = ScenEdit_GetUnit({name='Group_2612', guid='cd015e09-d208-4e67-9af0-3e8e0412209c'})
if u == nil then
return answer
end
-- unit that triggered event
local contact = ScenEdit_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
return answer
...
Function:ScenEdit_GetUnit (4) Error:Need to define a Name or Guid to identify a unit. Preferably a Guid or Side & Name.
22/10/2017 2:03:07 PM -- B976 --
Script:SAR
print('activate rescue')

local rescue = ScenEdit_UnitX()
local sar = ScenEdit_UnitY()
local chopper = nil
print(rescue)
print(sar)
if sar.unit.mission.name == 'SAR Mission' then
print( sar.unit.name .. ' rescuing ' .. rescue.name)
chopper = sar.unit
else
local mission = ScenEdit_GetMission(sar.unit.side, 'SAR Mission')
if mission == nill or mission.isactive == false then
print('no rescue')
else
for x = 1, #mission.unitlist do
local u = ScenEdit_GetUnit( {guid = mission.unitlist[x]})
print(u.airbornetime )
if #u.airbornetime > 0 then
chopper = u
print( chopper.name .. ' rescuing ' .. rescue.name)
break
else
print('no rescue')
end
end
end
end
if chopper ~= nil then
chopper.course = { {latitude = rescue.latitude, longitude = rescue.longitude, PRESETTHROTTLE='Hover', PRESETALTITUDE='MinAltitude'}}
end
activate rescue
unit {
type = 'Ship',
subtype = '9001',
name = 'Life Raft [5m]',
side = 'Markers',
guid = '7b6fc824-ad6f-4d77-9b55-d47729b2078b',
proficiency = 'Regular',
latitude = '33.8400329345168',
longitude = '136.823460247542',
altitude = '0',
heading = '0',
speed = '0',
throttle = 'FullStop',
autodetectable = 'False',
mounts = '0',
magazines = '0',
unitstate = 'Unassigned',
fuelstate = 'None',
weaponstate = 'None',
}
{ unit = unit {
type = 'Aircraft',
subtype = '6001',
name = 'Seeker #1',
side = 'SideA',
guid = '7a3b7dce-abe1-4b60-b0d5-b0f27510d4de',
proficiency = 'Regular',
latitude = '33.8481608094017',
longitude = '137.358870760905',
altitude = '457.2',
heading = '265.9691',
speed = '140',
throttle = 'Cruise',
autodetectable = 'False',
base = 'USS Rentz',
mission = 'SAR Mission',
mounts = '0',
magazines = '0',
unitstate = 'OnPlottedCourse',
fuelstate = 'None',
weaponstate = 'None',
}, sensor = { [1] = { name = 'Generic FLIR', type = 'Infrared' } } }
Seeker #1 rescuing Life Raft [5m]
22/10/2017 2:03:11 PM -- B976 --
Script:Within range
local x,y
local answer = false
-- unit base range on
local u = ScenEdit_GetUnit({name='Group_2612', guid='cd015e09-d208-4e67-9af0-3e8e0412209c'})
if u == nil then
return answer
end
-- unit that triggered event
local contact = ScenEdit_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
return answer



_____________________________

Michael

(in reply to TitaniumTrout)
Post #: 4
RE: Using UnitX() In Conditions - 10/22/2017 3:20:53 AM   
michaelm75au


Posts: 13500
Joined: 5/5/2001
From: Melbourne, Australia
Status: offline
Note the error reported
quote:

Function:ScenEdit_GetUnit (4) Error:Need to define a Name or Guid to identify a unit. Preferably a Guid or Side & Name.

It relates to the proceeding script 'Within range' on line (4). The reference used in the call does not exist.

Errors and print statements will show up after the dump of the script.
Again very useful for finding those weird cases before releasing the scenario into the "wild".

_____________________________

Michael

(in reply to michaelm75au)
Post #: 5
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> Using UnitX() In Conditions 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.984