mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
Feature Update (#237)
See PR for details, there are too many to be included here.
This commit is contained in:
@@ -27,6 +27,14 @@ Event.add(defines.events.on_player_created, function(event)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if config.armor.enable then
|
||||
player.insert{name=config.armor.main, count=1}
|
||||
|
||||
for _, item in pairs(config.armor.item) do
|
||||
player.insert{name=item.equipment, count=item.count}
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
Event.on_init(function()
|
||||
|
||||
@@ -70,9 +70,11 @@ function Public.add_compilatron(entity, name)
|
||||
if not entity and not entity.valid then
|
||||
return
|
||||
end
|
||||
|
||||
if name == nil then
|
||||
return
|
||||
end
|
||||
|
||||
Public.compilatrons[name] = entity
|
||||
local message =
|
||||
entity.surface.create_entity(
|
||||
@@ -95,6 +97,7 @@ end
|
||||
Event.add(defines.events.on_player_created, function(event)
|
||||
if event.player_index ~= 1 then return end
|
||||
local player = game.players[event.player_index]
|
||||
|
||||
for location in pairs(locations) do
|
||||
Public.spawn_compilatron(player.surface, location)
|
||||
end
|
||||
|
||||
@@ -11,13 +11,28 @@ local filepath = "log/decon.log"
|
||||
local function add_log(data)
|
||||
game.write_file(filepath, data .. "\n", true, 0) -- write data
|
||||
end
|
||||
local function get_secs ()
|
||||
|
||||
local function get_secs()
|
||||
return format_time(game.tick, { hours = true, minutes = true, seconds = true, string = true })
|
||||
end
|
||||
local function pos_tostring (pos)
|
||||
|
||||
local function pos_to_string(pos)
|
||||
return tostring(pos.x) .. "," .. tostring(pos.y)
|
||||
end
|
||||
|
||||
local function pos_to_gps_string(pos)
|
||||
return '[gps=' .. tostring(pos.x) .. ',' .. tostring(pos.y) .. ']'
|
||||
end
|
||||
|
||||
--- Print a message to all players who match the value of admin
|
||||
local function print_to_players(admin, message)
|
||||
for _, player in ipairs(game.connected_players) do
|
||||
if player.admin == admin then
|
||||
player.print(message)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Event.on_init(function()
|
||||
game.write_file(filepath, "\n", false, 0) -- write data
|
||||
end)
|
||||
@@ -25,8 +40,17 @@ end)
|
||||
if config.decon_area then
|
||||
Event.add(defines.events.on_player_deconstructed_area, function (e)
|
||||
local player = game.get_player(e.player_index)
|
||||
if Roles.player_has_flag(player, "deconlog-bypass") then return end
|
||||
add_log(get_secs() .. "," .. player.name .. ",decon_area," .. pos_tostring(e.area.left_top) .. "," .. pos_tostring(e.area.right_bottom))
|
||||
if Roles.player_has_flag(player, "deconlog-bypass") then
|
||||
return
|
||||
end
|
||||
|
||||
local items = e.surface.find_entities_filtered{area=e.area, force=player.force}
|
||||
|
||||
if #items > 250 then
|
||||
print_to_players(true, player.name .. ' tried to deconstruct the area ' .. pos_to_gps_string(e.area.left_top) .. ' to ' .. pos_to_gps_string(e.area.right_bottom) .. ' that have ' .. #items .. ' items, but were not allowed.')
|
||||
end
|
||||
|
||||
add_log(get_secs() .. "," .. player.name .. ",decon_area," .. pos_to_string(e.area.left_top) .. "," .. pos_to_string(e.area.right_bottom))
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -34,30 +58,38 @@ if config.built_entity then
|
||||
Event.add(defines.events.on_built_entity, function (e)
|
||||
if not e.player_index then return end
|
||||
local player = game.get_player(e.player_index)
|
||||
if Roles.player_has_flag(player, "deconlog-bypass") then return end
|
||||
if Roles.player_has_flag(player, "deconlog-bypass") then
|
||||
return
|
||||
end
|
||||
local ent = e.created_entity
|
||||
add_log(get_secs() .. "," .. player.name .. ",built_entity," .. ent.name .. "," .. pos_tostring(ent.position) .. "," .. tostring(ent.direction) .. "," .. tostring(ent.orientation))
|
||||
add_log(get_secs() .. "," .. player.name .. ",built_entity," .. ent.name .. "," .. pos_to_string(ent.position) .. "," .. tostring(ent.direction) .. "," .. tostring(ent.orientation))
|
||||
end)
|
||||
end
|
||||
|
||||
if config.mined_entity then
|
||||
Event.add(defines.events.on_player_mined_entity, function (e)
|
||||
local player = game.get_player(e.player_index)
|
||||
if Roles.player_has_flag(player, "deconlog-bypass") then return end
|
||||
if Roles.player_has_flag(player, "deconlog-bypass") then
|
||||
return
|
||||
end
|
||||
local ent = e.entity
|
||||
add_log(get_secs() .. "," .. player.name .. ",mined_entity," .. ent.name .. "," .. pos_tostring(ent.position) .. "," .. tostring(ent.direction) .. "," .. tostring(ent.orientation))
|
||||
add_log(get_secs() .. "," .. player.name .. ",mined_entity," .. ent.name .. "," .. pos_to_string(ent.position) .. "," .. tostring(ent.direction) .. "," .. tostring(ent.orientation))
|
||||
end)
|
||||
end
|
||||
|
||||
if config.fired_rocket then
|
||||
Event.add(defines.events.on_player_ammo_inventory_changed, function (e)
|
||||
local player = game.get_player(e.player_index)
|
||||
if Roles.player_has_flag(player, "deconlog-bypass") then return end
|
||||
if Roles.player_has_flag(player, "deconlog-bypass") then
|
||||
return
|
||||
end
|
||||
local ammo_inv = player.get_inventory(defines.inventory.character_ammo)
|
||||
local item = ammo_inv[player.character.selected_gun_index]
|
||||
if not item or not item.valid or not item.valid_for_read then return end
|
||||
if not item or not item.valid or not item.valid_for_read then
|
||||
return
|
||||
end
|
||||
if item.name == "rocket" then
|
||||
add_log(get_secs() .. "," .. player.name .. ",shot-rocket," .. pos_tostring(player.position) .. "," .. pos_tostring(player.shooting_state.position))
|
||||
add_log(get_secs() .. "," .. player.name .. ",shot-rocket," .. pos_to_string(player.position) .. "," .. pos_to_string(player.shooting_state.position))
|
||||
end
|
||||
end)
|
||||
end
|
||||
@@ -65,12 +97,18 @@ end
|
||||
if config.fired_explosive_rocket then
|
||||
Event.add(defines.events.on_player_ammo_inventory_changed, function (e)
|
||||
local player = game.get_player(e.player_index)
|
||||
if Roles.player_has_flag(player, "deconlog-bypass") then return end
|
||||
|
||||
if Roles.player_has_flag(player, "deconlog-bypass") then
|
||||
return
|
||||
end
|
||||
local ammo_inv = player.get_inventory(defines.inventory.character_ammo)
|
||||
local item = ammo_inv[player.character.selected_gun_index]
|
||||
if not item or not item.valid or not item.valid_for_read then return end
|
||||
|
||||
if not item or not item.valid or not item.valid_for_read then
|
||||
return
|
||||
end
|
||||
if item.name == "explosive-rocket" then
|
||||
add_log(get_secs() .. "," .. player.name .. ",shot-explosive-rocket," .. pos_tostring(player.position) .. "," .. pos_tostring(player.shooting_state.position))
|
||||
add_log(get_secs() .. "," .. player.name .. ",shot-explosive-rocket," .. pos_to_string(player.position) .. "," .. pos_to_string(player.shooting_state.position))
|
||||
end
|
||||
end)
|
||||
end
|
||||
@@ -78,12 +116,20 @@ end
|
||||
if config.fired_nuke then
|
||||
Event.add(defines.events.on_player_ammo_inventory_changed, function (e)
|
||||
local player = game.get_player(e.player_index)
|
||||
if Roles.player_has_flag(player, "deconlog-bypass") then return end
|
||||
|
||||
if Roles.player_has_flag(player, "deconlog-bypass") then
|
||||
return
|
||||
end
|
||||
|
||||
local ammo_inv = player.get_inventory(defines.inventory.character_ammo)
|
||||
local item = ammo_inv[player.character.selected_gun_index]
|
||||
if not item or not item.valid or not item.valid_for_read then return end
|
||||
|
||||
if not item or not item.valid or not item.valid_for_read then
|
||||
return
|
||||
end
|
||||
|
||||
if item.name == "atomic-bomb" then
|
||||
add_log(get_secs() .. "," .. player.name .. ",shot-nuke," .. pos_tostring(player.position) .. "," .. pos_tostring(player.shooting_state.position))
|
||||
add_log(get_secs() .. "," .. player.name .. ",shot-nuke," .. pos_to_string(player.position) .. "," .. pos_to_string(player.shooting_state.position))
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -6,12 +6,20 @@ local Colors = require 'utils.color_presets' --- @dep utils.color_presets
|
||||
local write_json, format_time = _C.write_json, _C.format_time --- @dep expcore.common
|
||||
local config = require 'config.discord_alerts' --- @dep config.discord_alerts
|
||||
|
||||
local playtime_format = { short = true, hours = true, minutes = true, string = true }
|
||||
local playtime_format = {hours = true, minutes = true, short = true, string = true}
|
||||
|
||||
local function append_playtime(player_name)
|
||||
if not config.show_playtime then return player_name end
|
||||
if not config.show_playtime then
|
||||
return player_name
|
||||
end
|
||||
|
||||
local player = game.get_player(player_name)
|
||||
if not player then return player_name end
|
||||
return player.name..' ('..format_time(player.online_time, playtime_format)..')'
|
||||
|
||||
if not player then
|
||||
return player_name
|
||||
end
|
||||
|
||||
return player.name ..' (' .. format_time(player.online_time, playtime_format) .. ')'
|
||||
end
|
||||
|
||||
local function get_player_name(event)
|
||||
@@ -24,10 +32,10 @@ local function to_hex(color)
|
||||
local function hex(bit)
|
||||
local major, minor = math.modf(bit/16)
|
||||
major, minor = major+1, minor*16+1
|
||||
return hex_digits:sub(major, major)..hex_digits:sub(minor, minor)
|
||||
return hex_digits:sub(major, major) .. hex_digits:sub(minor, minor)
|
||||
end
|
||||
|
||||
return '0x'..hex(color.r)..hex(color.g)..hex(color.b)
|
||||
return '0x' .. hex(color.r) .. hex(color.g) .. hex(color.b)
|
||||
end
|
||||
|
||||
local function emit_event(args)
|
||||
@@ -40,12 +48,14 @@ local function emit_event(args)
|
||||
end
|
||||
|
||||
local tick = args.tick or game.tick
|
||||
local tick_formatted = format_time(tick, {days = true, hours = true, minutes = true, string = true, long = true})
|
||||
local tick_formatted = format_time(tick, {days = false, hours = true, minutes = true, short = true, string = true})
|
||||
|
||||
local players_online = 0
|
||||
local admins_online = 0
|
||||
|
||||
for _, player in pairs(game.connected_players) do
|
||||
players_online = players_online+1
|
||||
players_online = players_online + 1
|
||||
|
||||
if player.admin then
|
||||
admins_online = admins_online + 1
|
||||
end
|
||||
@@ -93,8 +103,9 @@ if config.entity_protection then
|
||||
title='Entity Protection',
|
||||
description='A player removed protected entities',
|
||||
color=Colors.yellow,
|
||||
['Player']='<inline>'..append_playtime(player_name),
|
||||
['Entity']='<inline>'..event.entity.name
|
||||
['Player']='<inline>' .. append_playtime(player_name),
|
||||
['Entity']='<inline>' .. event.entity.name,
|
||||
['Location']=event.entity.position
|
||||
}
|
||||
end)
|
||||
end
|
||||
@@ -108,9 +119,9 @@ if config.player_reports then
|
||||
title='Report',
|
||||
description='A player was reported',
|
||||
color=Colors.yellow,
|
||||
['Player']='<inline>'..append_playtime(player_name),
|
||||
['By']='<inline>'..append_playtime(by_player_name),
|
||||
['Report Count']='<inline>'..Reports.count_reports(player_name),
|
||||
['Player']='<inline>' .. append_playtime(player_name),
|
||||
['By']='<inline>' .. append_playtime(by_player_name),
|
||||
['Report Count']='<inline>' .. Reports.count_reports(player_name),
|
||||
['Reason']=event.reason
|
||||
}
|
||||
end)
|
||||
@@ -121,9 +132,9 @@ if config.player_reports then
|
||||
title='Reports Removed',
|
||||
description='A player has a report removed',
|
||||
color=Colors.green,
|
||||
['Player']='<inline>'..player_name,
|
||||
['By']='<inline>'..event.removed_by_name,
|
||||
['Report Count']='<inline>'..event.batch_count
|
||||
['Player']='<inline>' .. player_name,
|
||||
['By']='<inline>' .. event.removed_by_name,
|
||||
['Report Count']='<inline>' .. event.batch_count
|
||||
}
|
||||
end)
|
||||
end
|
||||
@@ -138,9 +149,9 @@ if config.player_warnings then
|
||||
title='Warning',
|
||||
description='A player has been given a warning',
|
||||
color=Colors.yellow,
|
||||
['Player']='<inline>'..player_name,
|
||||
['By']='<inline>'..by_player_name,
|
||||
['Warning Count']='<inline>'..Warnings.count_warnings(player),
|
||||
['Player']='<inline>' .. player_name,
|
||||
['By']='<inline>' .. by_player_name,
|
||||
['Warning Count']='<inline>' .. Warnings.count_warnings(player),
|
||||
['Reason']=event.reason
|
||||
}
|
||||
end)
|
||||
@@ -151,9 +162,9 @@ if config.player_warnings then
|
||||
title='Warnings Removed',
|
||||
description='A player has a warning removed',
|
||||
color=Colors.green,
|
||||
['Player']='<inline>'..player_name,
|
||||
['By']='<inline>'..event.removed_by_name,
|
||||
['Warning Count']='<inline>'..event.batch_count
|
||||
['Player']='<inline>' .. player_name,
|
||||
['By']='<inline>' .. event.removed_by_name,
|
||||
['Warning Count']='<inline>' .. event.batch_count
|
||||
}
|
||||
end)
|
||||
end
|
||||
@@ -167,8 +178,8 @@ if config.player_jail then
|
||||
title='Jail',
|
||||
description='A player has been jailed',
|
||||
color=Colors.yellow,
|
||||
['Player']='<inline>'..player_name,
|
||||
['By']='<inline>'..by_player_name,
|
||||
['Player']='<inline>' .. player_name,
|
||||
['By']='<inline>' .. by_player_name,
|
||||
['Reason']=event.reason
|
||||
}
|
||||
end)
|
||||
@@ -178,8 +189,8 @@ if config.player_jail then
|
||||
title='Unjail',
|
||||
description='A player has been unjailed',
|
||||
color=Colors.green,
|
||||
['Player']='<inline>'..player_name,
|
||||
['By']='<inline>'..by_player_name
|
||||
['Player']='<inline>' .. player_name,
|
||||
['By']='<inline>' .. by_player_name
|
||||
}
|
||||
end)
|
||||
end
|
||||
@@ -193,8 +204,8 @@ if config.player_bans then
|
||||
title='Banned',
|
||||
description='A player has been banned',
|
||||
color=Colors.red,
|
||||
['Player']='<inline>'..event.player_name,
|
||||
['By']='<inline>'..by_player.name,
|
||||
['Player']='<inline>' .. event.player_name,
|
||||
['By']='<inline>' .. by_player.name,
|
||||
['Reason']=event.reason
|
||||
}
|
||||
end
|
||||
@@ -206,8 +217,8 @@ if config.player_bans then
|
||||
title='Un-Banned',
|
||||
description='A player has been un-banned',
|
||||
color=Colors.green,
|
||||
['Player']='<inline>'..event.player_name,
|
||||
['By']='<inline>'..by_player.name
|
||||
['Player']='<inline>' .. event.player_name,
|
||||
['By']='<inline>' .. by_player.name
|
||||
}
|
||||
end
|
||||
end)
|
||||
@@ -221,7 +232,7 @@ if config.player_mutes then
|
||||
title='Muted',
|
||||
description='A player has been muted',
|
||||
color=Colors.yellow,
|
||||
['Player']='<inline>'..player_name
|
||||
['Player']='<inline>' .. player_name
|
||||
}
|
||||
end)
|
||||
Event.add(defines.events.on_player_unmuted, function(event)
|
||||
@@ -230,7 +241,7 @@ if config.player_mutes then
|
||||
title='Un-Muted',
|
||||
description='A player has been un-muted',
|
||||
color=Colors.green,
|
||||
['Player']='<inline>'..player_name
|
||||
['Player']='<inline>' .. player_name
|
||||
}
|
||||
end)
|
||||
end
|
||||
@@ -245,8 +256,8 @@ if config.player_kicks then
|
||||
title='Kick',
|
||||
description='A player has been kicked',
|
||||
color=Colors.orange,
|
||||
['Player']='<inline>'..player_name,
|
||||
['By']='<inline>'..by_player.name,
|
||||
['Player']='<inline>' .. player_name,
|
||||
['By']='<inline>' .. by_player.name,
|
||||
['Reason']=event.reason
|
||||
}
|
||||
end
|
||||
@@ -261,7 +272,7 @@ if config.player_promotes then
|
||||
title='Promote',
|
||||
description='A player has been promoted',
|
||||
color=Colors.green,
|
||||
['Player']='<inline>'..player_name
|
||||
['Player']='<inline>' .. player_name
|
||||
}
|
||||
end)
|
||||
Event.add(defines.events.on_player_demoted, function(event)
|
||||
@@ -270,7 +281,7 @@ if config.player_promotes then
|
||||
title='Demote',
|
||||
description='A player has been demoted',
|
||||
color=Colors.yellow,
|
||||
['Player']='<inline>'..player_name
|
||||
['Player']='<inline>' .. player_name
|
||||
}
|
||||
end)
|
||||
end
|
||||
@@ -282,9 +293,9 @@ Event.add(defines.events.on_console_command, function(event)
|
||||
if config[event.command] then
|
||||
emit_event{
|
||||
title=event.command:gsub('^%l', string.upper),
|
||||
description='/'..event.command..' was used',
|
||||
description='/' .. event.command .. ' was used',
|
||||
color=Colors.grey,
|
||||
['By']='<inline>'..player_name,
|
||||
['By']='<inline>' .. player_name,
|
||||
['Details'] = event.parameters ~= '' and event.parameters or nil
|
||||
}
|
||||
end
|
||||
|
||||
23
modules/addons/inserter.lua
Normal file
23
modules/addons/inserter.lua
Normal file
@@ -0,0 +1,23 @@
|
||||
local Event = require 'utils.event'
|
||||
|
||||
local controllers_with_inventory = {
|
||||
[defines.controllers.character] = true,
|
||||
[defines.controllers.god] = true,
|
||||
[defines.controllers.editor] = true,
|
||||
}
|
||||
|
||||
Event.add(defines.events.on_player_mined_entity, function(event)
|
||||
if (not event.entity.valid) or (event.entity.type ~= 'inserter') or event.entity.drop_target then
|
||||
return
|
||||
end
|
||||
|
||||
local item_entity = event.entity.surface.find_entity('item-on-ground', event.entity.drop_position)
|
||||
|
||||
if item_entity then
|
||||
local player = game.get_player(event.player_index)
|
||||
|
||||
if controllers_with_inventory[player.controller_type] then
|
||||
player.mine_entity(item_entity)
|
||||
end
|
||||
end
|
||||
end)
|
||||
64
modules/addons/miner.lua
Normal file
64
modules/addons/miner.lua
Normal file
@@ -0,0 +1,64 @@
|
||||
local Event = require 'utils.event_core' --- @dep utils.event_core
|
||||
|
||||
local function miner_check(entity, event)
|
||||
if ((math.abs(entity.position.x - event.entity.position.x) < entity.prototype.mining_drill_radius) and (math.abs(entity.position.y - event.entity.position.y) < entity.prototype.mining_drill_radius)) then
|
||||
if entity.mining_target ~= nil and entity.mining_target.valid then
|
||||
if entity.mining_target.amount > 0 then
|
||||
return
|
||||
end
|
||||
|
||||
local resources = entity.surface.find_entities_filtered{area={{entity.position.x - entity.prototype.mining_drill_radius, entity.position.y - entity.prototype.mining_drill_radius}, {entity.position.x + entity.prototype.mining_drill_radius, entity.position.y + entity.prototype.mining_drill_radius}}, type='resource'}
|
||||
|
||||
for _, resource in pairs(resources) do
|
||||
if resource.amount > 0 then
|
||||
-- if any tile in the radius have resources
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
if entity.to_be_deconstructed(entity.force) then
|
||||
-- if it is already waiting to be deconstruct
|
||||
return
|
||||
else
|
||||
if entity.fluidbox and #entity.fluidbox > 0 then
|
||||
-- if require fluid to mine
|
||||
return
|
||||
end
|
||||
|
||||
if next(entity.circuit_connected_entities.red) ~= nil or next(entity.circuit_connected_entities.green) ~= nil then
|
||||
-- connected to circuit network
|
||||
return
|
||||
end
|
||||
|
||||
if not entity.minable then
|
||||
-- if it is minable
|
||||
return
|
||||
end
|
||||
|
||||
if not entity.prototype.selectable_in_game then
|
||||
-- if it can select
|
||||
return
|
||||
end
|
||||
|
||||
if entity.has_flag('not-deconstructable') then
|
||||
-- if it can deconstruct
|
||||
return
|
||||
end
|
||||
|
||||
entity.order_deconstruction(entity.force)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_resource_depleted, function(event)
|
||||
local entities = event.entity.surface.find_entities_filtered{area={{event.entity.position.x-1, event.entity.position.y-1}, {event.entity.position.x+1, event.entity.position.y+1}}, type='mining-drill'}
|
||||
|
||||
if #entities == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
for _, entity in pairs(entities) do
|
||||
miner_check(entity, event)
|
||||
end
|
||||
end)
|
||||
@@ -25,7 +25,10 @@ Event.add(Protection.events.on_repeat_violation, function(event)
|
||||
end
|
||||
|
||||
-- Jail if needed
|
||||
if repeat_count[player.index] < 3 then return end
|
||||
if repeat_count[player.index] < 3 then
|
||||
return
|
||||
end
|
||||
|
||||
local player_name_color = format_chat_player_name(player)
|
||||
Jail.jail_player(player, '<protection>', 'Removed too many protected entities, please wait for a moderator.')
|
||||
game.print{'protection-jail.jail', player_name_color}
|
||||
|
||||
@@ -9,17 +9,20 @@ local format_chat_player_name = _C.format_chat_player_name --- @dep expcore.comm
|
||||
--- Returns the playtime of the reporter. Used when calculating the total playtime of all reporters
|
||||
local function reporter_playtime(_, by_player_name, _)
|
||||
local player = game.get_player(by_player_name)
|
||||
if player == nil then return 0 end
|
||||
if player == nil then
|
||||
return 0
|
||||
end
|
||||
return player.online_time
|
||||
end
|
||||
|
||||
--- Tests the combined playtime of all reporters against the reported player
|
||||
Event.add(Reports.events.on_player_reported, function(event)
|
||||
local player = game.get_player(event.player_index)
|
||||
local total_playtime = Reports.count_reports(player, reporter_playtime)
|
||||
if total_playtime < player.online_time*1.5 then return end
|
||||
-- Combined playtime is greater than 150% of the reported's playtime
|
||||
local player_name_color = format_chat_player_name(player)
|
||||
Jail.jail_player(player, '<reports>', 'Reported by too many players, please wait for a moderator.')
|
||||
game.print{'report-jail.jail', player_name_color}
|
||||
end)
|
||||
|
||||
-- player less than 30 min
|
||||
if (Reports.count_reports(player) > 1) and (total_playtime > math.max(player.online_time * 2, 108000)) then
|
||||
local player_name_color = format_chat_player_name(player)
|
||||
Jail.jail_player(player, '<reports>', 'Reported by too many players, please wait for a moderator.')
|
||||
game.print{'report-jail.jail', player_name_color}
|
||||
end
|
||||
end)
|
||||
|
||||
@@ -12,7 +12,7 @@ end)
|
||||
|
||||
-- Apply an offset to a LuaPosition
|
||||
local function apply_offset(position, offset)
|
||||
return { x = position.x + (offset.x or offset[1]), y = position.y + (offset.y or offset[2]) }
|
||||
return {x=position.x + (offset.x or offset[1]), y=position.y + (offset.y or offset[2])}
|
||||
end
|
||||
|
||||
-- Apply the offset to the turrets default position
|
||||
@@ -22,23 +22,33 @@ end
|
||||
|
||||
-- Get or create the force used for entities in spawn
|
||||
local function get_spawn_force()
|
||||
local force = game.forces['Spawn']
|
||||
if force and force.valid then return force end
|
||||
force = game.create_force('Spawn')
|
||||
local force = game.forces['spawn']
|
||||
|
||||
if force and force.valid then
|
||||
return force
|
||||
end
|
||||
|
||||
force = game.create_force('spawn')
|
||||
force.set_cease_fire('player', true)
|
||||
game.forces['player'].set_cease_fire('Spawn', true)
|
||||
-- force.set_friend('player', true)
|
||||
game.forces['player'].set_cease_fire('spawn', true)
|
||||
-- game.forces['player'].set_friend('spawn', true)
|
||||
|
||||
return force
|
||||
end
|
||||
|
||||
-- Protects an entity and sets its force to the spawn force
|
||||
-- Protects an entity
|
||||
-- and sets its force to the spawn force
|
||||
local function protect_entity(entity, set_force)
|
||||
if entity and entity.valid then
|
||||
entity.destructible = false
|
||||
entity.minable = false
|
||||
entity.rotatable = false
|
||||
entity.operable = false
|
||||
if not set_force then entity.health = 0 end
|
||||
if set_force then entity.force = get_spawn_force() end
|
||||
|
||||
if set_force then
|
||||
entity.force = get_spawn_force()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -51,8 +61,8 @@ local function spawn_turrets()
|
||||
|
||||
-- Makes a new turret if it is not found
|
||||
if not turret or not turret.valid then
|
||||
turret = surface.create_entity{name='gun-turret', position=pos, force='Spawn'}
|
||||
protect_entity(turret, true)
|
||||
turret = surface.create_entity{name='gun-turret', position=pos, force='spawn'}
|
||||
protect_entity(turret)
|
||||
end
|
||||
|
||||
-- Adds ammo to the turret
|
||||
@@ -68,12 +78,16 @@ local function spawn_belts(surface, position)
|
||||
position = apply_offset(position, config.afk_belts.offset)
|
||||
local belt_type = config.afk_belts.belt_type
|
||||
local belt_details = {{-0.5, -0.5, 2}, {0.5, -0.5, 4}, {-0.5, 0.5, 0}, {0.5, 0.5, 6}} -- x, y,dir
|
||||
|
||||
for _, belt_set in pairs(config.afk_belts.locations) do
|
||||
local set_position = apply_offset(position, belt_set)
|
||||
for _, belt in pairs(belt_details) do
|
||||
local pos = apply_offset(set_position, belt)
|
||||
local belt_entity = surface.create_entity{name=belt_type, position=pos, force='neutral', direction=belt[3]}
|
||||
if config.afk_belts.protected then protect_entity(belt_entity) end
|
||||
local belt_entity = surface.create_entity{name=belt_type, position=pos, force='spawn', direction=belt[3]}
|
||||
|
||||
if config.afk_belts.protected then
|
||||
protect_entity(belt_entity)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -83,9 +97,11 @@ local function spawn_pattern(surface, position)
|
||||
position = apply_offset(position, config.pattern.offset)
|
||||
local tiles_to_make = {}
|
||||
local pattern_tile = config.pattern.pattern_tile
|
||||
|
||||
for _, tile in pairs(config.pattern.locations) do
|
||||
table.insert(tiles_to_make, {name=pattern_tile, position=apply_offset(position, tile)})
|
||||
end
|
||||
|
||||
surface.set_tiles(tiles_to_make)
|
||||
end
|
||||
|
||||
@@ -104,9 +120,13 @@ end
|
||||
local function spawn_entities(surface, position)
|
||||
position = apply_offset(position, config.entities.offset)
|
||||
for _, entity in pairs(config.entities.locations) do
|
||||
local pos = apply_offset(position, { x=entity[2], y=entity[3] })
|
||||
local pos = apply_offset(position, {x=entity[2], y=entity[3]})
|
||||
entity = surface.create_entity{name=entity[1], position=pos, force='neutral'}
|
||||
if config.entities.protected then protect_entity(entity) end
|
||||
|
||||
if config.entities.protected then
|
||||
protect_entity(entity)
|
||||
end
|
||||
|
||||
entity.operable = config.entities.operable
|
||||
end
|
||||
end
|
||||
@@ -114,7 +134,8 @@ end
|
||||
-- Generates an area with no water or entities, no water area is larger
|
||||
local function spawn_area(surface, position)
|
||||
local dr = config.spawn_area.deconstruction_radius
|
||||
local dr2 = dr^2
|
||||
local tr = config.spawn_area.tile_radius
|
||||
local tr2 = tr^2
|
||||
local decon_tile = config.spawn_area.deconstruction_tile
|
||||
|
||||
local fr = config.spawn_area.landfill_radius
|
||||
@@ -132,7 +153,7 @@ local function spawn_area(surface, position)
|
||||
local y2 = (y+0.5)^2
|
||||
local dst = x2+y2
|
||||
local pos = {x=position.x+x, y=position.y+y}
|
||||
if dst < dr2 then
|
||||
if dst < tr2 then
|
||||
-- If it is inside the decon radius always set the tile
|
||||
table.insert(tiles_to_make, {name=decon_tile, position=pos})
|
||||
elseif dst < fr2 and surface.get_tile(pos).collides_with('player-layer') then
|
||||
@@ -144,10 +165,34 @@ local function spawn_area(surface, position)
|
||||
|
||||
-- Remove entities then set the tiles
|
||||
local entities_to_remove = surface.find_entities_filtered{position=position, radius=dr, name='character', invert=true}
|
||||
for _, entity in pairs(entities_to_remove) do entity.destroy() end
|
||||
for _, entity in pairs(entities_to_remove) do
|
||||
entity.destroy()
|
||||
end
|
||||
surface.set_tiles(tiles_to_make)
|
||||
end
|
||||
|
||||
local function spawn_resource_tiles(surface)
|
||||
for _, v in ipairs(config.resource_tiles.resources) do
|
||||
if v.enabled then
|
||||
for x=v.offset[1], v.offset[1] + v.size[1] do
|
||||
for y=v.offset[2], v.offset[2] + v.size[2] do
|
||||
surface.create_entity({name=v.name, amount=v.amount, position={x, y}})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function spawn_resource_patches(surface)
|
||||
for _, v in ipairs(config.resource_patches.resources) do
|
||||
if v.enabled then
|
||||
for i=1, v.num_patches do
|
||||
surface.create_entity({name=v.name, amount=v.amount, position={v.offset[1] + v.offset_next[1] * (i - 1), v.offset[2] + v.offset_next[2] * (i - 1)}})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Only add a event handler if the turrets are enabled
|
||||
if config.turrets.enabled then
|
||||
Event.on_nth_tick(config.turrets.refill_time, function()
|
||||
@@ -156,6 +201,19 @@ if config.turrets.enabled then
|
||||
end)
|
||||
end
|
||||
|
||||
if config.resource_refill_nearby.enabled then
|
||||
-- could have a flag in global that early returns if true, and reset it on_tick
|
||||
Event.on_nth_tick(36000, function()
|
||||
if game.tick < 10 then
|
||||
return
|
||||
end
|
||||
|
||||
for _, ore in pairs(game.players[1].surface.find_entities_filtered{position=game.players[1].force.get_spawn_position(game.players[1].surface), radius=config.resource_refill_nearby.range, name=config.resource_refill_nearby.resources_name}) do
|
||||
ore.amount = ore.amount + math.random(config.resource_refill_nearby.amount[1], config.resource_refill_nearby.amount[2])
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- When the first player joins create the spawn area
|
||||
Event.add(defines.events.on_player_created, function(event)
|
||||
if event.player_index ~= 1 then return end
|
||||
@@ -169,8 +227,10 @@ Event.add(defines.events.on_player_created, function(event)
|
||||
if config.afk_belts.enabled then spawn_belts(s, p) end
|
||||
if config.turrets.enabled then spawn_turrets() end
|
||||
if config.entities.enabled then spawn_entities(s, p) end
|
||||
if config.resource_tiles.enabled then spawn_resource_tiles(s) end
|
||||
if config.resource_patches.enabled then spawn_resource_patches(s) end
|
||||
player.teleport(p, s)
|
||||
end)
|
||||
|
||||
-- Way to access global table
|
||||
return turrets
|
||||
return turrets
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
---LuaPlayerBuiltEntityEventFilters
|
||||
---Events.set_event_filter(defines.events.on_built_entity, {{filter = "name", name = "fast-inserter"}})
|
||||
local Event = require 'utils.event' --- @dep utils.event
|
||||
local config = require 'config.station_auto_name' --- @dep config.chat_reply
|
||||
|
||||
--Credit to Cooldude2606 for using his lua magic to make this function.
|
||||
local directions = {
|
||||
@@ -46,10 +47,9 @@ local function station_name_changer(event)
|
||||
|
||||
local boundingBox = entity.bounding_box
|
||||
-- expanded box for recourse search:
|
||||
local bounding2 = { {boundingBox.left_top.x -100 ,boundingBox.left_top.y -100} , {boundingBox.right_bottom.x +100, boundingBox.right_bottom.y +100 } }
|
||||
local bounding2 = {{boundingBox.left_top.x-100 ,boundingBox.left_top.y-100} , {boundingBox.right_bottom.x+100, boundingBox.right_bottom.y+100 }}
|
||||
-- gets all resources in bounding_box2:
|
||||
local recourses = game.surfaces[1].find_entities_filtered{area = bounding2, type = "resource"}
|
||||
|
||||
if #recourses > 0 then -- save cpu time if their are no recourses in bounding_box2
|
||||
local closest_distance
|
||||
local px, py = boundingBox.left_top.x, boundingBox.left_top.y
|
||||
@@ -70,12 +70,17 @@ local function station_name_changer(event)
|
||||
if item_name then -- prevent errors if something went wrong
|
||||
local item_name2 = item_name:gsub("^%l", string.upper):gsub('-', ' ') -- removing the - and making first letter capital
|
||||
|
||||
local Item_ore_fluid = "item"
|
||||
if item_name == "crude-oil" then
|
||||
Item_ore_fluid = "fluid"
|
||||
local item_type = 'item'
|
||||
if item_name == 'crude-oil' then
|
||||
item_type = 'fluid'
|
||||
end
|
||||
--Final string:
|
||||
entity.backer_name = string.format("[L] [img=%s.%s] %s %s (%s)", Item_ore_fluid, item_name, item_name2, entity.backer_name, Angle( entity ))
|
||||
|
||||
entity.backer_name = config.station_name:gsub('__icon__', '[img=' .. item_type .. '.' .. item_name .. ']')
|
||||
:gsub('__item_name__', item_name2)
|
||||
:gsub('__backer_name__', entity.backer_name)
|
||||
:gsub('__direction__', Angle(entity))
|
||||
:gsub('__x__', math.floor(entity.position.x))
|
||||
:gsub('__y__', math.floor(entity.position.y))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,7 +10,7 @@ local PlayerData = require 'expcore.player_data' --- @dep expcore.player_data
|
||||
-- Global queue used to store trees that need to be removed, also chache for player roles
|
||||
local chache = {}
|
||||
local tree_queue = { _head=0 }
|
||||
Global.register({ tree_queue, chache }, function(tbl)
|
||||
Global.register({tree_queue, chache}, function(tbl)
|
||||
tree_queue = tbl[1]
|
||||
chache = tbl[2]
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user