1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-06 00:23:49 +02:00
ComfyFactorio/modules/spitters_spit_biters.lua

34 lines
1.1 KiB
Lua
Raw Normal View History

2019-02-16 18:36:12 +02:00
-- spitters spit biters, because why not -- by mewmew
2021-03-24 21:14:55 +02:00
local Event = require 'utils.event'
2019-02-16 18:36:12 +02:00
local radius = 3
local max_biters_in_radius = 3
local biters = {
2021-03-24 17:46:00 +02:00
['big-spitter'] = 'small-biter',
['behemoth-spitter'] = 'medium-biter'
}
2019-02-16 18:36:12 +02:00
local function on_entity_damaged(event)
2021-03-24 17:46:00 +02:00
if not event.cause then
return
end
if not event.cause.valid then
return
end
if not biters[event.cause.name] then
return
end
local area = {{event.entity.position.x - radius, event.entity.position.y - radius}, {event.entity.position.x + radius, event.entity.position.y + radius}}
if event.cause.surface.count_entities_filtered({area = area, name = biters[event.cause.name], limit = 3}) >= max_biters_in_radius then
return
end
local pos = event.cause.surface.find_non_colliding_position(biters[event.cause.name], event.entity.position, radius, 0.5)
if pos then
event.cause.surface.create_entity({name = biters[event.cause.name], position = pos})
end
2019-02-16 18:36:12 +02:00
end
2021-03-24 17:46:00 +02:00
2021-03-24 21:14:55 +02:00
Event.add(defines.events.on_entity_damaged, on_entity_damaged)