From 9163433bc8dadb0212f3e271a399cf673e4b3e97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=BC=E5=A4=9C=E7=8B=8E=E6=98=B5?= <1046295287@qq.com> Date: Tue, 31 Dec 2024 17:14:55 +0800 Subject: [PATCH] **TODO:** - finish Range:activeTartgets() - add function Range:addTargetPreset(group/groupName,targetType) - add function Range:RemoveTargetPreset(group/groupName,targetType) --- Scripts/Localizations.lua | 4 ++ Scripts/Range.lua | 81 +++++++++++++++++++++++++++++++++++---- 2 files changed, 78 insertions(+), 7 deletions(-) diff --git a/Scripts/Localizations.lua b/Scripts/Localizations.lua index 51a7f30..4bc8107 100644 --- a/Scripts/Localizations.lua +++ b/Scripts/Localizations.lua @@ -41,6 +41,8 @@ Localizations = { --AutoRespawn ['Auto Respawn Targets: On'] = 'Auto Respawn Targets: On', ['Auto Respawn Targets: Off'] = 'Auto Respawn Targets: Off', + --Message + ['There is no range section of %s left.'] = 'There is no range section of %s left.', }, --中文 @@ -83,6 +85,8 @@ Localizations = { --AutoRespawn ['Auto Respawn Targets: On'] = '目标自动重生: 开', ['Auto Respawn Targets: Off'] = '目标自动重生: 关', + --Message + ['There is no range section of %s left.'] = '没有 %s 类型靶场空闲了.', } } diff --git a/Scripts/Range.lua b/Scripts/Range.lua index 70a734f..2e709ca 100644 --- a/Scripts/Range.lua +++ b/Scripts/Range.lua @@ -1,3 +1,12 @@ +--[[ + 24.13.31.1714 + TODO: + - finish Range:activeTartgets() + - add function Range:addTargetPreset(group/groupName,targetType) + - add function Range:RemoveTargetPreset(group/groupName,targetType) +]] + + Range = { MonitorRepeatTime = 5, --Seconds MonitorID = nil, @@ -27,6 +36,8 @@ Range = { -- TELE = 'Tele', }, + targetPresets = {}, + sections = {}, playerList = {}, @@ -201,8 +212,7 @@ do local FightBackSwitchName = Localizations:translate(string.format('Targets open fire: %s',switch),'cn') missionCommands.addCommandForGroup(groupID,FightBackSwitchName,SettingsMenu,function (vars) local self = vars.context - self.playerList[playerName].isTargerRedAlert = not self.playerList[playerName].isTargerRedAlert - self:createMenu(playerGroup) + self:setTargetFightBack(playerGroup) end,{context = self}) switch = 'Off' @@ -213,8 +223,7 @@ do local AutoRespawnSwitchName = Localizations:translate(string.format('Auto Respawn Targets: %s',switch),'cn') missionCommands.addCommandForGroup(groupID,AutoRespawnSwitchName,SettingsMenu,function (vars) local self = vars.context - self.playerList[playerName].autoRespawn = not self.playerList[playerName].autoRespawn - self:createMenu(playerGroup) + self:setTargetAutoRespawn(playerGroup) end,{context = self}) end @@ -237,6 +246,7 @@ do autoRespawn = false, isTargerRedAlert = false, activeTarget = nil, + targetData = {}, menu = nil, } self:createMenu(playerGroup) @@ -253,13 +263,46 @@ do self.playerList[PlayerName] = nil end - function Range:activeTartgets(section,targetType,AAType,Move) + function Range:activeTartgets(sectionType,targetType,AAType,Move) + if not sectionType then return end + if not targetType then return end + AAType = AAType or 'none' + Move = Move or false + + --Debug local isMove = 'Stationary' if Move then isMove = 'Moving' end - Utils.Debug('section:'..section..' targetType: '..' AAType: '..AAType..' Move: '..isMove) + Utils.Debug('section:'..sectionType..' targetType: '..' AAType: '..AAType..' Move: '..isMove) + + --Get sectionZone + local sectionZone = nil + for i=1,#self.sections[sectionType],1 do + local zoneNum = math.random(1,#self.sections[sectionType]) + if not self.sections[sectionType][zoneNum].active then + sectionZone = self.sections[sectionType][zoneNum] + self.sections[sectionType][zoneNum].active = true + end + end + + if not sectionZone then + for i=1,#self.sections[sectionType],1 do + if not self.sections[sectionType][i].active then + sectionZone = self.sections[sectionType][i] + self.sections[sectionType][i].active = true + end + end + end + + if not sectionZone then + trigger.action.outTextForGroup(string.format(Localizations:translate('There is no range section of %s left.','cn'),Localizations:translate(sectionType,'cn'))) + return + end + + --Get target types + end function Range:deactivateTargets(PlayerName) @@ -277,8 +320,32 @@ do if not playerUnit then return end if not playerUnit:isActive() then return end + local playerName = playerUnit:getPlayerName() + if not playerName then return end + + self.playerList[playerName].isTargerRedAlert = not self.playerList[playerName].isTargerRedAlert + if self.playerList[playerName].activeTarget then + local Controller = self.playerList[playerName].activeTarget:getController() + if Controller then + Controller:setOption(AI.Option.Ground.id.ROE,AI.Option.Ground.val.ROE.WEAPON_HOLD) + Controller:setOption(AI.Option.Ground.id.ALARM_STATE,AI.Option.Ground.val.ALARM_STATE.GREEN) + end + end + + self:createMenu(playerGroup) + end + + function Range:setTargetAutoRespawn(playerGroup) + if not playerGroup then return end - + local playerUnit = playerGroup:getUnit(1) + if not playerUnit then return end + if not playerUnit:isActive() then return end + + local playerName = playerUnit:getPlayerName() + if not playerName then return end + + self.playerList[playerName].autoRespawn = not self.playerList[playerName].autoRespawn self:createMenu(playerGroup) end