mirror of
https://github.com/Refactorio/RedMew.git
synced 2024-12-12 10:04:40 +02:00
Added missing require user_groups into nuke_control.lua
- Fixed bugs in user_groups - Moved get_actor into utils/utils.lua
This commit is contained in:
parent
440709c5ef
commit
43d1eb0ad6
@ -236,7 +236,7 @@ end
|
||||
Event.add(defines.events.on_built_entity, built_entity)
|
||||
|
||||
local function toggle_tp_mode(cmd)
|
||||
if not (game.player and (game.player.admin or UserGroups.is_mod(game.player.name))) then
|
||||
if not (game.player and game.player.admin) then
|
||||
cant_run(cmd.name)
|
||||
return
|
||||
end
|
||||
@ -367,7 +367,7 @@ local function tempban(cmd)
|
||||
end
|
||||
local group = get_group()
|
||||
|
||||
game.print(UserGroups.get_actor() .. " put " .. params[1] .. " in timeout for " .. params[2] .. " minutes.")
|
||||
game.print(get_actor() .. " put " .. params[1] .. " in timeout for " .. params[2] .. " minutes.")
|
||||
if group then
|
||||
group.add_player(params[1])
|
||||
if not tonumber(cmd.parameter) then
|
||||
|
@ -1,14 +1,14 @@
|
||||
local Event = require "utils.event"
|
||||
local UserGroups = require "user_groups"
|
||||
|
||||
function allowed_to_nuke(player)
|
||||
if type(player) == "table" then
|
||||
return player.admin or is_mod(player.name) or is_regular(player.name) or ((player.online_time / 216000) > global.scenario.config.nuke_min_time_hours)
|
||||
return player.admin or UserGroups.is_regular(player.name) or ((player.online_time / 216000) > global.scenario.config.nuke_min_time_hours)
|
||||
elseif type(player) == "number" then
|
||||
return allowed_to_nuke(game.players[player])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function ammo_changed(event)
|
||||
local player = game.players[event.player_index]
|
||||
if allowed_to_nuke(player) then return end
|
||||
@ -19,7 +19,6 @@ local function ammo_changed(event)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function on_player_deconstructed_area(event)
|
||||
local player = game.players[event.player_index]
|
||||
if allowed_to_nuke(player) then return end
|
||||
@ -41,45 +40,12 @@ local function on_player_deconstructed_area(event)
|
||||
end
|
||||
end
|
||||
|
||||
local function log_on_player_mined_entity(str, event)
|
||||
game.write_file("on_player_mined_entity_debug", game.tick .. " (" .. game.players[event.player_index].name .. ") " .. str .. "\n", true, 0)
|
||||
end
|
||||
|
||||
global.on_player_mined_item_enabled = true
|
||||
global.on_player_mined_item_init = true
|
||||
|
||||
|
||||
--Never knew the debug code made it into the codebase lol
|
||||
local function on_player_mined_item(event)
|
||||
log_on_player_mined_entity("nuke_control.on_player_mined_item: entry", event)
|
||||
if global.on_player_mined_item_enabled then
|
||||
log_on_player_mined_entity("nuke_control.on_player_mined_item: enabled", event)
|
||||
if global.on_player_mined_item_init then
|
||||
log_on_player_mined_entity("nuke_control.on_player_mined_item: init", event)
|
||||
game.forces.enemy.research_all_technologies() --avoids losing logstics slot configuration on force toggle
|
||||
global.on_player_mined_item_init = false
|
||||
end
|
||||
local entity = event.entity
|
||||
if entity.valid and entity.force.name ~= "enemy" and entity.force.name ~= "neutral" and entity.name ~= "entity-ghost" and entity.type ~= "logistic-robot" and entity.type ~= "construction-robot" then
|
||||
log_on_player_mined_entity("nuke_control.on_player_mined_item: in body", event)
|
||||
local entity_name = entity.name
|
||||
if entity_name == "pipe-to-ground" then entity_name = "pipe" end
|
||||
log_on_player_mined_entity("nuke_control.on_player_mined_item: before ghost placement", event)
|
||||
local ghost = event.entity.surface.create_entity{name = "entity-ghost", position = event.entity.position, inner_name = entity_name, expires = false, force = "enemy", direction = event.entity.direction}
|
||||
log_on_player_mined_entity("nuke_control.on_player_mined_item: ghost placed", event)
|
||||
ghost.last_user = event.player_index
|
||||
log_on_player_mined_entity("nuke_control.on_player_mined_item: last user set", event)
|
||||
end
|
||||
end
|
||||
log_on_player_mined_entity("nuke_control.on_player_mined_item: exit", event)
|
||||
end
|
||||
|
||||
local function item_not_sanctioned(item)
|
||||
local name = item.name
|
||||
return (
|
||||
name:find("capsule") or
|
||||
name == "cliff-explosives" or
|
||||
name == "raw-fish" or
|
||||
name:find("capsule") or
|
||||
name == "cliff-explosives" or
|
||||
name == "raw-fish" or
|
||||
name == "discharge-defense-remote"
|
||||
)
|
||||
end
|
||||
@ -103,8 +69,8 @@ local function on_capsule_used(event)
|
||||
local area = {{event.position.x-5, event.position.y-5}, {event.position.x+5, event.position.y+5}}
|
||||
local count = 0
|
||||
local entities = player.surface.find_entities_filtered{force=player.force, area=area}
|
||||
for _,e in pairs(entities) do
|
||||
if not entity_allowed_to_bomb(e) then count = count + 1 end
|
||||
for _,e in pairs(entities) do
|
||||
if not entity_allowed_to_bomb(e) then count = count + 1 end
|
||||
end
|
||||
if count > 8 then
|
||||
if global.players_warned[event.player_index] then
|
||||
@ -121,4 +87,3 @@ Event.add(defines.events.on_player_ammo_inventory_changed, ammo_changed)
|
||||
Event.add(defines.events.on_player_deconstructed_area, on_player_deconstructed_area)
|
||||
--Event.add(defines.events.on_player_mined_entity, on_player_mined_item)
|
||||
Event.add(defines.events.on_player_used_capsule, on_capsule_used)
|
||||
|
||||
|
@ -4,29 +4,25 @@ local Event = require "utils.event"
|
||||
local Module = {}
|
||||
|
||||
local function update_file()
|
||||
local file = position .. ".lua"
|
||||
local file = "regulars.lua"
|
||||
game.write_file(file, "{", false, 0)
|
||||
local group = global[position]
|
||||
local line = ""
|
||||
for player_name,_ in pairs(group) do
|
||||
for player_name,_ in pairs(global.regulars) do
|
||||
line = string.format('["%s"] = "",\n', player_name)
|
||||
game.write_file(file, line, true, 0)
|
||||
end
|
||||
game.write_file(file, "}", true, 0)
|
||||
end
|
||||
|
||||
Module.get_actor = function()
|
||||
if game.player then return game.player.name end
|
||||
return "<server>"
|
||||
end
|
||||
|
||||
local is_regular = function(player_name)
|
||||
return cast_bool(global.regulars[player_name] or global.regulars[player_name:lower()]) --to make it backwards compatible
|
||||
|
||||
Module.is_regular = function(player_name)
|
||||
return false or global.regulars[player_name] or global.regulars[player_name:lower()] --to make it backwards compatible
|
||||
end
|
||||
|
||||
Module.add_regular = function(player_name)
|
||||
local actor = get_actor()
|
||||
if is_regular(player_name) then player_print(player_name .. " is already a regular.")
|
||||
if Module.is_regular(player_name) then player_print(player_name .. " is already a regular.")
|
||||
else
|
||||
if game.players[player_name] then
|
||||
player_name = game.players[player_name].name
|
||||
@ -43,7 +39,7 @@ Module.remove_regular = function(player_name)
|
||||
local actor = get_actor()
|
||||
if game.players[player_name] then
|
||||
player_name = game.players[player_name].name
|
||||
if is_regular(player_name) then game.print(player_name .. " was demoted from regular by " .. actor .. ".") end
|
||||
if Module.is_regular(player_name) then game.print(player_name .. " was demoted from regular by " .. actor .. ".") end
|
||||
global.regulars[player_name] = nil
|
||||
global.regulars[player_name:lower()] = nil --backwards compatible
|
||||
update_file()
|
||||
|
@ -496,3 +496,8 @@ function print_admins(msg)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function get_actor()
|
||||
if game.player then return game.player.name end
|
||||
return "<server>"
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user