Lua - Paradrop
Posted: Sun Jul 24, 2016 12:50 pm
This is primarily for CK and michaelm but if any other Lua wizard is out there, please chime in.
Looking to do a para drop. 4x DZ, 4x Coy, 2 C-130's per DZ.
Based on your conversation here: tm.asp?m=4092628
I think I'm on the right track but have a couple questions
Event: Scenario Initialised
-- set up keys
ScenEdit_SetKeyValue("Recon/A", "dbid=714, maxNum=4, curNum=0");
ScenEdit_SetKeyValue("Recon/B", "dbid=714, maxNum=4, curNum=0");
ScenEdit_SetKeyValue("Recon/C", "dbid=714, maxNum=4, curNum=0");
ScenEdit_SetKeyValue("Recon/HQ", "dbid=714, maxNum=4, curNum=0");
Event: Drop troops and recall Hurc This will have to be done once for each DZ
local drop = ScenEdit_GetKeyValue("Recon/A");print("Drop: "..drop );
local t = {}
for k, v in string.gmatch(drop, "(%w+)=(%w+)")
do
t[k] = v
end
-- deploy one unit
local lastN = tonumber(t['curNum']);
if lastN == nil then
lastN = 0;
end
lastN = lastN +1;
if lastN > tonumber( t['maxNum']) then
ScenEdit_MsgBox('All troops landed',0)
return
end
-- deploy 2nd unit This is where I am not sure, each Hurc will carry 2x Pl this is the 2nd
local lastN = tonumber(t['curNum']);
if lastN == nil then
lastN = 0;
end
lastN = lastN +1;
if lastN > tonumber( t['maxNum']) then
ScenEdit_MsgBox('All troops landed',0)
return
end
local unit = ScenEdit_UnitX()
local world = -999999
local new ={}
local retries = 10
while world <0 and retries > 0
do
v = math.random () / 100; y = math.random() /100;print(v);print(y)
new.lat= tonumber(unit.latitude)+v-y;new.lon=tonumber(unit.longitude)-v+y
world = World_GetElevation({latitude=new.lat, longitude=new.lon});print(world)
retries = retries - 1
end
unit.altitude = world
if world >0 then
local veh =ScenEdit_AddUnit({type = 'Facility', name = 'AirDrop #' .. lastN,
heading = 0, dbid = t['dbid'], side = 'RAN', Lat=new.lat, Lon=new.lon});print(veh)
local b="curNum="..tostring(lastN)
local a=string.gsub(drop,"curNum=%d", b)
ScenEdit_SetKeyValue("CanberraAir", a); -- last id added successfully
end
-- unable to change loadout unless landed
-- if loadout could be interrogated and changed, then only troop carrying loadout could be checked with this script
-- and once troops deployed, an 'empty' loadout substituted
--ScenEdit_SetLoadout ({guid = unit.guid, loadoutid=9277, timetoready_minutes=0, ignoreMagzines=true})
Also in the Sandbox scenario you had a condition, which told a unit to wait if there is another in the process ahead of it. I don't want that but is it needed to ensure there is no Lua conflict or something?
Thanks guys - This is just a trial run before the major Regt size Amphib ... youch...
B
Looking to do a para drop. 4x DZ, 4x Coy, 2 C-130's per DZ.
Based on your conversation here: tm.asp?m=4092628
I think I'm on the right track but have a couple questions
Event: Scenario Initialised
-- set up keys
ScenEdit_SetKeyValue("Recon/A", "dbid=714, maxNum=4, curNum=0");
ScenEdit_SetKeyValue("Recon/B", "dbid=714, maxNum=4, curNum=0");
ScenEdit_SetKeyValue("Recon/C", "dbid=714, maxNum=4, curNum=0");
ScenEdit_SetKeyValue("Recon/HQ", "dbid=714, maxNum=4, curNum=0");
Event: Drop troops and recall Hurc This will have to be done once for each DZ
local drop = ScenEdit_GetKeyValue("Recon/A");print("Drop: "..drop );
local t = {}
for k, v in string.gmatch(drop, "(%w+)=(%w+)")
do
t[k] = v
end
-- deploy one unit
local lastN = tonumber(t['curNum']);
if lastN == nil then
lastN = 0;
end
lastN = lastN +1;
if lastN > tonumber( t['maxNum']) then
ScenEdit_MsgBox('All troops landed',0)
return
end
-- deploy 2nd unit This is where I am not sure, each Hurc will carry 2x Pl this is the 2nd
local lastN = tonumber(t['curNum']);
if lastN == nil then
lastN = 0;
end
lastN = lastN +1;
if lastN > tonumber( t['maxNum']) then
ScenEdit_MsgBox('All troops landed',0)
return
end
local unit = ScenEdit_UnitX()
local world = -999999
local new ={}
local retries = 10
while world <0 and retries > 0
do
v = math.random () / 100; y = math.random() /100;print(v);print(y)
new.lat= tonumber(unit.latitude)+v-y;new.lon=tonumber(unit.longitude)-v+y
world = World_GetElevation({latitude=new.lat, longitude=new.lon});print(world)
retries = retries - 1
end
unit.altitude = world
if world >0 then
local veh =ScenEdit_AddUnit({type = 'Facility', name = 'AirDrop #' .. lastN,
heading = 0, dbid = t['dbid'], side = 'RAN', Lat=new.lat, Lon=new.lon});print(veh)
local b="curNum="..tostring(lastN)
local a=string.gsub(drop,"curNum=%d", b)
ScenEdit_SetKeyValue("CanberraAir", a); -- last id added successfully
end
-- unable to change loadout unless landed
-- if loadout could be interrogated and changed, then only troop carrying loadout could be checked with this script
-- and once troops deployed, an 'empty' loadout substituted
--ScenEdit_SetLoadout ({guid = unit.guid, loadoutid=9277, timetoready_minutes=0, ignoreMagzines=true})
Also in the Sandbox scenario you had a condition, which told a unit to wait if there is another in the process ahead of it. I don't want that but is it needed to ensure there is no Lua conflict or something?
Thanks guys - This is just a trial run before the major Regt size Amphib ... youch...
B