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
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