Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scripting request: SAMs in Range 24 #34

Open
132ndNeck opened this issue Aug 1, 2024 · 5 comments
Open

Scripting request: SAMs in Range 24 #34

132ndNeck opened this issue Aug 1, 2024 · 5 comments

Comments

@132ndNeck
Copy link
Collaborator

@132nd-Entropy
Would it be possible to script the following for range 24:

Static locations:
Following static SAMs are in the .miz as late activation, and I request to add a F10 menu to activate and deactivate each site (when activated, you have the option to deactivate it):
R24_SA-10 site_static
R24_SA-2_site_static
R24_SA-6_site_static

Mobile SAMs:
The following SAMs are in the .miz as late activation and I request to add a F-10 menu to activate and deactive each site (when activated, you have the option to deactivate it). This are mobile SAMs and I want the SAM to appear in a random location within the zone marked by the late activation aircraft with waypoints labeled with the name in parenthesis behind the SAM name.
R24_SA-8_mobile (R24_SA-8_mobile_random_zone)
R24_SA-19_mobile (R24_SA-19_mobile_random_zone)
R24_SA-15_mobile (R24_SA-15_mobile_random_zone)
R24_SA-11_mobile (R24_SA-11_mobile_random_zone_1, R24_SA-11_mobile_random_zone_2, R24_SA-11_mobile_random_zone_3, R24_SA-11_mobile_random_zone_4)

@132ndNeck
Copy link
Collaborator Author

In addition to the above, I have created a target at the center for all mobile SAMs (for trainings to have something to shoot at). This is a Rocket artillery battalion. And I request to include scripting to activate these and deactive these as the mobile SAMs are deactivted. All rockety artillery BN units is set to late activation.

The four groups that correspond to the mobile SAM in the post above is named:
R24_rocket_arty_BN_SA8
R24_rocket_arty_BN_SA19
R24_rocket_arty_BN_SA15
R24_rocket_arty_BN_SA11

@132ndNeck
Copy link
Collaborator Author

132ndNeck commented Aug 2, 2024

In addition to the above, I have created a IADS in the same range that also can be activated.

Step 1: The following units need to be activated via F10 menu:
R24_IADS_Army_SBORKA
R24_IADS_Army_SA_15_BN
R24_IADS_Army_SA_8_BN
R24_rocket_arty_BN_IADS

Step 2: In addition, flag 21 need to be set to true when the units above are activated, as it will activate the IADS for the units listed above

@132ndNeck
Copy link
Collaborator Author

@132nd-Entropy
Note: As with range 16, I will set the units to late activated and hidden on map after the script is created. So all units is visible in the F10 map for now.

@132ndNeck
Copy link
Collaborator Author

132ndNeck commented Dec 9, 2024

@132nd-Entropy
I got help from ChatGPT, and it gave me this script. I have put it into the .miz and it seem to work.
If you get a chance, please have a look and see if something does not look right or it creates any errors:


-- Assumes MIST and MOOSE are already loaded!
-- This script integrates the requested functionality into
-- the "Range 24" submenu under "RANGES 19-24".

-- Create the Range 24 menu under RANGES 19-24 (assuming it exists)
-- Example:
-- range_root_menu = MENU_MISSION:New("Ranges")
-- range_root_menu19_24 = MENU_MISSION:New("RANGES 19-24", range_root_menu)
-- This script should run after the above is set.

local range_24_menu_root = MENU_MISSION:New("Range 24", range_root_menu19_24)


-- Utility Functions

local function activateGroup(groupName)
local grp = Group.getByName(groupName)
if not grp or not grp:isExist() then
mist.respawnGroup(groupName, true)
else
mist.respawnGroup(groupName, true)
end
end

local function deactivateGroup(groupName)
local grp = Group.getByName(groupName)
if grp and grp:isExist() then
grp:destroy()
end
end

local function sendMessage(msg, duration)
MESSAGE:New(msg, duration):ToAll()
end

-- Function to activate/deactivate mobile SAMs and their artillery.
-- samName: string - the name of the SAM group
-- artyName: string - the name of the associated artillery group
-- zonesTable: table - a list of one or more zone names for random placement
local function activateMobileSAM(samName, artyName, zonesTable)
local zoneName
if #zonesTable > 1 then
zoneName = zonesTable[math.random(#zonesTable)]
else
zoneName = zonesTable[1]
end

mist.respawnGroup(samName, true)

local zData = trigger.misc.getZone(zoneName)
if zData then
    local point = mist.getRandPointInCircle(zData.point, zData.radius)
    mist.teleportToPoint({
        groupName = samName,
        point = point,
        action = "teleport"
    })
end

mist.respawnGroup(artyName, true)
sendMessage(samName .. " (and associated artillery) Activated!", 5)

end

local function deactivateMobileSAM(samName, artyName)
deactivateGroup(samName)
deactivateGroup(artyName)
sendMessage(samName .. " and associated artillery Deactivated!", 5)
end

local function activateStaticSAM(samName)
activateGroup(samName)
sendMessage(samName .. " Activated!", 5)
end

local function deactivateStaticSAM(samName)
deactivateGroup(samName)
sendMessage(samName .. " Deactivated!", 5)
end


-- Part 1: Static SAM Activation/Deactivation

local staticSAMs = {
"R24_SA-10 site_static",
"R24_SA-2_site_static",
"R24_SA-6_site_static"
}

local range_24_static_sam_menu = MENU_MISSION:New("Static SAM Control", range_24_menu_root)

for _, samName in ipairs(staticSAMs) do
local samMenu = MENU_MISSION:New(samName, range_24_static_sam_menu)
MENU_MISSION_COMMAND:New("Activate " .. samName, samMenu, activateStaticSAM, samName)
MENU_MISSION_COMMAND:New("Deactivate " .. samName, samMenu, deactivateStaticSAM, samName)
end


-- Part 2 & 3: Mobile SAMs and associated artillery

local mobileSAMs = {
{
samName = "R24_SA-8_mobile",
artyName = "R24_rocket_arty_BN_SA8",
zones = {"R24_SA-8_mobile_random_zone"}
},
{
samName = "R24_SA-19_mobile",
artyName = "R24_rocket_arty_BN_SA19",
zones = {"R24_SA-19_mobile_random_zone"}
},
{
samName = "R24_SA-15_mobile",
artyName = "R24_rocket_arty_BN_SA15",
zones = {"R24_SA-15_mobile_random_zone"}
},
{
samName = "R24_SA-11_mobile",
artyName = "R24_rocket_arty_BN_SA11",
zones = {
"R24_SA-11_mobile_random_zone_1",
"R24_SA-11_mobile_random_zone_2",
"R24_SA-11_mobile_random_zone_3",
"R24_SA-11_mobile_random_zone_4"
}
}
}

local range_24_mobile_sam_menu = MENU_MISSION:New("Mobile SAM Control", range_24_menu_root)

for _, samData in ipairs(mobileSAMs) do
local samMenu = MENU_MISSION:New(samData.samName, range_24_mobile_sam_menu)
MENU_MISSION_COMMAND:New("Activate " .. samData.samName, samMenu, activateMobileSAM, samData.samName, samData.artyName, samData.zones)
MENU_MISSION_COMMAND:New("Deactivate " .. samData.samName, samMenu, deactivateMobileSAM, samData.samName, samData.artyName)
end


-- Part 4: IADS

local iadsGroups = {
"R24_IADS_Army_SBORKA",
"R24_IADS_Army_SA_15_BN",
"R24_IADS_Army_SA_8_BN",
"R24_rocket_arty_BN_IADS"
}

local function activateIADS()
for _, gName in ipairs(iadsGroups) do
activateGroup(gName)
end
trigger.action.setUserFlag("21", 1)
sendMessage("IADS Activated", 5)
end

local function deactivateIADS()
for _, gName in ipairs(iadsGroups) do
deactivateGroup(gName)
end
trigger.action.setUserFlag("21", 0)
sendMessage("IADS Deactivated", 5)
end

local range_24_iads_menu = MENU_MISSION:New("IADS Control", range_24_menu_root)
MENU_MISSION_COMMAND:New("Activate IADS", range_24_iads_menu, activateIADS)
MENU_MISSION_COMMAND:New("Deactivate IADS", range_24_iads_menu, deactivateIADS)


-- The entire functionality is now integrated under "Range 24"
-- within the "RANGES 19-24" menu.

@132nd-Entropy
Copy link
Contributor

132nd-Entropy commented Dec 10, 2024

hey @132ndNeck Im terribly behind on everything since the semester started. If it works and you dont get errors in the DCS log (I use the free app logExpert to let the run run in the background) then it will be ok. The only thing, you could ask chatGPT to rewrite it to use the MOOSE framework instead of MIST so it would be more in compliance with all the other scripts, but at this point I guess thats just a cosmetic change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants