1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-06 00:23:49 +02:00
ComfyFactorio/modules/nuclear_landmines.lua
2021-03-24 16:46:00 +01:00

28 lines
784 B
Lua

local math_random = math.random
local function detonate_nuke(entity)
local surface = entity.surface
surface.create_entity({name = 'atomic-rocket', position = entity.position, force = entity.force, speed = 1, max_range = 800, target = entity, source = entity})
end
local function on_entity_died(event)
local entity = event.entity
if not entity.valid then
return
end
if entity.name == 'land-mine' then
if math_random(1, global.nuclear_landmines.chance) == 1 then
detonate_nuke(entity)
end
end
end
local function on_init()
global.nuclear_landmines = {}
global.nuclear_landmines.chance = 512
end
local Event = require 'utils.event'
Event.on_init(on_init)
Event.add(defines.events.on_entity_died, on_entity_died)