Difference between revisions of "Script Repository"

From Weapons Release Wiki
Jump to: navigation, search
Line 124: Line 124:
 
ScenEdit_AddUnit({type = 'Air', unitname = 'F-15C Eagle', loadoutid = 16934, dbid = 3500, side = 'Mercs', base='Home'})
 
ScenEdit_AddUnit({type = 'Air', unitname = 'F-15C Eagle', loadoutid = 16934, dbid = 3500, side = 'Mercs', base='Home'})
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
 +
===Create a single unit in the air.===
 +
<syntaxhighlight lang="lua" line='line'>
 +
ScenEdit_AddUnit({type="air", side="Mercs", name="Plane", dbid=1160, loadoutid=12354, latitude="29.297778", longitude="90.911944", altitude="5000 ft", heading=0})
 +
</syntaxhighlight>
 +
  
 
===Create a single unit on whatever side you're playing that has a base named Home. ===
 
===Create a single unit on whatever side you're playing that has a base named Home. ===

Revision as of 16:27, 26 March 2020

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

  • 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

  • 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

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

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

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

Add a group of trucks to a random zone with a random course.

 1 local x =0
 2 local la="N46"
 3 local lo="E25"
 4 while x<math.random(10,50) do
 5     la = "N" .. math.random(29.5,36.5)
 6     lo = "E" .. math.random(60,71)
 7     ScenEdit_AddUnit({type = 'FACILITY', name = 'Convoy',
 8     heading = math.random(0,359), dbid = 624, side = 'NOTSOVIET', Latitude=la, Longitude=lo,
 9     autodetectable="false",
10 course={{lat="N".. math.random(30,37), lon="E" .. math.random(60,71)}}
11     })
12     x=x+1
13 end

Create a single unit in an airfield.

1 ScenEdit_AddUnit({type = 'Air', unitname = 'F-15C Eagle', loadoutid = 16934, dbid = 3500, side = 'Mercs', base='Home'})


Create a single unit in the air.

1 ScenEdit_AddUnit({type="air", side="Mercs", name="Plane", dbid=1160, loadoutid=12354, latitude="29.297778", longitude="90.911944", altitude="5000 ft", heading=0})


Create a single unit on whatever side you're playing that has a base named Home.

1 ScenEdit_AddUnit({type = 'Air', unitname = 'JAS-39C Gripen', loadoutid = 17279, dbid = 3226, side = ScenEdit_PlayerSide(), base='Home'})

Create multiple aircraft with the same name.

1 for planes = 1, 8, 1 do
2 ScenEdit_AddUnit({type = 'Air', unitname = 'JAS-39C Gripen', loadoutid = 17279, dbid = 3226, side = 'Mercs', base='Home'})
3 end

Create multiple aircraft, numbered.

1 for planes = 1, 8, 1 do
2 ScenEdit_AddUnit({type = 'Air', unitname = 'JAS-39C Gripen #'..planes, loadoutid = 17279, dbid = 3226, side = 'Mercs', base='Home'})
3 end

Set single unit as ready.

1 ScenEdit_SetLoadout({UnitName = "F-15C Eagle", LoadoutID = 0, TimeToReady_Minutes = 0, IgnoreMagazines = 1})

Set an entire batch as ready.

1 for i=1,6 do ScenEdit_SetLoadout({UnitName = "Ghostrider #"..i, LoadoutID = 0, TimeToReady_Minutes = 0, ignoremagazines = 1}) end

Swap Unit Side

1 ScenEdit_SetUnitSide({side='Opfor', name='airfield', newside='Blufor'})

Randomly create and delete units.

 1 math.randomseed(os.time())
 2 math.random()
 3 
 4 a = math.random(1,3)
 5 
 6 print(a)
 7 
 8 if a == 1 then
 9 
10 ScenEdit_DeleteUnit({name="Radar (China JY-8A Wall Rust)", base="Lhasa Gonggar International Airport"})
11 print("The Radar Blew Up!")
12 
13 elseif a == 2 then
14 
15 ScenEdit_DeleteUnit({name="Radar (China JY-8A Wall Rust)", base="Lhasa Gonggar International Airport"})
16 ScenEdit_AddUnit({type="land", side="China", name="AAA Sec (35mm/90 Type 90 x 2) (2x)", dbid=1682, latitude="29.297778", longitude="90.911944"})
17 print("The Radar Blew up! But you detect AAA radar firing up...")
18 
19 elseif a == 3 then
20 
21 ScenEdit_AddUnit({type="land", side="China", name="AAA Sec (35mm/90 Type 90 x 2) (2x)", dbid=1682, latitude="29.297778", longitude="90.911944"})
22 ScenEdit_AddUnit({type="land", side="China", name="AAA Sec (35mm/90 Type 90 x 2) (2x)", dbid=1682, latitude="29.304571450518", longitude="90.8938412514606"})
23 print("The mercs cut a sewage line and alerted the base. You detect AAA radar firing up...")
24 
25 end

Assign units to a mission

1 for i=1,6 do ScenEdit_AssignUnitToMission("Jas Gripen 39C #"..i, "Suicide Run") end

See component damage

1 local unit = ScenEdit_GetUnit({side="Opfor", unitname="JAS-39C Gripen#1"})
2 print(unit)
3 print(unit.components)

Set unit Damage

1 ScenEdit_SetUnitDamage({side="Opfor", unitname="JAS-39C Gripen #1", fires=1, components={{"F404-GE-400 RM.12 #1","None"}}}) \\ Sets unit component damaged

Arrayed Pilot Name List

1 arr = {"pilot x", "pilot y"}
2 
3 for i,line in ipairs(arr) do
4 ScenEdit_AddUnit({type = 'Air', unitname = line, loadoutid = 17279, dbid = 3226, side = 'Mercs', base='Home'})
5 end

Variable

1 test = "Hello World!"
2 print(test)