From 511a852c4db0a02242ff02026aecd9cc93c2be1d Mon Sep 17 00:00:00 2001 From: Butata <1046295287@qq.com> Date: Mon, 31 Mar 2025 22:59:08 +0800 Subject: [PATCH] Add miscellaneous scripts: - add red alarm event - add Power Station event(not done) --- Scripts/misc.lua | 106 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 Scripts/misc.lua diff --git a/Scripts/misc.lua b/Scripts/misc.lua new file mode 100644 index 0000000..ef3c79e --- /dev/null +++ b/Scripts/misc.lua @@ -0,0 +1,106 @@ +-- hanle miscellaneous mission events + +--Red alarm when under attack +do + local redAlarmEvent = { + redAlarm = false, + ignoreList = { + ['Red-RescueInf-1'] = true, + ['Red-Scud'] = true, + ['Red-Scud'] = true, + } + } + + function redAlarmEvent:redAlarm_On() + Utils.Debug('==================\n\n敌人因为受到攻击, 拉响了警报!\n\n==================') + + self.redAlarm = true + local redGrounds = coalition.getGroups(1,Group.Category.GROUND) + + for i, group in ipairs(redGrounds) do + local groupIsActivate = true + for i,unit in ipairs(group:getUnits()) do + if not unit:isActive() then + groupIsActivate = false + end + end + + if not groupIsActivate and not redAlarmEvent.ignoreList[group:getName()] then + + Utils.Debug('Activate: '..group:getName()) + timer.scheduleFunction(function (group) + group:activate() + Utils.Debug('Activated: '..group:getName()) + end,group,timer.getTime()+math.random(120,600)) + + end + + end + end + + function redAlarmEvent:onEvent(event) + if not self.redAlarm then + if event.id == world.event.S_EVENT_HIT or event.id == world.event.S_EVENT_KILL or event.id == world.event.S_EVENT_DEAD then + local object = event.initiator + if not object:getCoalition() == 1 then return end + Utils.Debug('redAlarmEvent') + + local objectCategory, unitCategory = Unit.getCategory(object) + if objectCategory == Object.Category.UNIT then + if unitCategory == Unit.Category.GROUND_UNIT or unitCategory == Unit.Category.STRUCTURE then + Utils.Debug('call redAlarm_On') + self:redAlarm_On() + world.removeEventHandler(redAlarmEvent) + end + end + + if objectCategory == Object.Category.STATIC then + if object:getName() == 'Red-PowerStation-1' then return end + Utils.Debug('call redAlarm_On') + self:redAlarm_On() + world.removeEventHandler(redAlarmEvent) + end + end + end + end + + world.addEventHandler(redAlarmEvent) +end + +-- Power Station +do + local PowerStationEvent = { + connectedUnitList = { + 'Red-EWR-CRAM-1', + 'Red-CWStorage-CRAM-1', + 'Red-SAMSite-CRAM-1', + 'Red-EWR-1', + 'Red-Rescue-SAM-1', + }, + replaceStatics = { + ['Static M92 Container watchtower lights-1'] = { + ori = 'Container_watchtower_lights', + replace = 'Container_watchtower', + }, + ['Static M92 NF-2 LightOn-1'] = { + ori = 'NF-2 LightOn', + replace = 'NF-2 LightOff 01', + }, + } + + } + function PowerStationEvent:onEvent(event) + if event.id == world.event.S_EVENT_KILL or event.id == world.event.S_EVENT_DEAD then + local object = event.initiator + + local objectCategory, unitCategory = Unit.getCategory(object) + if objectCategory == Object.Category.STATIC then + if object:getName() == 'Red-PowerStation-1' then return end + + world.removeEventHandler(PowerStationEvent) + end + end + end + + world.addEventHandler(PowerStationEvent) +end \ No newline at end of file