-- ============================================================
-- BAYRAKTAR TB2 - QUADCOPTER CONTROL PANEL
-- COMMAND: MODERN OPERATIONS 1900.24
-- SINGLE SPECIAL ACTION / MANUAL SELECTION
-- ============================================================
local TB2_GUID = "CWVLA7-0HNPS0BABCMVU"
local ACTION_NAME = "TB2 QUADCOPTER CONTROL PANEL"
local mother = ScenEdit_GetUnit({guid = TB2_GUID})
if not mother then
print("ERROR: BAYRAKTAR TB2 NOT FOUND")
return
end
-- ============================================================
-- PANEL SCRIPT
-- ============================================================
local PANEL_SCRIPT = [==[
local TB2_GUID = "CWVLA7-0HNPS0BABCMVU"
local ACTION_NAME = "TB2 QUADCOPTER CONTROL PANEL"
local DRONE_DBID = 5416
local DRONE_LOADOUT = 29923
local MAX_DRONES = 4
local MOUNT_ID = 1194
local WEAPON_ID = 1305
local WEAPON_QTY = 1
local REMOVE_WEAPON_ID = 551
local mother = ScenEdit_GetUnit({guid = TB2_GUID})
if not mother then
ScenEdit_MsgBox("BAYRAKTAR TB2 NOT FOUND", 0)
return
end
-- ============================================================
-- STATUS
-- ============================================================
local function GetDroneStatus(number)
local stored = ScenEdit_GetKeyValue(
"TB2_QUADCOPTER_" .. number
)
if stored == "LAUNCHED" then
return "DEPLOYED"
end
if stored == "CHECK" then
return "CHECK REQUIRED"
end
local existing = ScenEdit_GetUnit({
side = mother.side,
name = "TB2 Quadcopter " .. number
})
if existing then
return "EXISTING UNIT"
end
return "READY"
end
-- ============================================================
-- HTML INTERFACE
-- ============================================================
local function BuildPanel()
local deployed = 0
local available = 0
local rows = ""
local firstReady = nil
for i = 1, MAX_DRONES do
local status = GetDroneStatus(i)
local color = "#55df91"
local disabled = ""
if status == "DEPLOYED" then
color = "#42b7df"
deployed = deployed + 1
disabled = " disabled"
elseif status == "CHECK REQUIRED" then
color = "#ffb347"
disabled = " disabled"
elseif status == "EXISTING UNIT" then
color = "#ffb347"
disabled = " disabled"
else
available = available + 1
if not firstReady then
firstReady = i
end
end
local checked = ""
if firstReady == i then
checked = " checked"
end
rows = rows .. [[
0]] .. i .. [[
QUADCOPTER ]] .. i .. [[
TB2 AUTONOMOUS AIR UNIT
● ]] .. status .. [[
]]
end
return [[
TB2 / COMMAND
BAYRAKTAR TB2 - QUADCOPTER MANAGEMENT
● SYSTEM ONLINE
]] ..
available .. [[
AVAILABLE
]] ..
deployed .. [[
DEPLOYED
AIR UNIT MANAGEMENT / SELECT UNIT
]]
end
-- ============================================================
-- DEPLOYMENT FUNCTION
-- ============================================================
local function LaunchQuadcopter(number)
if number < 1 or number > MAX_DRONES then
return false, "INVALID UNIT SELECTION"
end
if GetDroneStatus(number) ~= "READY" then
return false, "UNIT IS NOT AVAILABLE"
end
local drone = ScenEdit_AddUnit({
type = "Air",
unitname = "TB2 Quadcopter " .. number,
side = mother.side,
dbid = DRONE_DBID,
loadoutid = DRONE_LOADOUT,
latitude = mother.latitude,
longitude = mother.longitude,
altitude = mother.altitude
})
if not drone then
return false, "DRONE CREATION FAILED"
end
print("DRONE CREATED: " .. tostring(drone.name))
print("DRONE GUID: " .. tostring(drone.guid))
ScenEdit_SetKeyValue(
"TB2_QUADCOPTER_" .. number,
"CHECK"
)
local mount_added = ScenEdit_UpdateUnit({
guid = drone.guid,
mode = "add_mount",
dbid = MOUNT_ID,
arc_mount = {"360"}
})
if not mount_added then
return false, "MOUNT CREATION FAILED"
end
local updated = ScenEdit_GetUnit({
guid = drone.guid
})
local mount_guid = nil
if updated and updated.mounts then
for _, m in ipairs(updated.mounts) do
if m.mount_dbid == MOUNT_ID then
mount_guid = m.mount_guid
break
end
end
end
if not mount_guid then
return false, "MOUNT GUID NOT FOUND"
end
local weapon_added = ScenEdit_UpdateUnit({
guid = drone.guid,
mode = "add_weapon",
mountid = mount_guid,
dbid = WEAPON_ID
})
if not weapon_added then
return false, "WEAPON 1305 ADDITION FAILED"
end
ScenEdit_AddReloadsToUnit({
side = mother.side,
guid = drone.guid,
mount_guid = mount_guid,
wpn_dbid = WEAPON_ID,
number = WEAPON_QTY
})
updated = ScenEdit_GetUnit({
guid = drone.guid
})
local weapon_551_guid = nil
if updated and updated.mounts then
for _, m in ipairs(updated.mounts) do
if m.mount_guid == mount_guid and m.mount_weapons then
for _, w in ipairs(m.mount_weapons) do
if w.wpn_dbid == REMOVE_WEAPON_ID then
weapon_551_guid = w.wpn_guid
end
end
end
end
end
if weapon_551_guid then
local removed = ScenEdit_UpdateUnit({
guid = drone.guid,
mode = "remove_weapon",
dbid = REMOVE_WEAPON_ID,
mountid = mount_guid,
weaponid = weapon_551_guid
})
if not removed then
return false, "WEAPON 551 REMOVAL FAILED"
end
end
updated = ScenEdit_GetUnit({
guid = drone.guid
})
local weapon_1305_found = false
local weapon_551_found = false
if updated and updated.mounts then
for _, m in ipairs(updated.mounts) do
if m.mount_guid == mount_guid and m.mount_weapons then
for _, w in ipairs(m.mount_weapons) do
if w.wpn_dbid == WEAPON_ID then
weapon_1305_found = true
end
if w.wpn_dbid == REMOVE_WEAPON_ID then
weapon_551_found = true
end
end
end
end
end
if weapon_1305_found and not weapon_551_found then
ScenEdit_SetKeyValue(
"TB2_QUADCOPTER_" .. number,
"LAUNCHED"
)
return true, "QUADCOPTER " .. number .. " DEPLOYED"
end
return false, "FINAL WEAPON VERIFICATION FAILED"
end
-- ============================================================
-- MAIN INTERFACE LOOP
-- ============================================================
while true do
local result = UI_CallAdvancedHTMLDialog(
"TB2 QUADCOPTER CONTROL PANEL",
BuildPanel(),
{
"LAUNCH SELECTED",
"REFRESH STATUS",
"CLOSE PANEL"
}
)
if not result then
break
end
if result.pressed == "CLOSE PANEL" then
break
elseif result.pressed == "REFRESH STATUS" then
-- Rebuild panel.
elseif result.pressed == "LAUNCH SELECTED" then
local number = tonumber(result.drone or "")
if not number then
ScenEdit_MsgBox(
"PLEASE SELECT AN AIR UNIT.",
0
)
else
local success, message =
LaunchQuadcopter(number)
print("DEPLOYMENT RESULT: " .. tostring(success))
print("DETAILS: " .. tostring(message))
ScenEdit_MsgBox(message, 0)
end
end
end
print("TB2 CONTROL PANEL CLOSED")
]==]
-- ============================================================
-- CREATE ONE SPECIAL ACTION
-- ============================================================
PANEL_SCRIPT = PANEL_SCRIPT:gsub("\n", "\r\n")
local created = ScenEdit_AddSpecialAction({
side = mother.side,
ActionNameOrID = ACTION_NAME,
description = "TB2 Quadcopter Operator Control Panel",
IsActive = "True",
IsRepeatable = "True",
ScriptText = PANEL_SCRIPT
})
if created then
print("======================================")
print("TB2 CONTROL PANEL CREATED")
print("SPECIAL ACTION: " .. ACTION_NAME)
print("QUADCOPTERS: 4")
print("MODE: MANUAL SELECTION")
print("======================================")
else
print("ERROR: SPECIAL ACTION CREATION FAILED")
end