LUA script for RTB flying UAV/UCAVs and set them unavailable
Posted: Sat May 06, 2023 7:32 pm
I'm trying to write a LUA script which
1) will pick all flying UAV/UCAVs of Bravo side, return them to base and set them unavailable
2) will pick all UAV/UCAVs of Bravo that are already grounded and set them unavailable
I came up with this script:
-- Define the get_side function
function get_side(sides, name)
for _, side in pairs(sides) do
if string.lower(side.name) == string.lower(name) then
return side
end
end
end
-- Define the return_to_base function
function return_to_base(units)
for _, unit in pairs(units) do
if unit:get_speed() > 0 then
local base = unit:get_airbase()
if base ~= nil then
unit:set_available(false)
unit:task_return_to_base(base)
end
else
unit:set_available(false)
end
end
end
-- Find all UAVs and UCAVs of Side B
local sides = get_sides()
local side_b = get_side(sides, "Bravo")
local uavs = side_b:get_units({type = {"UAV", "UCAV"}})
-- Return all flying UAVs and UCAVs of Bravo to their bases and set them as unavailable
return_to_base(uavs)
-- Set all grounded UAVs and UCAVs of Bravo as unavailable
for _, unit in pairs(uavs) do
if unit:get_speed() == 0 then
unit:set_available(false)
end
end
But when I run this script in LUA script console it comes up this error:
ERROR: [string "Console"]:26: attempt to call a nil value (global 'get_sides').
How could I solve this?
1) will pick all flying UAV/UCAVs of Bravo side, return them to base and set them unavailable
2) will pick all UAV/UCAVs of Bravo that are already grounded and set them unavailable
I came up with this script:
-- Define the get_side function
function get_side(sides, name)
for _, side in pairs(sides) do
if string.lower(side.name) == string.lower(name) then
return side
end
end
end
-- Define the return_to_base function
function return_to_base(units)
for _, unit in pairs(units) do
if unit:get_speed() > 0 then
local base = unit:get_airbase()
if base ~= nil then
unit:set_available(false)
unit:task_return_to_base(base)
end
else
unit:set_available(false)
end
end
end
-- Find all UAVs and UCAVs of Side B
local sides = get_sides()
local side_b = get_side(sides, "Bravo")
local uavs = side_b:get_units({type = {"UAV", "UCAV"}})
-- Return all flying UAVs and UCAVs of Bravo to their bases and set them as unavailable
return_to_base(uavs)
-- Set all grounded UAVs and UCAVs of Bravo as unavailable
for _, unit in pairs(uavs) do
if unit:get_speed() == 0 then
unit:set_available(false)
end
end
But when I run this script in LUA script console it comes up this error:
ERROR: [string "Console"]:26: attempt to call a nil value (global 'get_sides').
How could I solve this?