AlphaSierraGaming

LUA Collection

A few LUA commands that I have found useful in just about every scenario I have done. While they may not exactly fit your scenario the names and refrences can be changed in 1000 ways to make something work the way you want. The key is to experiment.

Weapons

 

ScenEdit_AddWeaponToUnitMagazine({side='Coalition',unitname='Al Dhafra AB',wpn_dbid='1383',number=100,maxcap=250,remove=0,new=1,fillout=0})

 

Grouping

ScenEdit_AddUnit({type = 'Air', unitname = 'Hammer 4', loadoutid = 2837, dbid = 3220, side = 'RED', group= 'Hammer Time'. latitude='11.3950063687867', longitude='105.683132876556',alt=5000})

 

ScenEdit_AddUnit({type = 'Facility', dbid = 428, unitname = 'Barracks', side = 'Blue', group= 'Andersen AFB',latitude='13.5752763748169', longitude='144.936279296875'})

 

ScenEdit_AddUnit({type = 'Facility', dbid = 428, unitname = 'Barracks', side = 'Blue', group= ''}) To Remove From Group Leave Group tag Empty Ie; group=''

 

Plotted Course

 

RC=({

[1] = { longitude = -119.395092123073, latitude = 33.1453014949142, TypeOf = 'ManualPlottedCourseWaypoint' },

[2] = { longitude = -119.451716715467, latitude = 33.2166660362762, TypeOf = 'ManualPlottedCourseWaypoint' })

 

ScenEdit_SetUnit({name='SDV Group',course=RC})

 

Communications (Set Unit)

 

ScenEdit_SetUnit({Name="Test Bottom Array", OutOfComms="True"})

ScenEdit_SetUnit({side="Blue", unitname="USS Wasp", RTB = "yes"})

 

Trigger (UnitX = Unit in trigger area)

 

ScenEdit_AssignUnitToMission('UnitX',"Base Camp Patrol")

 

Posture

 

ScenEdit_SetSidePosture("US", "China", "H")

ScenEdit_SetSidePosture("RED", "China", "H")

 

Mission

 

ScenEdit_AssignUnitToMission('PLAN SAG 1', 'Kill The Carrier')

ScenEdit_AssignUnitToMission('PLAN SAG 3', 'Kill The Vinson')

 

Cargo

 

ScenEdit_UnloadCargo({"San Nicolas Pier",cargoList={dbid=3037,18}})

{name='San Nicolas Pier', guid='0cacb045-6dac-4897-b1be-b41d362f9752'}

ScenEdit_UpdateUnitCargo({guid='34167542-d5c5-45c2-b2f6-88b303cb20c8', mode='add_cargo', cargo={'f7c377a7-90fb-45b7-974c-9c7733e9d294',{5,752}} })

 

Doctrine

 

ScenEdit_SetDoctrine({side="US"}, {weapon_control_status_surface = "0",weapon_control_status_subsurface= "0",weapon_control_status_land= "0", weapon_control_status_air="0" })

ScenEdit_SetDoctrine({side="Blue"}, {engage_opportunity_targets='yes'})

ScenEdit_SetDoctrine({Side= "China", unitname="China D-5 Silo ICBM Group"},{weapon_control_status_land=(0)})

 

EMCON

 

ScenEdit_SetEMCON('Side', 'China', 'Radar=Passive')

ScenEdit_SetEMCON('Unit', 'Hacka Loogie #1', 'Radar=Passive')

ScenEdit_SetEMCON('Unit', 'Hacka Loogie #2', 'Radar=Passive')

ScenEdit_SetEMCON('Mission', 'AEW', 'Radar=Passive, OECM=Passive')

 

Scoring

 

local g = 5

if g <= 7 then

ScenEdit_AddUnit({type = 'Air', unitname = 'KamaKazi 100', loadoutid = 18300, dbid = 3683, side = 'China', latitude='22.8206279079201', longitude='121.916163393456',alt=38000})

ScenEdit_AssignUnitToMission('KamaKazi 100', 'KamaKazi EW')

a=ScenEdit_GetScore("China")

ScenEdit_SetScore('China',(a-500),'-500 Points for KamaKazi')

end

 

 

Delete Random unit

 

local g = math.random(1,10)

if g <= 7 then

ScenEdit_DeleteUnit({side="US", unitname="Seahawk"})

end

a=ScenEdit_GetScore("US")

ScenEdit_SetScore('US',(a-500),'-500 Points for Suppressing Seahawk')

 

Change Unit Side

 

ScenEdit_SetUnitSide({side="Red", name="Firey Cross Reef", newside="Blue"})

 

Change Unit Base

 

ScenEdit_SetUnit({name='Blue Hawk #2',base='Fiery Cross Reef AB'})

ScenEdit_SetUnit({name='Blue Hawk #3',base='Fiery Cross Reef AB'})

ScenEdit_SetUnit({name='Blue Hawk #4',base='Fiery Cross Reef AB'})

ScenEdit_SetUnit({name='Blue Hawk #5',base='Fiery Cross Reef AB'})

ScenEdit_SetUnit({name='Blue Hawk #6',base='Fiery Cross Reef AB'})

ScenEdit_SetUnit({name='Blue Hawk #7',base='Fiery Cross Reef AB'})

ScenEdit_SetUnit({name='Blue Hawk #8',base='Fiery Cross Reef AB'})

ScenEdit_SetUnit({name='Blue Hawk #9',base='Fiery Cross Reef AB'})

 

 

 

ScenEdit_AssignUnitToMission('North Patrol 1', 'North Patrol')

ScenEdit_AssignUnitToMission('North Patrol 2', 'North Patrol')

ScenEdit_SetUnit({Name="North Patrol 1", group="North SAG"})

ScenEdit_SetUnit({Name="North Patrol 2", group="North SAG"})

 

ScenEdit_AssignUnitToMission('South Patrol 1', 'South Patrol')

ScenEdit_AssignUnitToMission('South Patrol 1', 'South Patrol')

ScenEdit_SetUnit({Name="South Patrol 1", group="South SAG"})

ScenEdit_SetUnit({Name="South Patrol 2", group="South SAG"})

 

 

 

mySide1 = VP_GetSide({Name="Blue"})

myZone1 = mySide1:getnonavzone("Fiery Cross Reef AB")

myZone1.isactive = False

 

mySide2 = VP_GetSide({Name="Blue"})

myZone2 = mySide2:getnonavzone("Subi Reef AB")

myZone2.isactive = False

 

mySide3 = VP_GetSide({Name="Blue"})

myZone3 = mySide3:getnonavzone("Quarteron Reef (Heli/Pier)")

myZone3.isactive = False

 

mySide4 = VP_GetSide({Name="Blue"})

myZone4 = mySide4:getnonavzone("Mischief Reef AB")

myZone4.isactive = False

 

mySide5 = VP_GetSide({Name="Blue"})

myZone5 = mySide5:getnonavzone("Gaven Reef (Heli/Pier)")

myZone5.isactive = False

 

mySide6 = VP_GetSide({Name="Blue"})

myZone6 = mySide6:getnonavzone("Johnson Reef (Heli/Pier)")

myZone6.isactive = False

 

mySide7 = VP_GetSide({Name="Blue"})

myZone7 = mySide7:getnonavzone("Hughes Reef (Heli/Pier)")

myZone7.isactive = False

 

 

 

 

mySide1 = VP_GetSide({Name="Blue"})

myZone1 = mySide1:getnonavzone("Fiery Cross Reef AB")

myZone1.isactive = true

 

mySide2 = VP_GetSide({Name="Blue"})

myZone2 = mySide2:getnonavzone("Subi Reef AB")

myZone2.isactive = true

 

mySide3 = VP_GetSide({Name="Blue"})

myZone3 = mySide3:getnonavzone("Quarteron Reef (Heli/Pier)")

myZone3.isactive = true

 

mySide4 = VP_GetSide({Name="Blue"})

myZone4 = mySide4:getnonavzone("Mischief Reef AB")

myZone4.isactive = true

 

mySide5 = VP_GetSide({Name="Blue"})

myZone5 = mySide5:getnonavzone("Gaven Reef (Heli/Pier)")

myZone5.isactive = true

 

mySide6 = VP_GetSide({Name="Blue"})

myZone6 = mySide6:getnonavzone("Johnson Reef (Heli/Pier)")

myZone6.isactive = true

 

mySide7 = VP_GetSide({Name="Blue"})

myZone7 = mySide7:getnonavzone("Hughes Reef (Heli/Pier)")

myZone7.isactive = true

 

local u1;

local u2;

u1 = ScenEdit_AddUnit({type="ship", side="US Navy", name="FFG-49 Robert G. Bradley", dbid=726, lat=28.58694, lon=49.409, heading=270});

u2 = ScenEdit_AddUnit({type="aircraft", side="US Navy", name="SmallHeloThatFits", dbid=1593, lat=28.58694, lon=49.409, heading=270,altitude=1000,loadoutid=15083});

--Put unit2 into unit1

ScenEdit_HostUnitToParent({HostedUnitNameOrID= tostring(u2.guid), SelectedHostNameOrID= tostring(u1.guid)});

 

 

Add Ferry Mission To Ship docked in port

 

ScenEdit_AddMission('Red','NPHelo2','Ferry',{destination='North Patrol 2'})

 

Get Unit information

 

local a = ScenEdit_GetUnit({name='USS Princeton (CG-59)', guid='CXXC1K-0HM0G0H4069SP'})

print(a)

 

[Returns:]

 

unit {

type = 'Ship',

subtype = '3106',

name = 'USS Cape St. George (CG-71)',

side = 'Blue',

guid = 'cxxc1k-0hlu7d7pg41qh',

class = 'CG 59 Princeton [Ticonderoga Baseline 3, VLS]',

proficiency = 'Veteran',

latitude = '19.1288620629699',

longitude = '126.840628644493',

altitude = '0',

heading = '37.36402',

speed = '20',

throttle = 'Cruise',

autodetectable = 'False',

group = 'Cape St. George SAG',

mission = 'Cape St. George AOR',

mounts = '25',

magazines = '32',

unitstate = 'OnPlottedCourse',

fuelstate = 'None',

weaponstate = 'None',

}

 

print(a.fuel)

[Returns:]

 

{ [2001] = { max = 72000, name = 'AviationFuel', type = 2001, current = 72000 }, [3003] = { max = 2000000, name = 'GasFuel', type = 3003, current = 893080.375 } }

 

[Logic](if u ~= nil then - Check if unit is still in scenario Ie; Not sunk)

 

u = ScenEdit_GetUnit({name='USS Cape St. George (CG-71)', guid='cxxc1k-0hlu7d7pg41qh'})

if u ~= nil then

local newfuel = u.fuel

if newfuel[3003].current < 1000000 then

newfuel[3003].current = newfuel[3003].max

u.fuel = newfuel

end

end

 

{Launch Tanker}...More realistic?

 

u = ScenEdit_GetUnit({name='USS Port Royal (CG-73)', guid='cxxc1k-0hlsrof1eaphc'})

if u ~= nil then

local newfuel = u.fuel

if newfuel[3003].current < 1000000 then

ScenEdit_AssignUnitToMission('Asuna', 'Royal Pain AOR')

end

end

 

ScenEdit_RefuelUnit({side="United States", unitname="USS Port Royal (CG-73)", tanker="Asuna"})

 

Functions for 3 types of fuel in SCS Template Ships

 

function Fillup3003( side, name )

u = ScenEdit_GetUnit({side=side,name=name})

if u ~= nil then

local newfuel = u.fuel

if newfuel[3003].current < 1000000 then

newfuel[3003].current = newfuel[3003].max

u.fuel = newfuel

end

end

end

 

function Fillup3002( side, name )

v = ScenEdit_GetUnit({side=side,name=name})

if v ~= nil then

local newfuel = v.fuel

if newfuel[3002].current < 15000 then

newfuel[3002].current = newfuel[3002].max

v.fuel = newfuel

end

end

end

 

function Fillup3001( side, name )

w = ScenEdit_GetUnit({side=side,name=name})

if w ~= nil then

local newfuel = w.fuel

if newfuel[3001].current < 1000000 then

newfuel[3001].current = newfuel[3001].max

w.fuel = newfuel

end

end

end

 

Fillup3003('Blue','USS Port Royal (CG-73)')

Fillup3003('Blue','USS John Paul Jones (DDG-53)')

Fillup3003('Blue','USS Cape St. George (CG-71)')

Fillup3003('Blue','USS William P. Lawrence (DDG-110)')

Fillup3003('Blue','USS Lake Erie (CG-70)')

Fillup3003('Blue','USS McFaul (DDG-74)')

Fillup3003('Blue','USS Shiloh (CG-67)')

Fillup3003('Blue','USS Mustin (DDG-89)')

Fillup3003('Blue','USS Leyte Gulf (CG-55)')

Fillup3003('Blue','USS Vella Gulf (CG-72)')

Fillup3003('Blue','USS Ross (DDG-71)')

Fillup3003('Blue','USS Shoup (DDG-86)')

Fillup3003('Blue','USS Pinckney (DDG-91)')

Fillup3003('Blue','USS Kidd (DDG-100)')

Fillup3003('Blue','USS Spruance (DDG-111)')

Fillup3003('Blue','USS Rafael Peralta DDG-115)')

Fillup3003('Blue','USS Chancellorsville (CG-62)')

Fillup3003('Blue','USS McCampbell (DDG-85)')

Fillup3003('Blue','USS Howard (DDG-83)')

Fillup3003('Blue','USS Preble (DDG-88)')

Fillup3003('Blue','USS Daniel Inouye (DDG-118)')

Fillup3001('Blue','USS Harpers Ferry (LSD-49)')

Fillup3001('Blue','USS Whidbey Island (LSD-41)')

Fillup3002('Blue','USS Essex (LHD-2)')

Fillup3002('Blue','USS Peleliu (LHA-5)')

Fillup3003('Blue','USS Princeton (CG-59)')

Fillup3003('Blue','USS Shoup (DDG-86)')

Fillup3003('Blue','USS Pinckney (DDG-91)')

Fillup3003('Blue','USS Kidd (DDG-100)')

Fillup3003('Blue','USS John Finn (DDG-113)')

 

 

Deactivate AI? (Renders the affected units "blind" to minimize CPU workload in large scenarios)

Thank You MichaelAU (Matrix Forums)

 

local listOfGUIDsForAllUnitsOnSide = VP_GetSide({side='Merchant'}).units

local typeOfUnitIAmInterestedIn = 'Aircraft'

local listOfUnitsIWantToWorkWith = {}

 

for k,v in ipairs (listOfGUIDsForAllUnitsOnSide) do

local unit = ScenEdit_GetUnit({guid=v.guid})

if unit.type == typeOfUnitIAmInterestedIn then

table.insert(listOfUnitsIWantToWorkWith,unit)

print ("'"..unit.guid.."', --"..unit.name.." ("..unit.classname..") added to list of units to work with..")

end

 

end

 

print ('List complete! '..#listOfUnitsIWantToWorkWith..' units added to list.')

 

local counter = 0

for k,v in ipairs (listOfUnitsIWantToWorkWith) do

local unit = ScenEdit_GetUnit({guid=v.guid})

unit.AI_DeterminePrimaryTarget_enabled = false

unit.AI_EvaluateTargets_enabled = false

print (unit.name..' AI disabled!')

counter = counter + 1

end

print ('Run complete, AI disabled for '..counter..' units.')

 

 

 

RTB After 11 Hrs Airborne (See Atlantic Wolfpack Carrier II event Poseidon RTB Check)

 

local

a = ScenEdit_GetUnit({name='War Eagle 421', guid='cxxc1k-0hluoncgrovfb'})

if a ~= nil then

b = a.airbornetime

num = tonumber(string.sub(b,1,2))

if num > 10

then

ScenEdit_SetUnit({side="Blue", unitname='War Eagle 421', RTB = "yes"})

end

end

 

local a = ScenEdit_GetLoadout({name='War Eagle 421'})

print(a.weapons)

 

 

{ [1] = { wpn_type = 2001, wpn_guid = 'cxxc1k-0hluoncgrovg3', wpn_current = 2, wpn_maxcap = 2, wpn_dbid = 452, wpn_name = 'AGM-84K SLAMER-ATA', wpn_default = 2 }, [2] = { wpn_type = 4001, wpn_guid = 'cxxc1k-0hluoncgrovg4', wpn_current = 5, wpn_maxcap = 5, wpn_dbid = 902, wpn_name = 'Mk54 LHT Mod 0', wpn_default = 5 }, [3] = { wpn_type = 4003, wpn_guid = 'cxxc1k-0hluoncgrovg5', wpn_current = 45, wpn_maxcap = 60, wpn_dbid = 2496, wpn_name = 'AN/SSQ-53F DIFAR', wpn_default = 60 }, [4] = { wpn_type = 4003, wpn_guid = 'cxxc1k-0hluoncgrovg6', wpn_current = 22, wpn_maxcap = 40, wpn_dbid = 2482, wpn_name = 'AN/SSQ-62E DICASS', wpn_default = 40 }, [5] = { wpn_type = 4003, wpn_guid = 'cxxc1k-0hluoncgrovg7', wpn_current = 26, wpn_maxcap = 40, wpn_dbid = 1939, wpn_name = 'AN/SSQ-77B VLAD', wpn_default = 40 } }

 

 

Load DF-21 onto Ship Guid of ship cargo = qty, dbid (found dbid of cargo in add weapons mount)

*Note When loaded ship arrives at pier it unloads cargo automatically?

 

ScenEdit_UpdateUnitCargo({guid='CXXC1K-0HM0M19DH4VDV', mode='add_cargo', cargo={{4,1858},{1,2284}} })

ScenEdit_UpdateUnitCargo({guid='CXXC1K-0HM0M19DH50B0', mode='add_cargo', cargo={{4,3085},{1,2284}} })

ScenEdit_UpdateUnitCargo({guid='CXXC1K-0HM05GMR87KST', mode='add_cargo', cargo={{4,3085},{1,2284}} })

 

ScenEdit_UpdateUnitCargo({guid='CXXC1K-0HM0OIQSML1D9', mode='add_cargo', cargo={{4,3085},{1,2284},{1,3085}} })

 

Load Y-20 with DF-21's

ScenEdit_UpdateUnitCargo({guid='CXXC1K-0HM1HC9QLIQTO', mode='add_cargo', cargo={{4,3085}})

ScenEdit_UpdateUnitCargo({guid='CXXC1K-0HM1HC9QLIQU7', mode='add_cargo', cargo={{4,1858}})

 

Unload Y-20's

 

local u = SE_GetUnit({name='Cargo Loogie #1', guid='CXXC1K-0HM1HC9QLIQTO'})

ScenEdit_UnloadCargo(u.name, { {4,3085}})

 

 

local u = SE_GetUnit({Cargo Loogie #2', guid='CXXC1K-0HM1HC9QLIQU7'})

ScenEdit_UnloadCargo(u.name, { {4,1858}})

 

{name='Cargo Loogie #1', guid='CXXC1K-0HM1HC9QLIQTO'}

{name='Cargo Loogie #2', guid='CXXC1K-0HM1HC9QLIQU7'}

 

Unload Cargo from Hangar on Coco

 

local cc = SE_GetUnit({{name='A/C Hangar (4x Medium Aircraft)', guid='CXXC1K-0HM181HNFBG94'})

print(cc.cargo[1].cargo)

for k,v in pairs (cc.cargo[1].cargo) do

print(v.dbid)

ScenEdit_UnloadCargo(cc.name, { {v.quantity,v.dbid}})

end

 

Unload cargo from mischief reef navy pier

 

local u = SE_GetUnit({name='Mischief Reef Navy Pier', guid='04c20418-a924-4669-b15f-0a8bd8aa6004'})

print(u.cargo[1].cargo)

 

for k,v in pairs (u.cargo[1].cargo) do

print(v.dbid)

ScenEdit_UnloadCargo(u.name, { {v.quantity,v.dbid}})

end

 

Unload Cargo From Mischief Pier (Short Version)

 

local u = SE_GetUnit({name='Mischief Reef Navy Pier', guid='04c20418-a924-4669-b15f-0a8bd8aa6004'})

ScenEdit_UnloadCargo(u.name, { {4,1858},{1,2284}})

 

Unload cargo from Johnson Reef Navy Pier (short version)

 

local u = SE_GetUnit({name='Johnson Reef Naval Pier', guid='CXXC1K-0HM0MKD4P35LJ'})

ScenEdit_UnloadCargo(u.name, { {4,1858},{1,2284}})

 

Unload Cargo from Firey Cross Pier (Short Version)

 

ScenEdit_AssignUnitToMission('Type 052D Escort 3', 'DF21 Group Retun Ferry')

ScenEdit_AssignUnitToMission('Type 052D Escort 4', 'DF21 Group Retun Ferry')

ScenEdit_AssignUnitToMission('Kunlun Shan (998)', 'DF21 Group Retun Ferry')

 

local j = SE_GetUnit({name='Fiery Cross Reef Structure (Pier [Extra Large, 200-500m])', guid='cxxc1k-0hltoh3e62099'})

ScenEdit_UnloadCargo(u.name, { {4,1858},{1,2284}})

 

 

local j = SE_GetUnit({name='Fiery Cross Reef Structure (Pier [Extra Large, 200-500m])', guid='cxxc1k-0hltoh3e62099'})

ScenEdit_UnloadCargo(u.name, { {4,1858},{1,2284}})

 

 

Get original mission for After FON

 

local StGeorge = SE_GetUnit({name='USS Cape St. George (CG-71)', guid='cxxc1k-0hlu7d7pg41qh'})

aor1=(StGeorge.mission.name)

 

 

local RoyalPain = SE_GetUnit({name='Royal Pain SAG', guid='cxxc1k-0hltnt9mlak83'})

aor1=(RoyalPain.mission.name)

 

 

local Shiloh = SE_GetUnit({name='Shiloh SAG', guid='cxxc1k-0hltnt9mlb1gj'})

aor1=(RoyalPain.mission.name)

 

local FONUnit = SE_GetUnit({UnitX()})

If FONUnit.name =

 

 

"Attack" a contact using BOL This will launch 4 Itald at a lat lon cordinate from a Hornet

 

local myunit = ScenEdit_GetUnit({unitname=UnitX().name})

local retval = ScenEdit_AttackContact(myunit.guid,'BOL',{latitude='31.4171680192908', longitude='121.289345200049', mode=1, weapon=881,qty=4})

 

Click Image To Watch Our Channel On Your Favorite Platform

Click Image To Follow Link

Roku
Copyright 2020-2021 AlphaSierraGaming - All Rights Reserved