Files
Buta-018-EagleHunt/Scripts/misc.lua
T
XiaoChen 511a852c4d Add miscellaneous scripts:
- add red alarm event
- add Power Station event(not done)
2025-03-31 22:59:08 +08:00

106 lines
3.5 KiB
Lua

-- 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