1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-18 03:21:47 +02:00

Features cleanup (#414)

* Fix scoping, var names, unused functions, etc.

* Autoformat
This commit is contained in:
Matthew 2018-11-20 05:46:19 -05:00 committed by Valansch
parent a1dae9ee91
commit c9369c3d14
20 changed files with 461 additions and 408 deletions

View File

@ -12,7 +12,7 @@ require 'features.bot'
-- Library modules which, if missing, will cause other feature modules to fail
require 'features.base_data'
require 'features.follow'
--require 'features.follow' -- Nothing currently uses anything inside follow
require 'features.player_create'
require 'features.user_groups'

View File

@ -1,14 +1,15 @@
local Event = require "utils.event"
local Utils = require "utils.utils"
local Event = require 'utils.event'
local Utils = require 'utils.utils'
local Game = require 'utils.game'
global.original_last_users_by_ent_pos = {}
Event.on_init(function()
global.ag_surface=game.create_surface("antigrief",{autoplace_controls={coal={frequency="normal",richness="normal",size="none"},["copper-ore"]={frequency="normal",richness="normal",size="none"},["crude-oil"]={frequency="normal",richness="normal",size="none"},desert={frequency="normal",richness="normal",size="none"},dirt={frequency="normal",richness="normal",size="none"},["enemy-base"]={frequency="normal",richness="normal",size="none"},grass={frequency="normal",richness="normal",size="none"},["iron-ore"]={frequency="normal",richness="normal",size="none"},sand={frequency="normal",richness="normal",size="none"},stone={frequency="normal",richness="normal",size="none"},trees={frequency="normal",richness="normal",size="none"},["uranium-ore"]={frequency="normal",richness="normal",size="none"}},cliff_settings={cliff_elevation_0=1024,cliff_elevation_interval=10,name="cliff"},height=2000000,peaceful_mode=false,seed=3461559752,starting_area="very-low",starting_points={{x=0,y=0}},terrain_segmentation="normal",water="normal",width=2000000})
Event.on_init(
function()
global.ag_surface = game.create_surface('antigrief', {autoplace_controls = {coal = {frequency = 'normal', richness = 'normal', size = 'none'}, ['copper-ore'] = {frequency = 'normal', richness = 'normal', size = 'none'}, ['crude-oil'] = {frequency = 'normal', richness = 'normal', size = 'none'}, desert = {frequency = 'normal', richness = 'normal', size = 'none'}, dirt = {frequency = 'normal', richness = 'normal', size = 'none'}, ['enemy-base'] = {frequency = 'normal', richness = 'normal', size = 'none'}, grass = {frequency = 'normal', richness = 'normal', size = 'none'}, ['iron-ore'] = {frequency = 'normal', richness = 'normal', size = 'none'}, sand = {frequency = 'normal', richness = 'normal', size = 'none'}, stone = {frequency = 'normal', richness = 'normal', size = 'none'}, trees = {frequency = 'normal', richness = 'normal', size = 'none'}, ['uranium-ore'] = {frequency = 'normal', richness = 'normal', size = 'none'}}, cliff_settings = {cliff_elevation_0 = 1024, cliff_elevation_interval = 10, name = 'cliff'}, height = 2000000, peaceful_mode = false, seed = 3461559752, starting_area = 'very-low', starting_points = {{x = 0, y = 0}}, terrain_segmentation = 'normal', water = 'normal', width = 2000000})
global.ag_surface.always_day = true
end)
end
)
local function is_mocked(entity)
return rawget(entity, 'mock')
@ -17,7 +18,7 @@ end
local function place_entity_on_surface(entity, surface, replace, player)
local new_entity = nil
for _, e in ipairs(surface.find_entities_filtered {position = entity.position}) do
if replace or e.type == "entity-ghost" then
if replace or e.type == 'entity-ghost' then
e.destroy()
end
end
@ -36,26 +37,31 @@ local function place_entity_on_surface(entity, surface, replace, player)
return new_entity
end
Event.add(defines.events.on_chunk_generated, function(event)
if event.surface.name == "antigrief" then
Event.add(
defines.events.on_chunk_generated,
function(event)
if event.surface.name == 'antigrief' then
local tiles = {}
for x = event.area.left_top.x, event.area.right_bottom.x - 1 do
for y = event.area.left_top.y, event.area.right_bottom.y - 1 do
table.insert(tiles,{name="lab-dark-2", position = {x,y}})
table.insert(tiles, {name = 'lab-dark-2', position = {x, y}})
end
end
event.surface.set_tiles(tiles)
end
end)
end
)
local function get_position_str(pos)
return string.format("%d|%d", pos.x, pos.y)
return string.format('%d|%d', pos.x, pos.y)
end
local function on_entity_changed(event)
local entity = event.entity or event.destination
local player = Game.get_player_by_index(event.player_index)
if player.admin or not entity.valid then return end --Freebees for admins
if player.admin or not entity.valid then
return
end --Freebees for admins
if entity.last_user ~= player and entity.force == player.force then --commented out to be able to debug
place_entity_on_surface(entity, global.ag_surface, true, event.player_index)
end
@ -64,13 +70,16 @@ local function on_entity_changed(event)
end
end
Event.add(defines.events.on_robot_pre_mined, function(event)
Event.add(
defines.events.on_robot_pre_mined,
function(event)
--The bot isnt the culprit! The last user is! They marked it for deconstruction!
if event.entity.valid and event.entity.last_user then
event.player_index = event.entity.last_user.index
on_entity_changed(event)
end
end)
end
)
local function get_pre_rotate_direction(entity)
--Some entities have 8 rotation steps and some have 4. So a mathmatical reverse is not possible
@ -80,32 +89,43 @@ local function get_pre_rotate_direction(entity)
return direction
end
Event.add(defines.events.on_player_rotated_entity, function(event)
Event.add(
defines.events.on_player_rotated_entity,
function(event)
local entity = event.entity
if not entity.valid then return end
if not entity.valid then
return
end
local ag_entities = global.ag_surface.find_entities_filtered {position = entity.position}
--If a player has rotated twice we want to preserve the original state.
if #ag_entities == 0 or not ag_entities[1].last_user or ag_entities[1].last_user ~= entity.last_user then
--Mock entity us used because the api doesnt support pre_player_rotated entity.
--The mocked entity has the entity state before rotation
--We also dont know who rotated it and dont want the griefers name there so we set it to 1
local mock_entity = {name = entity.name, position = entity.position, mock = true,
last_user = Game.get_player_by_index(1), force = entity.force, direction = get_pre_rotate_direction(entity)}
local mock_entity = {
name = entity.name,
position = entity.position,
mock = true,
last_user = Game.get_player_by_index(1),
force = entity.force,
direction = get_pre_rotate_direction(entity)
}
event.entity = mock_entity
on_entity_changed(event)
end
end)
end
)
Event.add(defines.events.on_pre_entity_settings_pasted, on_entity_changed)
Event.add(defines.events.on_entity_died, function(event)
Event.add(
defines.events.on_entity_died,
function(event)
--is a player on the same force as the destroyed object
if event.entity and event.entity.valid and event.entity.force.name == "player" and event.cause and
event.cause.force == event.entity.force and event.cause.type == "player" then
if event.entity and event.entity.valid and event.entity.force.name == 'player' and event.cause and event.cause.force == event.entity.force and event.cause.type == 'player' then
local new_entity = place_entity_on_surface(event.entity, global.ag_surface, true, event.cause.player)
if new_entity and event.entity.type == "container" then
if new_entity and event.entity.type == 'container' then
local items = event.entity.get_inventory(defines.inventory.chest).get_contents()
if items then
for item, n in pairs(items) do
@ -114,22 +134,29 @@ Event.add(defines.events.on_entity_died, function(event)
end
end
end
end)
end
)
Event.add(defines.events.on_player_mined_entity, on_entity_changed)
Event.add(defines.events.on_marked_for_deconstruction, function(event)
Event.add(
defines.events.on_marked_for_deconstruction,
function(event)
if event.entity.last_user then
global.original_last_users_by_ent_pos[get_position_str(event.entity.position)] = event.entity.last_user.index
end
end)
end
)
local Module = {}
Module.undo = function(player)
if type(player) == "nil" or type(player) == "string" then return --No support for strings!
elseif type(player) == "number" then player = Game.get_player_by_index(player) end
Module.undo =
function(player)
if type(player) == 'nil' or type(player) == 'string' then
return --No support for strings!
elseif type(player) == 'number' then
player = Game.get_player_by_index(player)
end
--Remove all items from all surfaces that player placed an entity on
for _, surface in pairs(game.surfaces) do
@ -149,12 +176,11 @@ Module.undo = function(player)
local new_entity = place_entity_on_surface(e, game.surfaces.nauvis, false, last_user)
--Transfer items
if new_entity then
local player = Utils.ternary(new_entity.last_user, new_entity.last_user, game.player)
local event = {created_entity = new_entity, player_index = player.index, stack = {}}
script.raise_event(defines.events.on_built_entity, event)
if e.type == "container" then
if e.type == 'container' then
local items = e.get_inventory(defines.inventory.chest).get_contents()
if items then
for item, n in pairs(items) do

View File

@ -1,9 +1,11 @@
local Event = require "utils.event"
local Event = require 'utils.event'
if not global.score_biter_total_kills then global.score_biter_total_kills = 0 end
if not global.score_biter_total_kills then
global.score_biter_total_kills = 0
end
local function biter_kill_counter(event)
if event.entity.force.name == "enemy" then
if event.entity.force.name == 'enemy' then
global.score_biter_total_kills = global.score_biter_total_kills + 1
end
end

View File

@ -1,33 +1,45 @@
local Event = require "utils.event"
local Event = require 'utils.event'
local Game = require 'utils.game'
Event.add(defines.events.on_player_died, function (event)
Event.add(
defines.events.on_player_died,
function(event)
local player = event.player_index
if Game.get_player_by_index(player).name ~= nil then
print("PLAYER$die," .. player .. "," .. Game.get_player_by_index(player).name .. "," .. Game.get_player_by_index(player).force.name)
print('PLAYER$die,' .. player .. ',' .. Game.get_player_by_index(player).name .. ',' .. Game.get_player_by_index(player).force.name)
end
end)
end
)
Event.add(defines.events.on_player_respawned, function (event)
Event.add(
defines.events.on_player_respawned,
function(event)
local player = event.player_index
if Game.get_player_by_index(player).name ~= nil then
print("PLAYER$respawn," .. player .. "," .. Game.get_player_by_index(player).name .. "," .. Game.get_player_by_index(player).force.name)
print('PLAYER$respawn,' .. player .. ',' .. Game.get_player_by_index(player).name .. ',' .. Game.get_player_by_index(player).force.name)
end
end)
end
)
Event.add(defines.events.on_player_joined_game, function (event)
Event.add(
defines.events.on_player_joined_game,
function(event)
local player = event.player_index
if Game.get_player_by_index(player).name ~= nil then
print("PLAYER$join," .. player .. "," .. Game.get_player_by_index(player).name .. "," .. Game.get_player_by_index(player).force.name)
print('PLAYER$join,' .. player .. ',' .. Game.get_player_by_index(player).name .. ',' .. Game.get_player_by_index(player).force.name)
end
end)
end
)
Event.add(defines.events.on_player_left_game, function (event)
Event.add(
defines.events.on_player_left_game,
function(event)
local player = event.player_index
if Game.get_player_by_index(player).name ~= nil then
print("PLAYER$leave," .. player .. "," .. Game.get_player_by_index(player).name .. "," .. Game.get_player_by_index(player).force.name)
print('PLAYER$leave,' .. player .. ',' .. Game.get_player_by_index(player).name .. ',' .. Game.get_player_by_index(player).force.name)
end
end)
end
)
function heartbeat()
--Do nothing, this is just so managepgm can call something as a heartbeat without any errors occurring
@ -35,12 +47,12 @@ end
function playerQuery()
if #game.connected_players == 0 then
print("output$pquery$none")
print('output$pquery$none')
else
local response = "output&pquery$"
local response = 'output&pquery$'
for _, player in pairs(game.connected_players) do
local playerdata = player.name .. "-" .. player.force.name
response = response .. playerdata .. ","
local playerdata = player.name .. '-' .. player.force.name
response = response .. playerdata .. ','
end
print(response:sub(1, #str - 1))
end

View File

@ -104,8 +104,8 @@ local function hodor(event)
local missing_player_string
local not_found = 0
local cannot_mention = {}
for word in event.message:gmatch('%S+') do
local word = word:lower()
for w in event.message:gmatch('%S+') do
local word = w:lower()
local trimmed_word = string.sub(word, 0, string.len(word)-1)
local first_char = string.sub(word, 0, 1)
local last_char = string.sub(word, string.len(word))

View File

@ -43,11 +43,7 @@ local function player_died(event)
local text = player.name .. "'s corpse"
local position = entity.position
local tag =
player.force.add_chart_tag(
player.surface,
{icon = {type = 'item', name = 'power-armor-mk2'}, position = position, text = text}
)
local tag = player.force.add_chart_tag(player.surface, {icon = {type = 'item', name = 'power-armor-mk2'}, position = position, text = text})
if not tag then
return

View File

@ -8,7 +8,6 @@ local Report = require 'features.report'
--local Antigrief = require 'features.antigrief'
--- Takes a target and teleports them to player. (admin only)
local function invoke(cmd)
if not (game.player and game.player.admin) then
@ -41,7 +40,7 @@ local function teleport_player(cmd)
local pos = surface.find_non_colliding_position('player', game.players[target].position, 0, 1)
game.player.teleport(pos, surface)
game.print(target .. "! watcha doin'?!")
game.player.print("You have teleported to" .. game.players[target].name)
game.player.print('You have teleported to ' .. game.players[target].name)
Utils.log_command(game.player.name, cmd.name, cmd.parameter)
end
@ -249,9 +248,7 @@ local function get_group()
group.set_allows_action(i, false)
end
else
game.print(
'This would have nearly crashed the server, please consult the next best scenario dev (valansch or TWLtriston).'
)
game.print('This would have nearly crashed the server, please consult the next best scenario dev (valansch or TWLtriston).')
end
end
return group
@ -326,7 +323,7 @@ local function zoom(cmd)
end
--- Creates a rectangle of water below an admin
local function pool()
local function pool(cmd)
if game.player and game.player.admin then
local t = {}
local p = game.player.position
@ -409,7 +406,6 @@ end
--- Places a target in jail (a permissions group which is unable to act aside from chatting)(admin only)
local function jail_player(cmd)
local player = game.player
-- Check if the player can run the command
if player and not player.admin then
@ -506,7 +502,6 @@ commands.add_command(
end
)
commands.add_command('kill', 'Will kill you.', kill)
commands.add_command('tpplayer', '<player> - Teleports you to the player. (Admins only)', teleport_player)
commands.add_command('invoke', '<player> - Teleports the player to you. (Admins only)', invoke)
@ -527,7 +522,6 @@ commands.add_command('a', 'Admin chat. Messages all other admins (Admins only)',
commands.add_command('report', '<griefer-name> <message> Reports a user to admins', Report.cmd_report)
commands.add_command('show-rail-block', 'Toggles rail block visualisation', show_rail_block)
--[[ commands.add_command('undo', '<player> undoes everything a player has done (Admins only)', undo)
commands.add_command(
'antigrief_surface',

View File

@ -138,6 +138,7 @@ local function fish_drop_entity_died(event)
Task.set_timeout_in_ticks(1, spill_items, {count = count, surface = entity.surface, position = entity.position})
end
end
--
--[[
local function pet(player, entity_name)
@ -191,8 +192,7 @@ local function boost_player_runningspeed(player, market)
[3] = 'Kungfu Master %s defended the village and was awarded a lv.3 speed boost!',
[4] = 'Travelled at the speed of light. %s saw a blackhole. Oops.'
}
global.player_speed_boost_records[player.index].boost_lvl =
1 + global.player_speed_boost_records[player.index].boost_lvl
global.player_speed_boost_records[player.index].boost_lvl = 1 + global.player_speed_boost_records[player.index].boost_lvl
player.character_running_speed_modifier = 1 + player.character_running_speed_modifier
if global.player_speed_boost_records[player.index].boost_lvl >= 4 then
@ -228,8 +228,7 @@ local function boost_player_miningspeed(player, market)
[3] = 'Wood fiend, %s, has picked up a massive chain saw and is awarded a lv.3 mining boost!',
[4] = 'Better learn to control that saw, %s, chopped off their legs. Oops.'
}
global.player_mining_boost_records[player.index].boost_lvl =
1 + global.player_mining_boost_records[player.index].boost_lvl
global.player_mining_boost_records[player.index].boost_lvl = 1 + global.player_mining_boost_records[player.index].boost_lvl
player.character_mining_speed_modifier = 1 + player.character_mining_speed_modifier
if global.player_mining_boost_records[player.index].boost_lvl >= 4 then

View File

@ -1,6 +1,6 @@
global.follows = {}
global.follows.n_entries = 0
local Utils = require "utils.utils"
local Utils = require 'utils.utils'
local Game = require 'utils.game'
local function get_direction(follower, target)
@ -30,7 +30,9 @@ local function get_direction(follower, target)
end
else
-- N or S
if a < 0 then delta_x = - delta_x end -- mirrow x axis if player is NNW or SSE
if a < 0 then
delta_x = -delta_x
end -- mirrow x axis if player is NNW or SSE
if delta_x > 0 then
return defines.direction.north
else

View File

@ -9,7 +9,7 @@ local ForceControl = {}
ForceControl.events = {
--- triggered when the force levels up
--- uses event = {level_reached = number, force = LuaForce}
on_level_up = script.generate_event_name(),
on_level_up = script.generate_event_name()
}
-- the builder, can only be accessed through ForceControl.register() and should be avoided used run-time
@ -20,16 +20,19 @@ local forces = {}
-- the table holding the function that calculates the experience to next level
local next_level_cap_calculator = {
execute = nil,
execute = nil
}
Global.register({
Global.register(
{
forces = forces,
next_level_cap_calculator = next_level_cap_calculator,
}, function (tbl)
next_level_cap_calculator = next_level_cap_calculator
},
function(tbl)
forces = tbl.forces
next_level_cap_calculator = tbl.next_level_cap_calculator
end)
end
)
---Asserts if a given variable is of the expected type using type().
---
@ -39,7 +42,7 @@ end)
local function assert_type(expected_type, given, variable_reference_message)
local given_type = type(given)
if given_type ~= expected_type then
error('Argument ' .. variable_reference_message .. ' must be of type \'' .. expected_type .. '\', given \'' .. given_type .. '\'')
error('Argument ' .. variable_reference_message .. " must be of type '" .. expected_type .. "', given '" .. given_type .. "'")
end
end
@ -92,7 +95,9 @@ function ForceControlBuilder.register(level_matches, callback, lua_force_name)
return
end
Event.add(ForceControl.events.on_level_up, function (event)
Event.add(
ForceControl.events.on_level_up,
function(event)
local force = get_valid_force(lua_force_name)
if not force then
error('Can only register a lua force name for ForceControlBuilder.register')
@ -102,7 +107,8 @@ function ForceControlBuilder.register(level_matches, callback, lua_force_name)
end
on_level_up(event)
end)
end
)
end
---Register a reward which triggers when the given level is reached.
@ -114,9 +120,13 @@ function ForceControlBuilder.register_on_single_level(level, callback, lua_force
assert_type('number', level, 'level of function ForceControl.register_reward_on_single_level')
assert_type('function', callback, 'callback of function ForceControlBuilder.register_on_single_level')
ForceControlBuilder.register(function (level_reached)
ForceControlBuilder.register(
function(level_reached)
return level == level_reached
end, callback, lua_force_name)
end,
callback,
lua_force_name
)
end
---Always returns true
@ -160,7 +170,7 @@ function ForceControl.register_force(lua_force_or_name)
forces[force.name] = {
current_experience = 0,
current_level = 0,
experience_level_up_cap = next_level_cap_calculator.execute(0),
experience_level_up_cap = next_level_cap_calculator.execute(0)
}
end
@ -253,7 +263,7 @@ function ForceControl.get_force_data(lua_force_or_name)
current_experience = force_config.current_experience,
current_level = force_config.current_level,
experience_level_up_cap = force_config.experience_level_up_cap,
experience_percentage = (force_config.current_experience / force_config.experience_level_up_cap) * 100,
experience_percentage = (force_config.current_experience / force_config.experience_level_up_cap) * 100
}
end

View File

@ -250,7 +250,4 @@ Gui.on_custom_close(
)
local market_items = require 'resources.market_items'
table.insert(
market_items,
{price = {{market_items.market_item, 100}}, offer = {type = 'give-item', item = 'infinity-chest'}}
)
table.insert(market_items, {price = {{market_items.market_item, 100}}, offer = {type = 'give-item', item = 'infinity-chest'}})

View File

@ -1,12 +1,12 @@
local Event = require "utils.event"
local UserGroups = require "features.user_groups"
local Utils = require "utils.utils"
local Game = require "utils.game"
local Event = require 'utils.event'
local UserGroups = require 'features.user_groups'
local Utils = require 'utils.utils'
local Game = require 'utils.game'
local function allowed_to_nuke(player)
if type(player) == "table" then
if type(player) == 'table' then
return player.admin or UserGroups.is_regular(player.name) or ((player.online_time / 216000) > global.scenario.config.nuke_control.nuke_min_time_hours)
elseif type(player) == "number" then
elseif type(player) == 'number' then
return allowed_to_nuke(Game.get_player_by_index(player))
end
end
@ -16,15 +16,15 @@ local function ammo_changed(event)
if allowed_to_nuke(player) then
return
end
local nukes = player.remove_item({name = "atomic-bomb", count = 1000})
local nukes = player.remove_item({name = 'atomic-bomb', count = 1000})
if nukes > 0 then
game.print(player.name .. " tried to use a nuke, but instead dropped it on his foot.")
game.print(player.name .. ' tried to use a nuke, but instead dropped it on his foot.')
local character = player.character
if character and character.valid then
for _, p in ipairs(game.connected_players) do
if p ~= player then
p.add_custom_alert(character, {type = "item", name = "atomic-bomb"}, player.name, true)
p.add_custom_alert(character, {type = 'item', name = 'atomic-bomb'}, player.name, true)
end
end
end
@ -37,17 +37,17 @@ local function on_player_deconstructed_area(event)
if allowed_to_nuke(player) then
return
end
player.remove_item({name = "deconstruction-planner", count = 1000})
player.remove_item({name = 'deconstruction-planner', count = 1000})
--Make them think they arent noticed
Utils.print_except(player.name .. " tried to deconstruct something, but instead deconstructed themself.", player)
player.print("Only regulars can mark things for deconstruction, if you want to deconstruct something you may ask an admin to promote you.")
Utils.print_except(player.name .. ' tried to deconstruct something, but instead deconstructed themself.', player)
player.print('Only regulars can mark things for deconstruction, if you want to deconstruct something you may ask an admin to promote you.')
local character = player.character
if character and character.valid then
for _, p in ipairs(game.connected_players) do
if p ~= player then
p.add_custom_alert(character, {type = "item", name = "deconstruction-planner"}, player.name, true)
p.add_custom_alert(character, {type = 'item', name = 'deconstruction-planner'}, player.name, true)
end
end
end
@ -61,7 +61,7 @@ local function on_player_deconstructed_area(event)
local entities = player.surface.find_entities_filtered {area = area, force = player.force}
if #entities > 1000 then
Utils.print_admins("Warning! " .. player.name .. " just tried to deconstruct " .. tostring(#entities) .. " entities!", false)
Utils.print_admins('Warning! ' .. player.name .. ' just tried to deconstruct ' .. tostring(#entities) .. ' entities!', false)
end
for _, entity in pairs(entities) do
if entity.valid and entity.to_be_deconstructed(Game.get_player_by_index(event.player_index).force) then
@ -72,33 +72,33 @@ 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 == "discharge-defense-remote")
return (name:find('capsule') or name == 'cliff-explosives' or name == 'raw-fish' or name == 'discharge-defense-remote')
end
global.entities_allowed_to_bomb = {
["stone-wall"] = true,
["transport-belt"] = true,
["fast-transport-belt"] = true,
["express-transport-belt"] = true,
["construction-robot"] = true,
["player"] = true,
["gun-turret"] = true,
["laser-turret"] = true,
["flamethrower-turret"] = true,
["rail"] = true,
["rail-chain-signal"] = true,
["rail-signal"] = true,
["tile-ghost"] = true,
["entity-ghost"] = true,
["gate"] = true,
["electric-pole"] = true,
["small-electric-pole"] = true,
["medium-electric-pole"] = true,
["big-electric-pole"] = true,
["logistic-robot"] = true,
["defender"] = true,
["destroyer"] = true,
["distractor"] = true
['stone-wall'] = true,
['transport-belt'] = true,
['fast-transport-belt'] = true,
['express-transport-belt'] = true,
['construction-robot'] = true,
['player'] = true,
['gun-turret'] = true,
['laser-turret'] = true,
['flamethrower-turret'] = true,
['rail'] = true,
['rail-chain-signal'] = true,
['rail-signal'] = true,
['tile-ghost'] = true,
['entity-ghost'] = true,
['gate'] = true,
['electric-pole'] = true,
['small-electric-pole'] = true,
['medium-electric-pole'] = true,
['big-electric-pole'] = true,
['logistic-robot'] = true,
['defender'] = true,
['destroyer'] = true,
['distractor'] = true
}
local function entity_allowed_to_bomb(entity)
@ -113,8 +113,8 @@ local function on_capsule_used(event)
return
end
if item.name == "artillery-targeting-remote" then
player.surface.create_entity {name = "flying-text", text = player.name, color = player.color, position = event.position}
if item.name == 'artillery-targeting-remote' then
player.surface.create_entity {name = 'flying-text', text = player.name, color = player.color, position = event.position}
end
if item_not_sanctioned(item) then
@ -133,12 +133,12 @@ local function on_capsule_used(event)
if count > 8 then
if global.players_warned[event.player_index] then
if global.scenario.config.nuke_control.enable_autokick then
game.ban_player(player, string.format("Damaged %i entities with %s. This action was performed automatically. If you want to contest this ban please visit redmew.com/discord.", count, event.item.name))
game.ban_player(player, string.format('Damaged %i entities with %s. This action was performed automatically. If you want to contest this ban please visit redmew.com/discord.', count, event.item.name))
end
else
global.players_warned[event.player_index] = true
if global.scenario.config.nuke_control.enable_autoban then
game.print(player, string.format("Damaged %i entities with %s -Antigrief", count, event.item.name))
game.print(player, string.format('Damaged %i entities with %s -Antigrief', count, event.item.name))
end
end
end
@ -147,7 +147,7 @@ end
local function on_player_joined(event)
local player = game.players[event.player_index]
if string.match(player.name, "^[Ili1|]+$") then
if string.match(player.name, '^[Ili1|]+$') then
game.ban_player(player) --No reason given, to not give them any hints to change their name
end
end

View File

@ -79,7 +79,7 @@ local function alert(reactor)
end
local function check_reactors()
for _, surface in pairs(game.surfaces) do
for _ in pairs(game.surfaces) do
for i, reactor in pairs(global.reactors) do
if reactor.valid then
if reactor.temperature > 800 then
@ -109,7 +109,7 @@ local function check_reactors()
table.remove(global.reactors, i)
end
end
global.last_reactor_warning = last_reactor_warning
--global.last_reactor_warning = last_reactor_warning
end
end

View File

@ -1,23 +1,24 @@
local Event = require "utils.event"
local Event = require 'utils.event'
local Game = require 'utils.game'
local Utils = require "utils.utils"
local Utils = require 'utils.utils'
local Module = {}
global.player_spawns = {} -- player_index to spawn_name
global.spawns = {} -- spawn_name to x, y, player_online_count
function add_spawn(name, x, y)
if type(name) ~= "string" then
game.print("name must be a string")
Module.add_spawn = function(name, x, y)
if type(name) ~= 'string' then
game.print('name must be a string')
return
end
if type(x) ~= "number" then
game.print("x must be a number")
if type(x) ~= 'number' then
game.print('x must be a number')
return
end
if type(y) ~= "number" then
game.print("y must be a number")
if type(y) ~= 'number' then
game.print('y must be a number')
return
end
@ -53,7 +54,9 @@ local function player_joined_game(event)
spawn_name = get_min_count_spawn_name()
if not spawn_name then return end
if not spawn_name then
return
end
local spawn = global.spawns[spawn_name]
global.player_spawns[index] = spawn_name
@ -68,7 +71,9 @@ local function player_left_game(event)
local spawn_name = global.player_spawns[index]
local spawn = global.spawns[spawn_name]
if not spawn then return end
if not spawn then
return
end
local count = spawn.count
spawn.count = count - 1
@ -79,7 +84,9 @@ local function player_respawned(event)
local spawn_name = global.player_spawns[index]
local spawn = global.spawns[spawn_name]
if not spawn then return end
if not spawn then
return
end
Game.get_player_by_index(index).teleport(spawn)
end
@ -87,15 +94,15 @@ end
local function tp_spawn(player_name, spawn_name)
local player = Game.get_player_by_index(player_name)
if not player then
player_name = player_name or ""
game.player.print("player " .. player_name .. " does not exist.")
player_name = player_name or ''
game.player.print('player ' .. player_name .. ' does not exist.')
return
end
local spawn = global.spawns[spawn_name]
if not spawn then
spawn_name = spawn_name or ""
game.player.print("spawn " .. spawn_name .. " does not exist.")
spawn_name = spawn_name or ''
game.player.print('spawn ' .. spawn_name .. ' does not exist.')
return
end
@ -106,16 +113,16 @@ local function change_spawn(player_name, spawn_name)
local new_spawn = global.spawns[spawn_name]
if not new_spawn then
spawn_name = spawn_name or ""
game.player.print("spawn " .. spawn_name .. " does not exist.")
spawn_name = spawn_name or ''
game.player.print('spawn ' .. spawn_name .. ' does not exist.')
return
end
local player = Game.get_player_by_index(player_name)
if not player then
player_name = player_name or ""
game.player.print("player " .. player_name .. " does not exist.")
player_name = player_name or ''
game.player.print('player ' .. player_name .. ' does not exist.')
return
end
@ -133,34 +140,35 @@ local function change_spawn(player_name, spawn_name)
global.player_spawns[index] = spawn_name
game.player.print(player_name .. " spawn moved to " .. spawn_name)
game.player.print(player_name .. ' spawn moved to ' .. spawn_name)
end
local function print_spawns()
local str = ""
for name, spawn in pairs(global.spawns) do
game.player.print(string.format("%s: (%d, %d), player count = %d", name, spawn.x, spawn.y, spawn.count))
game.player.print(string.format('%s: (%d, %d), player count = %d', name, spawn.x, spawn.y, spawn.count))
end
end
local function print_players_for_spawn(target_spawn_name)
if not global.spawns[target_spawn_name] then
target_spawn_name = target_spawn_name or ""
game.player.print("spawn " .. target_spawn_name .. " does not exist.")
target_spawn_name = target_spawn_name or ''
game.player.print('spawn ' .. target_spawn_name .. ' does not exist.')
return
end
str = ""
local str = ''
for index, spawn_name in pairs(global.player_spawns) do
if target_spawn_name == spawn_name then
local player = Game.get_player_by_index(index)
if player.connected then
str = str .. player.name .. ", "
str = str .. player.name .. ', '
end
end
end
if str == "" then str = "no players" end
if str == '' then
str = 'no players'
end
game.player.print(str)
end
@ -171,33 +179,39 @@ local function tp_spawn_command(cmd)
end
local params = cmd.parameter
if type(params) ~= "string" then
game.player.print("Command failed. Usage: /tpspawn <player>, <spawn_name>")
if type(params) ~= 'string' then
game.player.print('Command failed. Usage: /tpspawn <player>, <spawn_name>')
return
end
local ps = {}
for p in params:gmatch("%S+") do
for p in params:gmatch('%S+') do
table.insert(ps, p)
end
if #ps == 1 then tp_spawn(game.player.name, ps[1]) else tp_spawn(ps[1], ps[2]) end
if #ps == 1 then
tp_spawn(game.player.name, ps[1])
else
tp_spawn(ps[1], ps[2])
end
end
function change_spawn_command(cmd)
local function change_spawn_command(cmd)
if not game.player.admin then
Utils.cant_run(cmd.name)
return
end
local params = cmd.parameter
if type(params) ~= "string" then
game.player.print("Command failed. Usage: /changespawn <player>, <spawn_name>")
if type(params) ~= 'string' then
game.player.print('Command failed. Usage: /changespawn <player>, <spawn_name>')
return
end
local ps = {}
for p in params:gmatch("%S+") do table.insert( ps,p ) end
for p in params:gmatch('%S+') do
table.insert(ps, p)
end
change_spawn(ps[1], ps[2])
end
@ -218,13 +232,15 @@ local function print_players_for_spawn_command(cmd)
end
local params = cmd.parameter
if type(params) ~= "string" then
game.player.print("Command failed. Usage: /playersforspawn <spawn_name>")
if type(params) ~= 'string' then
game.player.print('Command failed. Usage: /playersforspawn <spawn_name>')
return
end
local ps = {}
for p in params:gmatch("%S+") do table.insert( ps,p ) end
for p in params:gmatch('%S+') do
table.insert(ps, p)
end
print_players_for_spawn(ps[1])
end
@ -233,7 +249,9 @@ Event.add(defines.events.on_player_joined_game, player_joined_game)
Event.add(defines.events.on_player_left_game, player_left_game)
Event.add(defines.events.on_player_respawned, player_respawned)
commands.add_command("tpspawn", "<player> <spawn_name> teleports a player to the spawn point (Admins only)", tp_spawn_command)
commands.add_command("changespawn", "<player> <spawn_name> changes the spawn point for a player (Admins only)", change_spawn_command)
commands.add_command("printspawns", "prints info on all spawn points (Admins only)", print_spawns_command)
commands.add_command("printplayersforspawn", "<spawn_name> prints all the connected players for a spawn (Admins only)", print_players_for_spawn_command)
commands.add_command('tpspawn', '<player> <spawn_name> teleports a player to the spawn point (Admins only)', tp_spawn_command)
commands.add_command('changespawn', '<player> <spawn_name> changes the spawn point for a player (Admins only)', change_spawn_command)
commands.add_command('printspawns', 'prints info on all spawn points (Admins only)', print_spawns_command)
commands.add_command('printplayersforspawn', '<spawn_name> prints all the connected players for a spawn (Admins only)', print_players_for_spawn_command)
return Module

View File

@ -9,10 +9,7 @@ local train_perk_flag = Donators.donator_perk_flags.train
local saviour_token_name = 'small-plane' -- item name for what saves players
local saviour_timeout = 180 -- number of ticks players are train immune after getting hit (roughly)
table.insert(
Market_items, 3,
{price = {{Market_items.market_item, 100}}, offer = {type = 'nothing', effect_description = 'Train Immunity (+1 ' .. saviour_token_name .. ')\nEach ' .. saviour_token_name .. ' in your inventory will save you\nfrom being killed by a train once\n\nPrice: 100 '..Market_items.market_item..'s'}, item = saviour_token_name}
)
table.insert(Market_items, 3, {price = {{Market_items.market_item, 100}}, offer = {type = 'nothing', effect_description = 'Train Immunity (+1 ' .. saviour_token_name .. ')\nEach ' .. saviour_token_name .. ' in your inventory will save you\nfrom being killed by a train once\n\nPrice: 100 ' .. Market_items.market_item .. 's'}, item = saviour_token_name})
local remove_stack = {name = saviour_token_name, count = 1}

View File

@ -3,7 +3,9 @@ local Game = require 'utils.game'
local function player_built_entity(event)
local entity = event.created_entity
if not entity or not entity.valid then return end
if not entity or not entity.valid then
return
end
if entity.name == 'train-stop' then
local y = math.random(1, 3)

View File

@ -1,7 +1,7 @@
local global = {}
local Task = require 'utils.Task'
local Game = require "utils.game"
local Event = require "utils.event"
local Game = require 'utils.game'
local Event = require 'utils.event'
local Token = require 'utils.global_token'
local Utils = require 'utils.utils'
@ -126,7 +126,7 @@ end
--- Cleans the walkabout status off players who disconnected during walkabout.
-- Restores their original force, character, and position.
function clean_on_join(event)
local function clean_on_join(event)
local player = Game.get_player_by_index(event.player_index)
local index = player.index
if global.walking[index] then
@ -134,7 +134,6 @@ function clean_on_join(event)
local walking_storage = global.walking_storage
for _, s in pairs(walking_storage) do
if s.index == index then
local walkabout_character = player.character
if walkabout_character and walkabout_character.valid then
walkabout_character.destroy()

View File

@ -3,7 +3,7 @@ local Token = require 'utils.global_token'
local Task = require 'utils.Task'
local PlayerStats = require 'features.player_stats'
local Game = require 'utils.game'
local Utils = require "utils.utils"
local Utils = require 'utils.utils'
local market_items = require 'resources.market_items'
@ -103,8 +103,7 @@ local function boost_player_runningspeed(player, market)
[3] = 'Kungfu Master %s defended the village and was awarded a lv.3 speed boost!',
[4] = 'Travelled at the speed of light. %s saw a blackhole. Oops.'
}
global.player_speed_boost_records[player.index].boost_lvl =
1 + global.player_speed_boost_records[player.index].boost_lvl
global.player_speed_boost_records[player.index].boost_lvl = 1 + global.player_speed_boost_records[player.index].boost_lvl
player.character_running_speed_modifier = 1 + player.character_running_speed_modifier
game.print(string.format(boost_msg[global.player_speed_boost_records[player.index].boost_lvl], player.name))
if global.player_speed_boost_records[player.index].boost_lvl >= 4 then
@ -136,8 +135,7 @@ local function boost_player_miningspeed(player, market)
[3] = 'Wood fiend, %s, has picked up a massive chain saw and is awarded a lv.3 mining boost!',
[4] = 'Better learn to control that saw, %s, chopped off their legs. Oops.'
}
global.player_mining_boost_records[player.index].boost_lvl =
1 + global.player_mining_boost_records[player.index].boost_lvl
global.player_mining_boost_records[player.index].boost_lvl = 1 + global.player_mining_boost_records[player.index].boost_lvl
player.character_mining_speed_modifier = 1 + player.character_mining_speed_modifier
game.print(string.format(boost_msg[global.player_mining_boost_records[player.index].boost_lvl], player.name))
if global.player_mining_boost_records[player.index].boost_lvl >= 4 then

View File

@ -105,8 +105,9 @@ end
map = b.apply_effect(map, effect)
require 'features.spawn_control'
add_spawn('left', -88, -88)
add_spawn('right', 88, 88)
local Spawn_Control = require 'features.spawn_control'
Spawn_Control.add_spawn('left', -88, -88)
Spawn_Control.add_spawn('right', 88, 88)
return map