1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2024-12-30 23:17:53 +02:00
ComfyFactorio/modules/teleporting_worms.lua
2021-03-24 20:14:55 +01:00

32 lines
1.0 KiB
Lua

-- worms will teleport to where they shoot -- by mewmew
local Event = require 'utils.event'
local function on_entity_damaged(event)
if not event.cause then
return
end
local cause = event.cause
if cause.type ~= 'turret' then
return
end
if cause.health <= 0 then
return
end
local new_position = {
x = (cause.position.x + event.entity.position.x) * 0.5,
y = (cause.position.y + event.entity.position.y) * 0.5
}
new_position = {
x = (cause.position.x + new_position.x) * 0.5,
y = (cause.position.y + new_position.y) * 0.5
}
local new_turret = cause.surface.create_entity({name = cause.name, force = cause.force, position = new_position})
cause.surface.create_entity({name = 'blood-explosion-big', position = new_position})
cause.surface.create_entity({name = 'blood-explosion-big', position = cause.position})
new_turret.health = cause.health
cause.destroy()
end
Event.add(defines.events.on_entity_damaged, on_entity_damaged)