Script Repository

From Weapons Release Wiki
Jump to: navigation, search

Put your Lua scripts here. This is less for learning how the scripts work and instead giving working examples and showing the results. If this is not your script please attribute the author.

Please add a description of functionality and use the <syntaxhighlight lang="lua" line='line'>Lua code here</syntaxhighlight> tags.

Airfields[edit]

  • This script places a unit into an airbase.
1 ScenEdit_AddUnit({type = 'Air', unitname = 'F-15C Eagle', loadoutid = 16934, dbid = 3500, side = 'Mercs', base='Home'})

Unit Functions[edit]

  • This script uses the filterOnComponent method to return a type of component.
1 local unit = ScenEdit_GetUnit({side="BLUFOR", unitname="MIG-21"})
2 print(unit)
3 print(unit.components)
4 print(unit:filterOnComponent("Sensor"))

Which returns the below values. filterOnComponent results highlighted in yellow.

 1 unit {
 2  type = 'Aircraft', 
 3  subtype = '2001', 
 4  name = 'MIG-21', 
 5  side = 'BLUFOR', 
 6  guid = '6d088198-4a5b-44a5-b87f-75da50f8cf8c', 
 7  proficiency = 'Regular', 
 8  latitude = '0.706202368990351', 
 9  longitude = '-2.44914023444803', 
10  altitude = '10972.8', 
11  heading = '0', 
12  speed = '350', 
13  throttle = 'Loiter', 
14  autodetectable = 'False', 
15  mounts = '1', 
16  magazines = '1', 
17  unitstate = 'Unassigned', 
18  fuelstate = 'None', 
19  weaponstate = 'None', 
20 }
21 { [1] = { comp_guid = '33dec6b3-3bef-4858-8c92-4aaf4b8cc31a', comp_type = 'Sensor', comp_status = 'Operational', comp_dbid = 887, comp_name = 'Jay Bird [RP-22M Sapfir-22]' }, [2] = { comp_guid = '6771ae2d-0e11-413a-9321-b1bf0cd7483d', comp_type = 'Sensor', comp_status = 'Operational', comp_dbid = 2750, comp_name = 'SPO-10 Sirena-3M' }, [3] = { comp_guid = 'fe11edda-9b00-4175-a83e-369157d354af', comp_type = 'Sensor', comp_status = 'Operational', comp_dbid = 0, comp_name = 'Mk1 Eyeball' }, [4] = { comp_guid = '721ecc1f-ca3d-42a7-b460-ef43829868c7', comp_type = 'Mount', comp_status = 'Operational', comp_dbid = 274, comp_name = '23mm Gsh-23L [200 rnds]' }, [5] = { comp_guid = '0231e457-4203-4dfc-81ce-5ff0068b6c58', comp_type = 'CommDevice', comp_status = 'Operational', comp_dbid = 20, comp_name = 'UHF/VHF Radio [Unsecure]' }, [6] = { comp_guid = 'f6058dbb-6ce0-4bb0-816b-04437e4a3e75', comp_type = 'Engine', comp_status = 'Operational', comp_dbid = 393, comp_name = 'R-25-300 #1' } }
22 { [1] = { comp_guid = '33dec6b3-3bef-4858-8c92-4aaf4b8cc31a', comp_type = 'Sensor', comp_status = 'Operational', comp_dbid = 887, comp_name = 'Jay Bird [RP-22M Sapfir-22]' }, [2] = { comp_guid = '6771ae2d-0e11-413a-9321-b1bf0cd7483d', comp_type = 'Sensor', comp_status = 'Operational', comp_dbid = 2750, comp_name = 'SPO-10 Sirena-3M' }, [3] = { comp_guid = 'fe11edda-9b00-4175-a83e-369157d354af', comp_type = 'Sensor', comp_status = 'Operational', comp_dbid = 0, comp_name = 'Mk1 Eyeball' } }
  • This script set a unit to "Out of Comms". This is a simpler way than destroying a radio component.
1 ScenEdit_SetUnit({Name="USS Barry", OutOfComms="True"})


Waypoints[edit]

This script will set waypoints for a unit. Useful for pathing OPFOR after they take off for a strike mission.

1 ScenEdit_SetUnit({side="BLUFOR",
2 unitname="Unit",
3 course={
4 {latitude='41.4581064637219', longitude='23.271687278387', presetAltitude=min, desiredAltitude='200', description='test'},
5 {latitude='42.2706667596912', longitude='23.0730243792651'},
6 {latitude='42.6907498549919', longitude='23.0425951461823'},
7 {latitude='42.7065667663771', longitude='23.4498477038231'}
8 }
9 })

Check Unit Name[edit]

This script will check if a unit matches a name. Useful to detect if a certain unit or type of unit enters an area.

1 local unit = UnitX()
2 print(unit)
3 local namecheck = 'JAS 39F Gripen NG'
4 local name2 = 'JAS 39B Gripen'
5 if unit.name == namecheck or unit.name == name2 then print('New!') end

Compare a Unit Detail[edit]

Looks at a unit and detects if it matches a variable. The % is needed before the - and the / as Lua will ignore it otherwise.

1 local unit = UnitX()
2 print(unit)
3 print(unit.name)
4 
5 if string.find(unit.name, "GBU%-39%/B SDB") then
6 print("SDB")
7 end