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:
parent
a1dae9ee91
commit
c9369c3d14
@ -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'
|
||||
|
||||
|
@ -1,185 +1,211 @@
|
||||
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})
|
||||
global.ag_surface.always_day = true
|
||||
|
||||
end)
|
||||
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
|
||||
)
|
||||
|
||||
local function is_mocked(entity)
|
||||
return rawget(entity, 'mock')
|
||||
return rawget(entity, 'mock')
|
||||
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
|
||||
e.destroy()
|
||||
local new_entity = nil
|
||||
for _, e in ipairs(surface.find_entities_filtered {position = entity.position}) do
|
||||
if replace or e.type == 'entity-ghost' then
|
||||
e.destroy()
|
||||
end
|
||||
end
|
||||
end
|
||||
local entities_to_be_replaced = surface.find_entities_filtered{position = entity.position}
|
||||
if (replace or #entities_to_be_replaced == 0 or entities_to_be_replaced[1].type == entity.type) then
|
||||
new_entity = surface.create_entity{name = entity.name, position = entity.position, force = entity.force, direction = entity.direction}
|
||||
if new_entity then
|
||||
if not is_mocked(entity) then
|
||||
new_entity.copy_settings(entity)
|
||||
end
|
||||
if player then
|
||||
new_entity.last_user = player
|
||||
end
|
||||
local entities_to_be_replaced = surface.find_entities_filtered {position = entity.position}
|
||||
if (replace or #entities_to_be_replaced == 0 or entities_to_be_replaced[1].type == entity.type) then
|
||||
new_entity = surface.create_entity {name = entity.name, position = entity.position, force = entity.force, direction = entity.direction}
|
||||
if new_entity then
|
||||
if not is_mocked(entity) then
|
||||
new_entity.copy_settings(entity)
|
||||
end
|
||||
if player then
|
||||
new_entity.last_user = player
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return new_entity
|
||||
return new_entity
|
||||
end
|
||||
|
||||
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}})
|
||||
end
|
||||
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}})
|
||||
end
|
||||
end
|
||||
event.surface.set_tiles(tiles)
|
||||
end
|
||||
end
|
||||
event.surface.set_tiles(tiles)
|
||||
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 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
|
||||
if entity.last_user then
|
||||
global.original_last_users_by_ent_pos[get_position_str(entity.position)] = entity.last_user.index
|
||||
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 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
|
||||
if entity.last_user then
|
||||
global.original_last_users_by_ent_pos[get_position_str(entity.position)] = entity.last_user.index
|
||||
end
|
||||
end
|
||||
|
||||
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)
|
||||
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
|
||||
)
|
||||
|
||||
local function get_pre_rotate_direction(entity)
|
||||
--Some entities have 8 rotation steps and some have 4. So a mathmatical reverse is not possible
|
||||
entity.rotate{reverse=true}
|
||||
local direction = entity.direction
|
||||
entity.rotate()
|
||||
return direction
|
||||
--Some entities have 8 rotation steps and some have 4. So a mathmatical reverse is not possible
|
||||
entity.rotate {reverse = true}
|
||||
local direction = entity.direction
|
||||
entity.rotate()
|
||||
return direction
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_player_rotated_entity, function(event)
|
||||
local entity = event.entity
|
||||
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)}
|
||||
event.entity = mock_entity
|
||||
on_entity_changed(event)
|
||||
end
|
||||
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)
|
||||
}
|
||||
event.entity = mock_entity
|
||||
on_entity_changed(event)
|
||||
end
|
||||
end
|
||||
)
|
||||
Event.add(defines.events.on_pre_entity_settings_pasted, on_entity_changed)
|
||||
|
||||
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
|
||||
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
|
||||
local items = event.entity.get_inventory(defines.inventory.chest).get_contents()
|
||||
if items then
|
||||
for item, n in pairs(items) do
|
||||
new_entity.insert{name = item, count = n}
|
||||
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
|
||||
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
|
||||
local items = event.entity.get_inventory(defines.inventory.chest).get_contents()
|
||||
if items then
|
||||
for item, n in pairs(items) do
|
||||
new_entity.insert {name = item, count = n}
|
||||
end
|
||||
end
|
||||
end
|
||||
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)
|
||||
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)
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
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
|
||||
|
||||
--Remove all items from all surfaces that player placed an entity on
|
||||
for _,surface in pairs(game.surfaces) do
|
||||
if surface ~= global.ag_surface then
|
||||
for _,e in ipairs(surface.find_entities_filtered{force = player.force.name}) do
|
||||
if e.last_user == player then
|
||||
e.destroy()
|
||||
end
|
||||
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
|
||||
end
|
||||
|
||||
for _,e in ipairs(global.ag_surface.find_entities_filtered{}) do
|
||||
if e.last_user == player then
|
||||
--Place removed entity IF no collision is detected
|
||||
local last_user = global.original_last_users_by_ent_pos[get_position_str(e.position)]
|
||||
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
|
||||
local items = e.get_inventory(defines.inventory.chest).get_contents()
|
||||
if items then
|
||||
for item, n in pairs(items) do
|
||||
new_entity.insert{name = item, count = n}
|
||||
--Remove all items from all surfaces that player placed an entity on
|
||||
for _, surface in pairs(game.surfaces) do
|
||||
if surface ~= global.ag_surface then
|
||||
for _, e in ipairs(surface.find_entities_filtered {force = player.force.name}) do
|
||||
if e.last_user == player then
|
||||
e.destroy()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for _, e in ipairs(global.ag_surface.find_entities_filtered {}) do
|
||||
if e.last_user == player then
|
||||
--Place removed entity IF no collision is detected
|
||||
local last_user = global.original_last_users_by_ent_pos[get_position_str(e.position)]
|
||||
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
|
||||
local items = e.get_inventory(defines.inventory.chest).get_contents()
|
||||
if items then
|
||||
for item, n in pairs(items) do
|
||||
new_entity.insert {name = item, count = n}
|
||||
end
|
||||
end
|
||||
end
|
||||
e.destroy() --destory entity only if a new entity was created
|
||||
end
|
||||
end
|
||||
end
|
||||
e.destroy() --destory entity only if a new entity was created
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Module.antigrief_surface_tp = function()
|
||||
if game.player then
|
||||
if game.player.surface == global.ag_surface then
|
||||
game.player.teleport(game.player.position, game.surfaces.nauvis)
|
||||
else
|
||||
game.player.teleport(game.player.position, global.ag_surface)
|
||||
if game.player then
|
||||
if game.player.surface == global.ag_surface then
|
||||
game.player.teleport(game.player.position, game.surfaces.nauvis)
|
||||
else
|
||||
game.player.teleport(game.player.position, global.ag_surface)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Module.count_removed_entities = function(player)
|
||||
return #Utils.find_entities_by_last_user(player, global.ag_surface)
|
||||
return #Utils.find_entities_by_last_user(player, global.ag_surface)
|
||||
end
|
||||
|
||||
return Module
|
||||
|
@ -1,11 +1,13 @@
|
||||
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
|
||||
|
||||
local function biter_kill_counter(event)
|
||||
if event.entity.force.name == "enemy" then
|
||||
global.score_biter_total_kills = global.score_biter_total_kills + 1
|
||||
end
|
||||
if not global.score_biter_total_kills then
|
||||
global.score_biter_total_kills = 0
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_entity_died, biter_kill_counter)
|
||||
local function biter_kill_counter(event)
|
||||
if event.entity.force.name == 'enemy' then
|
||||
global.score_biter_total_kills = global.score_biter_total_kills + 1
|
||||
end
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_entity_died, biter_kill_counter)
|
||||
|
@ -1,47 +1,59 @@
|
||||
local Event = require "utils.event"
|
||||
local Event = require 'utils.event'
|
||||
local Game = require 'utils.game'
|
||||
|
||||
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)
|
||||
end
|
||||
end)
|
||||
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)
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
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)
|
||||
end
|
||||
end)
|
||||
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)
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
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)
|
||||
end
|
||||
end)
|
||||
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)
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
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)
|
||||
end
|
||||
end)
|
||||
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)
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
function heartbeat()
|
||||
--Do nothing, this is just so managepgm can call something as a heartbeat without any errors occurring
|
||||
--Do nothing, this is just so managepgm can call something as a heartbeat without any errors occurring
|
||||
end
|
||||
|
||||
function playerQuery()
|
||||
if #game.connected_players == 0 then
|
||||
print("output$pquery$none")
|
||||
else
|
||||
local response = "output&pquery$"
|
||||
for _,player in pairs(game.connected_players) do
|
||||
local playerdata = player.name .. "-" .. player.force.name
|
||||
response = response .. playerdata .. ","
|
||||
end
|
||||
print(response:sub(1,#str-1))
|
||||
end
|
||||
if #game.connected_players == 0 then
|
||||
print('output$pquery$none')
|
||||
else
|
||||
local response = 'output&pquery$'
|
||||
for _, player in pairs(game.connected_players) do
|
||||
local playerdata = player.name .. '-' .. player.force.name
|
||||
response = response .. playerdata .. ','
|
||||
end
|
||||
print(response:sub(1, #str - 1))
|
||||
end
|
||||
end
|
||||
|
@ -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))
|
||||
|
@ -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
|
||||
|
@ -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',
|
||||
|
@ -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
|
||||
@ -270,7 +269,7 @@ local function market_item_purchased(event)
|
||||
if event.offer_index == 3 then -- train saviour item
|
||||
local player = Game.get_player_by_index(player_index)
|
||||
local train_savior_item = Market_items[offer_index].item
|
||||
player.insert{name=train_savior_item, count=event.count}
|
||||
player.insert {name = train_savior_item, count = event.count}
|
||||
end
|
||||
|
||||
--[[
|
||||
|
@ -1,61 +1,63 @@
|
||||
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)
|
||||
local delta_x = target.position.x - follower.position.x
|
||||
local delta_y = follower.position.y - target.position.y --reversed x axis
|
||||
local a = delta_y/delta_x
|
||||
if a >= -1.5 and a < -0.5 then
|
||||
--SE OR NW
|
||||
if delta_x > 0 then
|
||||
return defines.direction.southeast
|
||||
local delta_x = target.position.x - follower.position.x
|
||||
local delta_y = follower.position.y - target.position.y --reversed x axis
|
||||
local a = delta_y / delta_x
|
||||
if a >= -1.5 and a < -0.5 then
|
||||
--SE OR NW
|
||||
if delta_x > 0 then
|
||||
return defines.direction.southeast
|
||||
else
|
||||
return defines.direction.northwest
|
||||
end
|
||||
elseif a >= -0.5 and a < 0.5 then
|
||||
--E OR W
|
||||
if delta_x > 0 then
|
||||
return defines.direction.east
|
||||
else
|
||||
return defines.direction.west
|
||||
end
|
||||
elseif a >= 0.5 and a < 1.5 then
|
||||
--NE OR SW
|
||||
if delta_x > 0 then
|
||||
return defines.direction.northeast
|
||||
else
|
||||
return defines.direction.southwest
|
||||
end
|
||||
else
|
||||
return defines.direction.northwest
|
||||
-- N or S
|
||||
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
|
||||
return defines.direction.south
|
||||
end
|
||||
end
|
||||
elseif a >= -0.5 and a < 0.5 then
|
||||
--E OR W
|
||||
if delta_x > 0 then
|
||||
return defines.direction.east
|
||||
else
|
||||
return defines.direction.west
|
||||
end
|
||||
elseif a >= 0.5 and a < 1.5 then
|
||||
--NE OR SW
|
||||
if delta_x > 0 then
|
||||
return defines.direction.northeast
|
||||
else
|
||||
return defines.direction.southwest
|
||||
end
|
||||
else
|
||||
-- N or S
|
||||
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
|
||||
return defines.direction.south
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function walk_on_tick()
|
||||
if global.follows.n_entries > 0 then
|
||||
for k,v in pairs(global.follows) do
|
||||
local follower = game.playesr[k]
|
||||
local target = game.players[v]
|
||||
if follower ~= nil and target ~= nil then
|
||||
local d = Utils.distance(follower, target)
|
||||
if follower.connected and target.connected and d < 32 then
|
||||
if d > 5 then
|
||||
direction = get_direction(follower, target)
|
||||
follower.walking_state = {walking = true, direction = direction}
|
||||
end
|
||||
else
|
||||
global.follows[follower.name] = nil
|
||||
global.follows.n_entries = global.follows.n_entries - 1
|
||||
if global.follows.n_entries > 0 then
|
||||
for k, v in pairs(global.follows) do
|
||||
local follower = game.playesr[k]
|
||||
local target = game.players[v]
|
||||
if follower ~= nil and target ~= nil then
|
||||
local d = Utils.distance(follower, target)
|
||||
if follower.connected and target.connected and d < 32 then
|
||||
if d > 5 then
|
||||
direction = get_direction(follower, target)
|
||||
follower.walking_state = {walking = true, direction = direction}
|
||||
end
|
||||
else
|
||||
global.follows[follower.name] = nil
|
||||
global.follows.n_entries = global.follows.n_entries - 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -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({
|
||||
forces = forces,
|
||||
next_level_cap_calculator = next_level_cap_calculator,
|
||||
}, function (tbl)
|
||||
forces = tbl.forces
|
||||
next_level_cap_calculator = tbl.next_level_cap_calculator
|
||||
end)
|
||||
Global.register(
|
||||
{
|
||||
forces = forces,
|
||||
next_level_cap_calculator = next_level_cap_calculator
|
||||
},
|
||||
function(tbl)
|
||||
forces = tbl.forces
|
||||
next_level_cap_calculator = tbl.next_level_cap_calculator
|
||||
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
|
||||
|
||||
@ -75,7 +78,7 @@ end
|
||||
---@param lua_force_name string|nil only register for this force (optional)
|
||||
function ForceControlBuilder.register(level_matches, callback, lua_force_name)
|
||||
if game then
|
||||
error('You can only register level up callbacks before the game is initialized')
|
||||
error('You can only register level up callbacks before the game is initialized')
|
||||
end
|
||||
assert_type('function', level_matches, 'level_matches of function ForceControl.register_reward')
|
||||
assert_type('function', callback, 'callback of function ForceControlBuilder.register')
|
||||
@ -92,17 +95,20 @@ function ForceControlBuilder.register(level_matches, callback, lua_force_name)
|
||||
return
|
||||
end
|
||||
|
||||
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')
|
||||
end
|
||||
if force ~= event.force then
|
||||
return
|
||||
end
|
||||
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')
|
||||
end
|
||||
if force ~= event.force then
|
||||
return
|
||||
end
|
||||
|
||||
on_level_up(event)
|
||||
end)
|
||||
on_level_up(event)
|
||||
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)
|
||||
return level == level_reached
|
||||
end, callback, lua_force_name)
|
||||
ForceControlBuilder.register(
|
||||
function(level_reached)
|
||||
return level == level_reached
|
||||
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
|
||||
|
||||
|
@ -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'}})
|
||||
|
@ -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
|
||||
|
@ -18,4 +18,4 @@ Event.add(
|
||||
player.color = color_data.color
|
||||
player.chat_color = color_data.chat_color or color_data.color
|
||||
end
|
||||
)
|
||||
)
|
||||
|
@ -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
|
||||
|
||||
|
@ -1,27 +1,28 @@
|
||||
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
|
||||
|
||||
global.spawns[name] = { x = x, y = y, count = 0}
|
||||
global.spawns[name] = {x = x, y = y, count = 0}
|
||||
end
|
||||
|
||||
local function get_min_count_spawn_name()
|
||||
@ -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,79 +140,86 @@ 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
|
||||
|
||||
local function tp_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: /tpspawn <player>, <spawn_name>")
|
||||
Utils.cant_run(cmd.name)
|
||||
return
|
||||
end
|
||||
|
||||
local ps ={}
|
||||
for p in params:gmatch("%S+") do
|
||||
table.insert( ps,p )
|
||||
local params = cmd.parameter
|
||||
if type(params) ~= 'string' then
|
||||
game.player.print('Command failed. Usage: /tpspawn <player>, <spawn_name>')
|
||||
return
|
||||
end
|
||||
|
||||
if #ps == 1 then tp_spawn(game.player.name, ps[1]) else tp_spawn(ps[1], ps[2]) end
|
||||
local ps = {}
|
||||
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
|
||||
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>")
|
||||
Utils.cant_run(cmd.name)
|
||||
return
|
||||
end
|
||||
|
||||
local ps ={}
|
||||
for p in params:gmatch("%S+") do table.insert( ps,p ) end
|
||||
local params = cmd.parameter
|
||||
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
|
||||
|
||||
change_spawn(ps[1], ps[2])
|
||||
end
|
||||
|
||||
local function print_spawns_command(cmd)
|
||||
if not game.player.admin then
|
||||
Utils.cant_run(cmd.name)
|
||||
return
|
||||
Utils.cant_run(cmd.name)
|
||||
return
|
||||
end
|
||||
|
||||
print_spawns()
|
||||
@ -213,18 +227,20 @@ end
|
||||
|
||||
local function print_players_for_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: /playersforspawn <spawn_name>")
|
||||
Utils.cant_run(cmd.name)
|
||||
return
|
||||
end
|
||||
|
||||
local ps ={}
|
||||
for p in params:gmatch("%S+") do table.insert( ps,p ) end
|
||||
local params = cmd.parameter
|
||||
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
|
||||
|
||||
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
|
||||
|
@ -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}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -1,7 +1,7 @@
|
||||
local global ={}
|
||||
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,15 +126,14 @@ 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
|
||||
global.walking[index] = false
|
||||
local walking_storage = global.walking_storage
|
||||
for _, s in pairs (walking_storage) do
|
||||
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()
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user