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

43 lines
1.2 KiB
Lua
Raw Normal View History

2019-08-13 10:33:14 +02:00
--moving players attract biters from far away
2021-03-24 21:14:55 +02:00
local Event = require 'utils.event'
2019-08-13 10:33:14 +02:00
local math_random = math.random
local function on_player_changed_position(event)
2021-03-24 17:46:00 +02:00
if math_random(1, 128) ~= 1 then
return
end
if game.tick - global.biters_attack_moving_players_last_action_tick < 7200 then
return
end
local player = game.players[event.player_index]
if not player.character then
return
end
local amount = math.floor(game.tick * 0.0005) + 1
if amount > 32 then
amount = 32
end
player.surface.set_multi_command(
{
command = {
type = defines.command.attack_area,
destination = player.position,
radius = 16,
distraction = defines.distraction.by_anything
},
unit_count = amount,
force = 'enemy',
unit_search_distance = 1024
}
)
global.biters_attack_moving_players_last_action_tick = game.tick
2019-08-13 10:33:14 +02:00
end
2021-03-24 21:14:55 +02:00
local function on_init()
2021-03-24 17:46:00 +02:00
global.biters_attack_moving_players_last_action_tick = 0
2019-08-13 10:33:14 +02:00
end
2021-03-24 21:14:55 +02:00
Event.add(defines.events.on_player_changed_position, on_player_changed_position)
Event.on_init(on_init)