mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-03-03 14:53:01 +02:00
commit
3eb8be8b34
@ -1,5 +1,6 @@
|
||||
local Event = require "utils.event"
|
||||
local Utils = require "utils.utils"
|
||||
local Game = require 'utils.game'
|
||||
|
||||
global.original_last_users_by_ent_pos = {}
|
||||
|
||||
@ -53,7 +54,7 @@ end
|
||||
|
||||
local function on_entity_changed(event)
|
||||
local entity = event.entity or event.destination
|
||||
local player = game.players[event.player_index]
|
||||
local player = Game.players[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)
|
||||
@ -92,7 +93,7 @@ Event.add(defines.events.on_player_rotated_entity, function(event)
|
||||
--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.players[1], force = entity.force, direction = get_pre_rotate_direction(entity)}
|
||||
last_user = Game.players[1], force = entity.force, direction = get_pre_rotate_direction(entity)}
|
||||
event.entity = mock_entity
|
||||
on_entity_changed(event)
|
||||
end
|
||||
@ -128,7 +129,7 @@ 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.players[player] end
|
||||
elseif type(player) == "number" then player = Game.players[player] end
|
||||
|
||||
--Remove all items from all surfaces that player placed an entity on
|
||||
for _,surface in pairs(game.surfaces) do
|
||||
|
@ -3,6 +3,7 @@
|
||||
local Event = require 'utils.event'
|
||||
local Token = require 'utils.global_token'
|
||||
local Gui = require 'utils.gui'
|
||||
local Game = require 'utils.game'
|
||||
|
||||
local function getBlueprintCursorStack(player)
|
||||
local cursor = player.cursor_stack
|
||||
@ -265,7 +266,7 @@ local filter_table_clear_name = Gui.uid_name()
|
||||
local clear_all_filters_name = Gui.uid_name()
|
||||
|
||||
local function player_joined(event)
|
||||
local player = game.players[event.player_index]
|
||||
local player = Game.players[event.player_index]
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
17
bot.lua
17
bot.lua
@ -1,30 +1,31 @@
|
||||
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.players[player].name ~= nil then
|
||||
print("PLAYER$die," .. player .. "," .. game.players[player].name .. "," .. game.players[player].force.name)
|
||||
if Game.players[player].name ~= nil then
|
||||
print("PLAYER$die," .. player .. "," .. Game.players[player].name .. "," .. Game.players[player].force.name)
|
||||
end
|
||||
end)
|
||||
|
||||
Event.add(defines.events.on_player_respawned, function (event)
|
||||
local player = event.player_index
|
||||
if game.players[player].name ~= nil then
|
||||
print("PLAYER$respawn," .. player .. "," .. game.players[player].name .. "," .. game.players[player].force.name)
|
||||
if Game.players[player].name ~= nil then
|
||||
print("PLAYER$respawn," .. player .. "," .. Game.players[player].name .. "," .. Game.players[player].force.name)
|
||||
end
|
||||
end)
|
||||
|
||||
Event.add(defines.events.on_player_joined_game, function (event)
|
||||
local player = event.player_index
|
||||
if game.players[player].name ~= nil then
|
||||
print("PLAYER$join," .. player .. "," .. game.players[player].name .. "," .. game.players[player].force.name)
|
||||
if Game.players[player].name ~= nil then
|
||||
print("PLAYER$join," .. player .. "," .. Game.players[player].name .. "," .. Game.players[player].force.name)
|
||||
end
|
||||
end)
|
||||
|
||||
Event.add(defines.events.on_player_left_game, function (event)
|
||||
local player = event.player_index
|
||||
if game.players[player].name ~= nil then
|
||||
print("PLAYER$leave," .. player .. "," .. game.players[player].name .. "," .. game.players[player].force.name)
|
||||
if Game.players[player].name ~= nil then
|
||||
print("PLAYER$leave," .. player .. "," .. Game.players[player].name .. "," .. Game.players[player].force.name)
|
||||
end
|
||||
end)
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
_DEBUG = false
|
||||
_DEBUG = true
|
||||
MARKET_ITEM = 'coin'
|
||||
|
||||
global.scenario = {}
|
||||
|
20
control.lua
20
control.lua
@ -1,6 +1,9 @@
|
||||
require 'config'
|
||||
require 'utils.utils'
|
||||
require 'utils.list_utils'
|
||||
|
||||
local Game = require 'utils.game'
|
||||
|
||||
require 'user_groups'
|
||||
require 'custom_commands'
|
||||
require 'base_data'
|
||||
@ -28,11 +31,12 @@ require 'paint'
|
||||
require 'score'
|
||||
require 'popup'
|
||||
|
||||
|
||||
local Event = require 'utils.event'
|
||||
local Donators = require 'resources.donators'
|
||||
|
||||
local function player_created(event)
|
||||
local player = game.players[event.player_index]
|
||||
local player = Game.players[event.player_index]
|
||||
|
||||
if not player or not player.valid then
|
||||
return
|
||||
@ -124,13 +128,13 @@ local function hodor(event)
|
||||
end
|
||||
|
||||
-- player_index is nil if the message came from the server,
|
||||
-- and indexing game.players with nil is apparently an error.
|
||||
-- and indexing Game.players with nil is apparently an error.
|
||||
local player_index = event.player_index
|
||||
if not player_index then
|
||||
return
|
||||
end
|
||||
|
||||
local player = game.players[event.player_index]
|
||||
local player = Game.players[event.player_index]
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
@ -152,7 +156,7 @@ local function hodor(event)
|
||||
end
|
||||
|
||||
local function player_joined(event)
|
||||
local player = game.players[event.player_index]
|
||||
local player = Game.players[event.player_index]
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
@ -177,7 +181,7 @@ Event.add(
|
||||
local p_index = event.player_index
|
||||
local name
|
||||
if p_index then
|
||||
name = game.players[event.player_index].name
|
||||
name = Game.players[event.player_index].name
|
||||
else
|
||||
name = '<server>'
|
||||
end
|
||||
@ -242,7 +246,7 @@ Event.add(
|
||||
defines.events.on_player_crafted_item,
|
||||
function(event)
|
||||
local pi = event.player_index
|
||||
local p = game.players[pi]
|
||||
local p = Game.players[pi]
|
||||
|
||||
if not p or not p.valid or not p.cheat_mode then
|
||||
return
|
||||
@ -273,7 +277,7 @@ Event.add(
|
||||
|
||||
function print_cheated_items()
|
||||
local res = {}
|
||||
local players = game.players
|
||||
local players = Game.players
|
||||
|
||||
for pi, data in pairs(global.cheated_items) do
|
||||
res[players[pi].name] = data
|
||||
@ -289,7 +293,7 @@ Event.add(
|
||||
if not player_index then
|
||||
return
|
||||
end
|
||||
local player = game.players[player_index]
|
||||
local player = Game.players[player_index]
|
||||
local command = event.parameters or ''
|
||||
if player.name:lower() == 'gotze' and string.find(command, 'insert') then
|
||||
string.gsub(
|
||||
|
@ -2,6 +2,7 @@ local Event = require 'utils.event'
|
||||
local Global = require 'utils.global'
|
||||
local Task = require 'utils.Task'
|
||||
local Token = require 'utils.global_token'
|
||||
local Game = require 'utils.game'
|
||||
|
||||
local player_corpses = {}
|
||||
|
||||
@ -14,7 +15,7 @@ Global.register(
|
||||
|
||||
local function player_died(event)
|
||||
local player_index = event.player_index
|
||||
local player = game.players[player_index]
|
||||
local player = Game.players[player_index]
|
||||
|
||||
if not player or not player.valid then
|
||||
return
|
||||
|
@ -3,6 +3,7 @@ local Event = require 'utils.event'
|
||||
local Token = require 'utils.global_token'
|
||||
local UserGroups = require 'user_groups'
|
||||
local Utils = require 'utils.utils'
|
||||
local Game = require 'utils.game'
|
||||
--local Antigrief = require 'antigrief'
|
||||
|
||||
function player_print(str)
|
||||
@ -23,12 +24,12 @@ local function invoke(cmd)
|
||||
return
|
||||
end
|
||||
local target = cmd['parameter']
|
||||
if target == nil or game.players[target] == nil then
|
||||
if target == nil or Game.players[target] == nil then
|
||||
player_print('Unknown player.')
|
||||
return
|
||||
end
|
||||
local pos = game.player.surface.find_non_colliding_position('player', game.player.position, 0, 1)
|
||||
game.players[target].teleport({pos.x, pos.y}, game.player.surface)
|
||||
Game.players[target].teleport({pos.x, pos.y}, game.player.surface)
|
||||
game.print(target .. ', get your ass over here!')
|
||||
end
|
||||
|
||||
@ -38,12 +39,12 @@ local function teleport_player(cmd)
|
||||
return
|
||||
end
|
||||
local target = cmd['parameter']
|
||||
if target == nil or game.players[target] == nil then
|
||||
if target == nil or Game.players[target] == nil then
|
||||
player_print('Unknown player.')
|
||||
return
|
||||
end
|
||||
local surface = game.players[target].surface
|
||||
local pos = surface.find_non_colliding_position('player', game.players[target].position, 0, 1)
|
||||
local surface = Game.players[target].surface
|
||||
local pos = surface.find_non_colliding_position('player', Game.players[target].position, 0, 1)
|
||||
game.player.teleport(pos, surface)
|
||||
game.print(target .. "! watcha doin'?!")
|
||||
end
|
||||
@ -83,7 +84,7 @@ local function kill(cmd)
|
||||
local param = cmd.parameter
|
||||
local target
|
||||
if param then
|
||||
target = game.players[param]
|
||||
target = Game.players[param]
|
||||
if not target then
|
||||
player_print(table.concat {"Sorry, player '", param, "' was not found."})
|
||||
return
|
||||
@ -178,7 +179,7 @@ local function walkabout(cmd)
|
||||
duration = 15
|
||||
end
|
||||
|
||||
local player = game.players[player_name]
|
||||
local player = Game.players[player_name]
|
||||
if player == nil or not player.valid or global.walking[player.index] then
|
||||
player_print(player_name .. ' could not go on a walkabout.')
|
||||
return
|
||||
@ -267,7 +268,7 @@ local function follow(cmd)
|
||||
log("<Server can't do that.")
|
||||
return
|
||||
end
|
||||
if cmd.parameter ~= nil and game.players[cmd.parameter] ~= nil then
|
||||
if cmd.parameter ~= nil and Game.players[cmd.parameter] ~= nil then
|
||||
global.follows[game.player.name] = cmd.parameter
|
||||
global.follows.n_entries = global.follows.n_entries + 1
|
||||
else
|
||||
@ -297,7 +298,7 @@ local function built_entity(event)
|
||||
return
|
||||
end
|
||||
|
||||
game.players[index].teleport(entity.position)
|
||||
Game.players[index].teleport(entity.position)
|
||||
entity.destroy()
|
||||
end
|
||||
end
|
||||
@ -370,7 +371,7 @@ local function tempban(cmd)
|
||||
player_print('Tempban failed. Usage: /tempban <player> <minutes> Temporarily bans a player.')
|
||||
return
|
||||
end
|
||||
if not game.players[params[1]] then
|
||||
if not Game.players[params[1]] then
|
||||
player_print("Player doesn't exist.")
|
||||
return
|
||||
end
|
||||
@ -429,23 +430,23 @@ local function undo(cmd)
|
||||
cant_run(cmd.name)
|
||||
return
|
||||
end
|
||||
if cmd.parameter and game.players[cmd.parameter] then
|
||||
if cmd.parameter and Game.players[cmd.parameter] then
|
||||
if
|
||||
not global.undo_warned_players[game.player.index] or
|
||||
global.undo_warned_players[game.player.index] ~= game.players[cmd.parameter].index
|
||||
global.undo_warned_players[game.player.index] ~= Game.players[cmd.parameter].index
|
||||
then
|
||||
global.undo_warned_players[game.player.index] = game.players[cmd.parameter].index
|
||||
global.undo_warned_players[game.player.index] = Game.players[cmd.parameter].index
|
||||
game.player.print(
|
||||
string.format(
|
||||
'Warning! You are about to remove %s entities and restore %s entities.',
|
||||
#Utils.find_entities_by_last_user(game.players[cmd.parameter], game.surfaces.nauvis),
|
||||
Antigrief.count_removed_entities(game.players[cmd.parameter])
|
||||
#Utils.find_entities_by_last_user(Game.players[cmd.parameter], game.surfaces.nauvis),
|
||||
Antigrief.count_removed_entities(Game.players[cmd.parameter])
|
||||
)
|
||||
)
|
||||
game.player.print('To execute the command please run it again.')
|
||||
return
|
||||
end
|
||||
Antigrief.undo(game.players[cmd.parameter])
|
||||
Antigrief.undo(Game.players[cmd.parameter])
|
||||
game.print(string.format('Undoing everything %s did...', cmd.parameter))
|
||||
global.undo_warned_players[game.player.index] = nil
|
||||
else
|
||||
@ -472,7 +473,7 @@ local function find_player(cmd)
|
||||
return
|
||||
end
|
||||
|
||||
local target = game.players[name]
|
||||
local target = Game.players[name]
|
||||
if not target then
|
||||
player.print('player ' .. name .. ' not found')
|
||||
return
|
||||
@ -504,7 +505,7 @@ local function jail_player(cmd)
|
||||
return
|
||||
end
|
||||
|
||||
local target_player = game.players[target]
|
||||
local target_player = Game.players[target]
|
||||
|
||||
if not target_player then
|
||||
player_print('Unknown player.')
|
||||
@ -566,7 +567,7 @@ local function unjail_player(cmd)
|
||||
return
|
||||
end
|
||||
|
||||
local target_player = game.players[target]
|
||||
local target_player = Game.players[target]
|
||||
if not target_player then
|
||||
player_print('Unknown player.')
|
||||
return
|
||||
@ -723,7 +724,7 @@ local function report(cmd)
|
||||
return nil
|
||||
end
|
||||
local reported_player_name = params[1] or ''
|
||||
local reported_player = game.players[reported_player_name]
|
||||
local reported_player = Game.players[reported_player_name]
|
||||
|
||||
if not reported_player then
|
||||
reporting_player.print(reported_player_name .. ' does not exist.')
|
||||
@ -740,7 +741,7 @@ commands.add_command(
|
||||
'Shows user reports (Admins only)',
|
||||
function(event)
|
||||
if game.player and game.player.admin then
|
||||
Report.show_reports(game.players[event.player_index])
|
||||
Report.show_reports(Game.players[event.player_index])
|
||||
end
|
||||
end
|
||||
)
|
||||
|
@ -20,6 +20,7 @@ local Event = require 'utils.event'
|
||||
local Token = require 'utils.global_token'
|
||||
local Task = require 'utils.Task'
|
||||
local PlayerStats = require 'player_stats'
|
||||
local Game = require 'utils.game'
|
||||
|
||||
local Market_items = require 'resources.market_items'
|
||||
local market_item = Market_items.market_item
|
||||
@ -115,7 +116,7 @@ local total_fish_market_bonus_messages = #fish_market_bonus_message
|
||||
|
||||
local function fish_earned(event, amount)
|
||||
local player_index = event.player_index
|
||||
local player = game.players[player_index]
|
||||
local player = Game.players[player_index]
|
||||
|
||||
local stack = {name = market_item, count = amount}
|
||||
local inserted = player.insert(stack)
|
||||
@ -198,7 +199,7 @@ local function pet(player, entity_name)
|
||||
if not player then
|
||||
player = game.connected_players[1]
|
||||
else
|
||||
player = game.players[player]
|
||||
player = Game.players[player]
|
||||
end
|
||||
if not entity_name then
|
||||
entity_name = 'small-biter'
|
||||
@ -311,12 +312,12 @@ local function market_item_purchased(event)
|
||||
PlayerStats.change_coin_spent(player_index, fish_cost)
|
||||
|
||||
if event.offer_index == 1 then -- Temporary speed bonus
|
||||
local player = game.players[player_index]
|
||||
local player = Game.players[player_index]
|
||||
boost_player_runningspeed(player, market)
|
||||
end
|
||||
|
||||
if event.offer_index == 2 then -- Temporary mining bonus
|
||||
local player = game.players[player_index]
|
||||
local player = Game.players[player_index]
|
||||
boost_player_miningspeed(player, market)
|
||||
end
|
||||
|
||||
@ -376,14 +377,14 @@ local function on_180_ticks()
|
||||
if global.player_speed_boost_records then
|
||||
for k, v in pairs(global.player_speed_boost_records) do
|
||||
if game.tick - v.start_tick > 3000 then
|
||||
reset_player_runningspeed(game.players[k])
|
||||
reset_player_runningspeed(Game.players[k])
|
||||
end
|
||||
end
|
||||
end
|
||||
if global.player_mining_boost_records then
|
||||
for k, v in pairs(global.player_mining_boost_records) do
|
||||
if game.tick - v.start_tick > 6000 then
|
||||
reset_player_miningspeed(game.players[k])
|
||||
reset_player_miningspeed(Game.players[k])
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -391,7 +392,7 @@ local function on_180_ticks()
|
||||
|
||||
if global.player_pets then
|
||||
for _, pets in pairs(global.player_pets) do
|
||||
local player = game.players[pets.owner]
|
||||
local player = Game.players[pets.owner]
|
||||
if
|
||||
pcall(
|
||||
function()
|
||||
|
@ -1,6 +1,7 @@
|
||||
global.follows = {}
|
||||
global.follows.n_entries = 0
|
||||
local Utils = require "utils.utils"
|
||||
local Game = require 'utils.game'
|
||||
|
||||
function get_direction(follower, target)
|
||||
local delta_x = target.position.x - follower.position.x
|
||||
@ -41,8 +42,8 @@ end
|
||||
function walk_on_tick()
|
||||
if global.follows.n_entries > 0 then
|
||||
for k,v in pairs(global.follows) do
|
||||
local follower = game.players[k]
|
||||
local target = game.players[v]
|
||||
local follower = Game.players[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
|
||||
|
@ -3,6 +3,7 @@ local Token = require 'utils.global_token'
|
||||
local Gui = require 'utils.gui'
|
||||
local Task = require 'utils.Task'
|
||||
local Global = require 'utils.global'
|
||||
local Game = require 'utils.game'
|
||||
|
||||
local chests = {}
|
||||
local chests_next = {}
|
||||
@ -188,7 +189,7 @@ local function gui_opened(event)
|
||||
return
|
||||
end
|
||||
|
||||
local player = game.players[event.player_index]
|
||||
local player = Game.players[event.player_index]
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
@ -224,7 +225,7 @@ Event.add(defines.events.on_gui_opened, gui_opened)
|
||||
Event.add(
|
||||
defines.events.on_player_died,
|
||||
function(event)
|
||||
local player = game.players[event.player_index or 0]
|
||||
local player = Game.players[event.player_index or 0]
|
||||
|
||||
if not player or not player.valid then
|
||||
return
|
||||
|
3
info.lua
3
info.lua
@ -2,6 +2,7 @@ local Gui = require 'utils.gui'
|
||||
local Global = require 'utils.global'
|
||||
local Event = require 'utils.event'
|
||||
local UserGroups = require 'user_groups'
|
||||
local Game = require 'utils.game'
|
||||
|
||||
local normal_color = {r = 1, g = 1, b = 1}
|
||||
local focus_color = {r = 1, g = 0.55, b = 0.1}
|
||||
@ -633,7 +634,7 @@ local function toggle(event)
|
||||
end
|
||||
|
||||
local function player_created(event)
|
||||
local player = game.players[event.player_index]
|
||||
local player = Game.players[event.player_index]
|
||||
|
||||
if not player or not player.valid then
|
||||
return
|
||||
|
@ -16,7 +16,7 @@ random game events // earthquake, biters, rock treasure, messages
|
||||
local simplex_noise = require 'map_gen.shared.simplex_noise'
|
||||
local Event = require 'utils.event'
|
||||
local market_items = require "map_gen.combined.cave_miner.market_items"
|
||||
|
||||
local Game = require 'utils.game'
|
||||
|
||||
local Info = require 'info'
|
||||
|
||||
@ -473,7 +473,7 @@ end
|
||||
|
||||
local function on_player_joined_game(event)
|
||||
local surface = game.surfaces[1]
|
||||
local player = game.players[event.player_index]
|
||||
local player = Game.players[event.player_index]
|
||||
if not global.cave_miner_init_done then
|
||||
local p = surface.find_non_colliding_position("player", {0,-40}, 10, 1)
|
||||
game.forces["player"].set_spawn_position(p,surface)
|
||||
@ -765,7 +765,7 @@ local function on_tick(event)
|
||||
if game.forces.map_pregen.is_chunk_charted(game.surfaces[1], {40,40}) then
|
||||
game.print("Map generation done!", { r=0.22, g=0.99, b=0.99})
|
||||
|
||||
game.players[1].force = game.forces["player"]
|
||||
Game.players[1].force = game.forces["player"]
|
||||
global.map_pregeneration_is_active = nil
|
||||
end
|
||||
end
|
||||
@ -774,7 +774,7 @@ end
|
||||
|
||||
local function on_marked_for_deconstruction(event)
|
||||
if event.entity.name == "rock-huge" or event.entity.name == "rock-big" or event.entity.name == "sand-rock-big" then
|
||||
event.entity.cancel_deconstruction(game.players[event.player_index].force.name)
|
||||
event.entity.cancel_deconstruction(Game.players[event.player_index].force.name)
|
||||
end
|
||||
end
|
||||
|
||||
@ -790,7 +790,7 @@ local function pre_player_mined_item(event)
|
||||
end
|
||||
|
||||
if event.entity.name == "rock-huge" or event.entity.name == "rock-big" or event.entity.name == "sand-rock-big" then
|
||||
local player = game.players[event.player_index]
|
||||
local player = Game.players[event.player_index]
|
||||
local rock_position = {x = event.entity.position.x, y = event.entity.position.y}
|
||||
event.entity.destroy()
|
||||
local tile_distance_to_center = math.sqrt(rock_position.x^2 + rock_position.y^2)
|
||||
@ -873,7 +873,7 @@ local function on_player_mined_entity(event)
|
||||
end
|
||||
if event.entity.name == "fish" then
|
||||
if math.random(1,2) == 1 then
|
||||
local player = game.players[event.player_index]
|
||||
local player = Game.players[event.player_index]
|
||||
local health = player.character.health
|
||||
player.character.damage(math.random(50,150),"enemy")
|
||||
if not player.character then
|
||||
@ -920,7 +920,7 @@ local function on_entity_damaged(event)
|
||||
end
|
||||
|
||||
local function on_player_respawned(event)
|
||||
local player = game.players[event.player_index]
|
||||
local player = Game.players[event.player_index]
|
||||
player.character.disable_flashlight()
|
||||
global.player_hunger[player.name] = global.player_hunger_spawn_value
|
||||
hunger_update(player, 0)
|
||||
@ -936,7 +936,7 @@ end
|
||||
local function on_gui_click(event)
|
||||
if not (event and event.element and event.element.valid) then return end
|
||||
|
||||
local player = game.players[event.element.player_index]
|
||||
local player = Game.players[event.element.player_index]
|
||||
local name = event.element.name
|
||||
local frame = player.gui.top["caver_miner_stats_frame"]
|
||||
|
||||
@ -951,7 +951,7 @@ end
|
||||
|
||||
local function on_player_used_capsule(event)
|
||||
if event.item.name == "raw-fish" then
|
||||
local player = game.players[event.player_index]
|
||||
local player = Game.players[event.player_index]
|
||||
hunger_update(player, global.player_hunger_fish_food_value)
|
||||
player.play_sound{path="utility/armor_insert", volume_modifier=1}
|
||||
refresh_gui()
|
||||
@ -961,7 +961,7 @@ end
|
||||
function map_pregen()
|
||||
local radius = 1280
|
||||
if not game.forces.map_pregen then game.create_force("map_pregen") end
|
||||
game.players[1].force = game.forces["map_pregen"]
|
||||
Game.players[1].force = game.forces["map_pregen"]
|
||||
game.forces.map_pregen.chart(game.surfaces[1],{{x = -1 * radius, y = -1 * radius}, {x = radius, y = radius}})
|
||||
global.map_pregeneration_is_active = true
|
||||
end
|
||||
|
@ -1,4 +1,5 @@
|
||||
local Event = require 'utils.event'
|
||||
local Game = require 'utils.game'
|
||||
|
||||
global.allowed_entites = {
|
||||
['transport-belt'] = true,
|
||||
@ -53,7 +54,7 @@ Event.add(
|
||||
return
|
||||
end
|
||||
|
||||
local p = game.players[event.player_index]
|
||||
local p = Game.players[event.player_index]
|
||||
if not p or not p.valid then
|
||||
return
|
||||
end
|
||||
|
@ -1,4 +1,5 @@
|
||||
local Event = require 'utils.event'
|
||||
local Game = require 'utils.game'
|
||||
|
||||
global.allowed_landfill_tiles = {}
|
||||
|
||||
@ -29,7 +30,7 @@ Event.add(
|
||||
local surface = game.surfaces[event.surface_index]
|
||||
surface.set_tiles(new_tiles)
|
||||
|
||||
local player = game.players[event.player_index]
|
||||
local player = Game.players[event.player_index]
|
||||
player.insert {name = item_name, count = count}
|
||||
end
|
||||
)
|
||||
|
@ -1,4 +1,5 @@
|
||||
local Event = require "utils.event"
|
||||
local Game = require 'utils.game'
|
||||
|
||||
Event.on_init(function()
|
||||
|
||||
@ -12,7 +13,7 @@ Event.on_init(function()
|
||||
end)
|
||||
|
||||
Event.add(defines.events.on_player_created, function(event)
|
||||
local player = game.players[event.player_index]
|
||||
local player = Game.players[event.player_index]
|
||||
--player.print("Info: PVP server mod 'Bearded Snails' (c) byte");
|
||||
guiNewPlayer(player.gui.left);
|
||||
printNewPlayer(player);
|
||||
@ -30,7 +31,7 @@ Event.add(defines.events.on_player_created, function(event)
|
||||
end)
|
||||
|
||||
Event.add(defines.events.on_player_respawned, function(event)
|
||||
local player = game.players[event.player_index]
|
||||
local player = Game.players[event.player_index]
|
||||
|
||||
player.insert{name="heavy-armor", count=1}
|
||||
player.insert{name="pistol", count=1}
|
||||
@ -69,7 +70,7 @@ Event.add(defines.events.on_rocket_launched, function(event)
|
||||
end)
|
||||
|
||||
Event.add(defines.events.on_gui_click, function(event)
|
||||
local player = game.players[event.player_index]
|
||||
local player = Game.players[event.player_index]
|
||||
local gui = player.gui.left;
|
||||
|
||||
if player.force == game.forces.player and event.element.name == "new_button" then
|
||||
@ -91,7 +92,7 @@ Event.add(defines.events.on_gui_click, function(event)
|
||||
elseif event.element.name == "inv_button" then
|
||||
local name = gui.own_force.inv_name.text;
|
||||
if name ~= nil and validPlayer(name) then
|
||||
local iplayer = game.players[name];
|
||||
local iplayer = Game.players[name];
|
||||
local igui = iplayer.gui.left;
|
||||
|
||||
iplayer.force = player.force;
|
||||
@ -142,7 +143,7 @@ function dist(position1, position2)
|
||||
end
|
||||
|
||||
function validPlayer(name)
|
||||
if name ~= nil and game.players[name] ~= nil and game.players[name].force == game.forces.player then
|
||||
if name ~= nil and Game.players[name] ~= nil and Game.players[name].force == game.forces.player then
|
||||
return true;
|
||||
end
|
||||
return false;
|
||||
|
@ -4,6 +4,7 @@ require("rso_config")
|
||||
require("util")
|
||||
require("rso_resource_config")
|
||||
local Utils = require "utils.utils"
|
||||
local Game = require 'utils.game'
|
||||
|
||||
local MB=require "metaball"
|
||||
local drand = require 'drand'
|
||||
@ -32,9 +33,9 @@ local max = math.max
|
||||
local function rso_debug(str)
|
||||
if rso_debug_enabled then
|
||||
if (type(str) == "table") then
|
||||
game.players[1].print(serpent.dump(str))
|
||||
Game.players[1].print(serpent.dump(str))
|
||||
else
|
||||
game.players[1].print(str)
|
||||
Game.players[1].print(str)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1136,26 +1137,26 @@ function RSO_init()
|
||||
initDone = true
|
||||
|
||||
if surface.map_gen_settings.autoplace_controls["iron-ore"].size ~= "none" then
|
||||
game.players[1].print("RSO WARNING - VANILLA iron-ore GEN IS NOT DISABLED!")
|
||||
Game.players[1].print("RSO WARNING - VANILLA iron-ore GEN IS NOT DISABLED!")
|
||||
end
|
||||
if surface.map_gen_settings.autoplace_controls["copper-ore"].size ~= "none" then
|
||||
game.players[1].print("RSO WARNING - VANILLA copper-ore GEN IS NOT DISABLED!")
|
||||
Game.players[1].print("RSO WARNING - VANILLA copper-ore GEN IS NOT DISABLED!")
|
||||
end
|
||||
if surface.map_gen_settings.autoplace_controls["uranium-ore"].size ~= "none" then
|
||||
game.players[1].print("RSO WARNING - VANILLA uranium-ore GEN IS NOT DISABLED!")
|
||||
Game.players[1].print("RSO WARNING - VANILLA uranium-ore GEN IS NOT DISABLED!")
|
||||
end
|
||||
if surface.map_gen_settings.autoplace_controls["crude-oil"].size ~= "none" then
|
||||
game.players[1].print("RSO WARNING - VANILLA crude-oil GEN IS NOT DISABLED!")
|
||||
Game.players[1].print("RSO WARNING - VANILLA crude-oil GEN IS NOT DISABLED!")
|
||||
end
|
||||
if surface.map_gen_settings.autoplace_controls["enemy-base"].size ~= "none" then
|
||||
-- Not a problem, as this RSO does not gen biters
|
||||
-- game.players[1].print("RSO WARNING - VANILLA enemy-base GEN IS NOT DISABLED!")
|
||||
-- Game.players[1].print("RSO WARNING - VANILLA enemy-base GEN IS NOT DISABLED!")
|
||||
end
|
||||
if surface.map_gen_settings.autoplace_controls["stone"].size ~= "none" then
|
||||
game.players[1].print("RSO WARNING - VANILLA stone GEN IS NOT DISABLED!")
|
||||
Game.players[1].print("RSO WARNING - VANILLA stone GEN IS NOT DISABLED!")
|
||||
end
|
||||
if surface.map_gen_settings.autoplace_controls["coal"].size ~= "none" then
|
||||
game.players[1].print("RSO WARNING - VANILLA coal GEN IS NOT DISABLED!")
|
||||
Game.players[1].print("RSO WARNING - VANILLA coal GEN IS NOT DISABLED!")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -2,6 +2,7 @@ local Gui = require 'utils.gui'
|
||||
local Event = require 'utils.event'
|
||||
local Global = require 'utils.global'
|
||||
local PlayerStats = require 'player_stats'
|
||||
local Game = require 'utils.game'
|
||||
|
||||
local Public = {}
|
||||
|
||||
@ -118,7 +119,7 @@ local function gui_opened(event)
|
||||
return
|
||||
end
|
||||
|
||||
local player = game.players[event.player_index]
|
||||
local player = Game.players[event.player_index]
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
@ -156,7 +157,7 @@ Gui.on_custom_close(
|
||||
Event.add(
|
||||
defines.events.on_player_died,
|
||||
function(event)
|
||||
local player = game.players[event.player_index or 0]
|
||||
local player = Game.players[event.player_index or 0]
|
||||
|
||||
if not player or not player.valid then
|
||||
return
|
||||
|
@ -1,4 +1,5 @@
|
||||
local Event = require 'utils.event'
|
||||
local Game = require 'utils.game'
|
||||
|
||||
local mines_factor = 1
|
||||
|
||||
@ -35,7 +36,7 @@ local death_messages = {
|
||||
}
|
||||
|
||||
local function player_died(event)
|
||||
local player = game.players[event.player_index]
|
||||
local player = Game.players[event.player_index]
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
@ -1,17 +1,18 @@
|
||||
local Event = require "utils.event"
|
||||
local UserGroups = require "user_groups"
|
||||
local Utils = require "utils.utils"
|
||||
local Game = require 'utils.game'
|
||||
|
||||
function allowed_to_nuke(player)
|
||||
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
|
||||
return allowed_to_nuke(game.players[player])
|
||||
return allowed_to_nuke(Game.players[player])
|
||||
end
|
||||
end
|
||||
|
||||
local function ammo_changed(event)
|
||||
local player = game.players[event.player_index]
|
||||
local player = Game.players[event.player_index]
|
||||
if allowed_to_nuke(player) then return end
|
||||
local nukes = player.remove_item({name="atomic-bomb", count=1000})
|
||||
if nukes > 0 then
|
||||
@ -30,7 +31,7 @@ local function ammo_changed(event)
|
||||
end
|
||||
|
||||
local function on_player_deconstructed_area(event)
|
||||
local player = game.players[event.player_index]
|
||||
local player = Game.players[event.player_index]
|
||||
if allowed_to_nuke(player) then return end
|
||||
player.remove_item({name="deconstruction-planner", count=1000})
|
||||
|
||||
@ -59,8 +60,8 @@ local function on_player_deconstructed_area(event)
|
||||
Utils.print_admins("Warning! " .. player.name .. " just tried to deconstruct " .. tostring(#entities) .. " entities!")
|
||||
end
|
||||
for _,entity in pairs(entities) do
|
||||
if entity.valid and entity.to_be_deconstructed(game.players[event.player_index].force) then
|
||||
entity.cancel_deconstruction(game.players[event.player_index].force)
|
||||
if entity.valid and entity.to_be_deconstructed(Game.players[event.player_index].force) then
|
||||
entity.cancel_deconstruction(Game.players[event.player_index].force)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -107,7 +108,7 @@ end
|
||||
global.players_warned = {}
|
||||
local function on_capsule_used(event)
|
||||
local item = event.item
|
||||
local player = game.players[event.player_index]
|
||||
local player = Game.players[event.player_index]
|
||||
|
||||
if not player or not player.valid or
|
||||
(global.scenario.config.nuke_control.enable_autokick and global.scenario.config.nuke_control.enable_autoban) then
|
||||
|
@ -1,5 +1,6 @@
|
||||
local Event = require 'utils.event'
|
||||
local Gui = require 'utils.gui'
|
||||
local Game = require 'utils.game'
|
||||
|
||||
local brush_tool = 'refined-hazard-concrete'
|
||||
|
||||
@ -52,7 +53,7 @@ local function player_build_tile(event)
|
||||
return
|
||||
end
|
||||
|
||||
local player = game.players[event.player_index]
|
||||
local player = Game.players[event.player_index]
|
||||
if not player.gui.left[main_frame_name] then
|
||||
return
|
||||
end
|
||||
@ -77,7 +78,7 @@ local function player_joined(event)
|
||||
if not global.scenario.config.paint.enable then
|
||||
return
|
||||
end
|
||||
local player = game.players[event.player_index]
|
||||
local player = Game.players[event.player_index]
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
@ -1,4 +1,5 @@
|
||||
local Event = require 'utils.event'
|
||||
local Game = require 'utils.game'
|
||||
|
||||
local player_colors = {
|
||||
['grilledham'] = {
|
||||
@ -26,7 +27,7 @@ local player_colors = {
|
||||
Event.add(
|
||||
defines.events.on_player_created,
|
||||
function(event)
|
||||
local player = game.players[event.player_index]
|
||||
local player = Game.players[event.player_index]
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
@ -6,6 +6,7 @@ local UserGroups = require 'user_groups'
|
||||
local PlayerStats = require 'player_stats'
|
||||
local Utils = require 'utils.utils'
|
||||
local Report = require 'report'
|
||||
local Game = require 'utils.game'
|
||||
|
||||
local poke_messages = require 'resources.poke_messages'
|
||||
local player_sprites = require 'resources.player_sprites'
|
||||
@ -611,7 +612,7 @@ local function tick()
|
||||
end
|
||||
|
||||
local function player_joined(event)
|
||||
local player = game.players[event.player_index]
|
||||
local player = Game.players[event.player_index]
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
@ -1,5 +1,6 @@
|
||||
local Event = require 'utils.event'
|
||||
local Global = require 'utils.global'
|
||||
local Game = require 'utils.game'
|
||||
|
||||
local player_last_position = {}
|
||||
local player_walk_distances = {}
|
||||
@ -30,7 +31,7 @@ Global.register(
|
||||
local function player_created(event)
|
||||
local index = event.player_index
|
||||
|
||||
player_last_position[index] = game.players[index].position
|
||||
player_last_position[index] = Game.players[index].position
|
||||
player_walk_distances[index] = 0
|
||||
player_coin_earned[index] = 0
|
||||
player_coin_spent[index] = 0
|
||||
|
9
poll.lua
9
poll.lua
@ -2,6 +2,7 @@ local Gui = require 'utils.gui'
|
||||
local Global = require 'utils.global'
|
||||
local Event = require 'utils.event'
|
||||
local UserGroups = require 'user_groups'
|
||||
local Game = require 'utils.game'
|
||||
|
||||
local default_poll_duration = 300 * 60 -- in ticks
|
||||
local duration_max = 3600 -- in seconds
|
||||
@ -129,7 +130,7 @@ local function redraw_poll_viewer_content(data)
|
||||
end
|
||||
|
||||
for player_index, answer in pairs(voters) do
|
||||
local p = game.players[player_index]
|
||||
local p = Game.players[player_index]
|
||||
table.insert(tooltips[answer], p.name)
|
||||
end
|
||||
|
||||
@ -156,7 +157,7 @@ local function redraw_poll_viewer_content(data)
|
||||
if next(edited_by_players) then
|
||||
local edit_names = {'Edited by '}
|
||||
for pi, _ in pairs(edited_by_players) do
|
||||
local p = game.players[pi]
|
||||
local p = Game.players[pi]
|
||||
if p and p.valid then
|
||||
table.insert(edit_names, p.name)
|
||||
table.insert(edit_names, ', ')
|
||||
@ -666,7 +667,7 @@ local function update_vote(voters, answer, direction)
|
||||
local tooltip = {}
|
||||
for pi, a in pairs(voters) do
|
||||
if a == answer then
|
||||
local player = game.players[pi]
|
||||
local player = Game.players[pi]
|
||||
table.insert(tooltip, player.name)
|
||||
end
|
||||
end
|
||||
@ -738,7 +739,7 @@ local function vote(event)
|
||||
end
|
||||
|
||||
local function player_joined(event)
|
||||
local player = game.players[event.player_index]
|
||||
local player = Game.players[event.player_index]
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
11
report.lua
11
report.lua
@ -2,6 +2,7 @@ local Module = {}
|
||||
|
||||
local Gui = require("utils.gui")
|
||||
local Utils = require("utils.utils");
|
||||
local Game = require 'utils.game'
|
||||
local report_frame_name = Gui.uid_name()
|
||||
local report_close_button_name = Gui.uid_name()
|
||||
local report_tab_button_name = Gui.uid_name()
|
||||
@ -18,8 +19,8 @@ local function draw_report(parent, report_id)
|
||||
parent.add {type = "label", caption="No reports yet."}
|
||||
return
|
||||
end
|
||||
local reported_player_name = game.players[report.reported_player_index].name
|
||||
local reporting_player_name = game.players[report.reporting_player_index].name
|
||||
local reported_player_name = Game.players[report.reported_player_index].name
|
||||
local reporting_player_name = Game.players[report.reporting_player_index].name
|
||||
local time = Utils.format_time(report.tick)
|
||||
local time_ago = Utils.format_time(game.tick - report.tick)
|
||||
|
||||
@ -63,7 +64,7 @@ Module.show_reports = function(player)
|
||||
button_cell.add {
|
||||
type="button",
|
||||
name=report_tab_button_name,
|
||||
caption = game.players[report.reported_player_index].name
|
||||
caption = Game.players[report.reported_player_index].name
|
||||
}
|
||||
end
|
||||
end
|
||||
@ -178,9 +179,9 @@ Gui.on_click(
|
||||
local reported_player_index = data["reported_player_index"]
|
||||
|
||||
Gui.destroy(frame)
|
||||
Module.report(event.player, game.players[reported_player_index], msg)
|
||||
Module.report(event.player, Game.players[reported_player_index], msg)
|
||||
|
||||
event.player.print("Sucessfully reported " .. game.players[reported_player_index].name)
|
||||
event.player.print("Sucessfully reported " .. Game.players[reported_player_index].name)
|
||||
end
|
||||
)
|
||||
|
||||
|
@ -1,9 +1,10 @@
|
||||
local Event = require "utils.event"
|
||||
local Game = require 'utils.game'
|
||||
|
||||
if not global.score_rockets_launched then global.score_rockets_launched = 0 end
|
||||
|
||||
local function create_score_gui(event)
|
||||
local player = game.players[event.player_index]
|
||||
local player = Game.players[event.player_index]
|
||||
|
||||
if player.gui.top.score == nil then
|
||||
local button = player.gui.top.add({ type = "sprite-button", name = "score", sprite = "item/rocket-silo" })
|
||||
@ -18,8 +19,8 @@ end
|
||||
|
||||
function refresh_score()
|
||||
local x = 1
|
||||
while (game.players[x] ~= nil) do
|
||||
local player = game.players[x]
|
||||
while (Game.players[x] ~= nil) do
|
||||
local player = Game.players[x]
|
||||
local frame = player.gui.top["score_panel"]
|
||||
|
||||
if (frame) then
|
||||
@ -72,7 +73,7 @@ end
|
||||
local function on_gui_click(event)
|
||||
if not (event and event.element and event.element.valid) then return end
|
||||
|
||||
local player = game.players[event.element.player_index]
|
||||
local player = Game.players[event.element.player_index]
|
||||
local name = event.element.name
|
||||
local frame = player.gui.top["score_panel"]
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
local Event = require "utils.event"
|
||||
local Game = require 'utils.game'
|
||||
|
||||
global.player_spawns = {} -- player_index to spawn_name
|
||||
global.spawns = {} -- spawn_name to x, y, player_online_count
|
||||
@ -55,7 +56,7 @@ local function player_joined_game(event)
|
||||
|
||||
local spawn = global.spawns[spawn_name]
|
||||
global.player_spawns[index] = spawn_name
|
||||
game.players[index].teleport(spawn)
|
||||
Game.players[index].teleport(spawn)
|
||||
|
||||
local count = spawn.count
|
||||
spawn.count = count + 1
|
||||
@ -79,11 +80,11 @@ local function player_respawned(event)
|
||||
|
||||
if not spawn then return end
|
||||
|
||||
game.players[index].teleport(spawn)
|
||||
Game.players[index].teleport(spawn)
|
||||
end
|
||||
|
||||
local function tp_spawn(player_name, spawn_name)
|
||||
local player = game.players[player_name]
|
||||
local player = Game.players[player_name]
|
||||
if not player then
|
||||
player_name = player_name or ""
|
||||
game.player.print("player " .. player_name .. " does not exist.")
|
||||
@ -109,7 +110,7 @@ local function change_spawn(player_name, spawn_name)
|
||||
return
|
||||
end
|
||||
|
||||
local player = game.players[player_name]
|
||||
local player = Game.players[player_name]
|
||||
|
||||
if not player then
|
||||
player_name = player_name or ""
|
||||
@ -151,7 +152,7 @@ local function print_players_for_spawn(target_spawn_name)
|
||||
str = ""
|
||||
for index, spawn_name in pairs(global.player_spawns) do
|
||||
if target_spawn_name == spawn_name then
|
||||
local player = game.players[index]
|
||||
local player = Game.players[index]
|
||||
if player.connected then
|
||||
str = str .. player.name .. ", "
|
||||
end
|
||||
|
@ -2,6 +2,7 @@ local Event = require 'utils.event'
|
||||
local Gui = require 'utils.gui'
|
||||
local Global = require 'utils.global'
|
||||
local UserGroups = require 'user_groups'
|
||||
local Game = require 'utils.game'
|
||||
|
||||
local deafult_verb = 'expanded'
|
||||
|
||||
@ -86,7 +87,7 @@ local function get_size(players, show_offline)
|
||||
size = table.size(players)
|
||||
else
|
||||
for pi, _ in pairs(players) do
|
||||
local player = game.players[pi]
|
||||
local player = Game.players[pi]
|
||||
if player and player.valid and player.connected then
|
||||
size = size + 1
|
||||
end
|
||||
@ -118,7 +119,7 @@ local delete_tag_name = Gui.uid_name()
|
||||
local close_create_tag_name = Gui.uid_name()
|
||||
|
||||
local function player_joined(event)
|
||||
local player = game.players[event.player_index]
|
||||
local player = Game.players[event.player_index]
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
@ -179,11 +180,11 @@ local function draw_main_frame_content(parent)
|
||||
|
||||
if players then
|
||||
for k, _ in pairs(players) do
|
||||
local p = game.players[k]
|
||||
local p = Game.players[k]
|
||||
if p and p.valid and p.connected then
|
||||
local color = {r = 0.4 + 0.6 * p.color.r, g = 0.4 + 0.6 * p.color.g, b = 0.4 + 0.6 * p.color.b}
|
||||
|
||||
local label = list.add {type = 'label', caption = game.players[k].name}
|
||||
local label = list.add {type = 'label', caption = Game.players[k].name}
|
||||
label.style.top_padding = 8
|
||||
label.style.font_color = color
|
||||
end
|
||||
@ -678,7 +679,7 @@ local function tag_command(cmd)
|
||||
return
|
||||
end
|
||||
|
||||
local target_player = game.players[params[1]]
|
||||
local target_player = Game.players[params[1]]
|
||||
|
||||
if target_player == nil or not target_player.valid then
|
||||
player_print('Player does not exist.')
|
||||
|
@ -3,6 +3,7 @@ local Gui = require 'utils.gui'
|
||||
local Global = require 'utils.global'
|
||||
local UserGroups = require 'user_groups'
|
||||
local Utils = require 'utils.utils'
|
||||
local Game = require 'utils.game'
|
||||
|
||||
local normal_color = {r = 1, g = 1, b = 1}
|
||||
local focus_color = {r = 1, g = 0.55, b = 0.1}
|
||||
@ -111,7 +112,7 @@ local function get_editing_players_message(players)
|
||||
local message = {'Editing players: '}
|
||||
|
||||
for pi, _ in pairs(players) do
|
||||
local name = game.players[pi].name
|
||||
local name = Game.players[pi].name
|
||||
table.insert(message, name)
|
||||
table.insert(message, ', ')
|
||||
end
|
||||
@ -584,7 +585,7 @@ local function draw_create_task_frame(left, previous_task)
|
||||
end
|
||||
|
||||
local function player_created(event)
|
||||
local player = game.players[event.player_index]
|
||||
local player = Game.players[event.player_index]
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
@ -630,7 +631,7 @@ local function player_created(event)
|
||||
end
|
||||
|
||||
local function player_left(event)
|
||||
local player = game.players[event.player_index]
|
||||
local player = Game.players[event.player_index]
|
||||
local left = player.gui.left
|
||||
|
||||
local frame = left[edit_announcements_frame_name]
|
||||
|
@ -3,6 +3,7 @@ local Market_items = require 'resources.market_items'
|
||||
local Global = require 'utils.global'
|
||||
local Donators = require 'resources.donators'
|
||||
local UserGroups = require 'user_groups'
|
||||
local Game = require 'utils.game'
|
||||
local train_perk_flag = Donators.donator_perk_flags.train
|
||||
|
||||
local saviour_token_name = 'small-plane' -- item name for what saves players
|
||||
@ -52,7 +53,7 @@ local function on_pre_death(event)
|
||||
end
|
||||
|
||||
local player_index = event.player_index
|
||||
local player = game.players[player_index]
|
||||
local player = Game.players[player_index]
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
@ -1,4 +1,5 @@
|
||||
local Event = require 'utils.event'
|
||||
local Game = require 'utils.game'
|
||||
|
||||
local function player_built_entity(event)
|
||||
local entity = event.created_entity
|
||||
@ -7,8 +8,8 @@ local function player_built_entity(event)
|
||||
if entity.name == 'train-stop' then
|
||||
local y = math.random(1, 3)
|
||||
if y ~= 1 then
|
||||
local x = math.random(1, #game.players)
|
||||
local player = game.players[x]
|
||||
local x = math.random(1, #Game.players)
|
||||
local player = Game.players[x]
|
||||
event.created_entity.backer_name = player.name
|
||||
end
|
||||
end
|
||||
|
@ -3,6 +3,7 @@ local Donators = require 'resources.donators'
|
||||
global.donators = Donators.donators
|
||||
local Event = require 'utils.event'
|
||||
local Utils = require 'utils.utils'
|
||||
local Game = require 'utils.game'
|
||||
|
||||
local Module = {}
|
||||
|
||||
@ -27,8 +28,8 @@ Module.add_regular = function(player_name)
|
||||
if Module.is_regular(player_name) then
|
||||
player_print(player_name .. ' is already a regular.')
|
||||
else
|
||||
if game.players[player_name] then
|
||||
player_name = game.players[player_name].name
|
||||
if Game.players[player_name] then
|
||||
player_name = Game.players[player_name].name
|
||||
game.print(actor .. ' promoted ' .. player_name .. ' to regular.')
|
||||
global.regulars[player_name] = true
|
||||
update_file()
|
||||
@ -41,8 +42,8 @@ end
|
||||
Module.remove_regular =
|
||||
function(player_name)
|
||||
local actor = Utils.get_actor()
|
||||
if game.players[player_name] then
|
||||
player_name = game.players[player_name].name
|
||||
if Game.players[player_name] then
|
||||
player_name = Game.players[player_name].name
|
||||
if Module.is_regular(player_name) then
|
||||
game.print(player_name .. ' was demoted from regular by ' .. actor .. '.')
|
||||
end
|
||||
@ -84,7 +85,7 @@ end
|
||||
Event.add(
|
||||
defines.events.on_player_joined_game,
|
||||
function(event)
|
||||
local correctCaseName = game.players[event.player_index].name
|
||||
local correctCaseName = Game.players[event.player_index].name
|
||||
if global.regulars[correctCaseName:lower()] and not global.regulars[correctCaseName] then
|
||||
global.regulars[correctCaseName:lower()] = nil
|
||||
global.regulars[correctCaseName] = true
|
||||
|
51
utils/game.lua
Normal file
51
utils/game.lua
Normal file
@ -0,0 +1,51 @@
|
||||
local Event = require 'utils.event'
|
||||
local Global = require 'utils.global'
|
||||
|
||||
local Game = {}
|
||||
|
||||
local players
|
||||
|
||||
local function get_player(index)
|
||||
local p = game.players[index]
|
||||
if not p then
|
||||
return nil
|
||||
end
|
||||
if p.index == index then
|
||||
return p
|
||||
end
|
||||
|
||||
for k, v in pairs(game.players) do
|
||||
if k == index then
|
||||
return v
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Event.add(
|
||||
defines.events.on_player_created,
|
||||
function(event)
|
||||
local p = get_player(event.player_index)
|
||||
table.insert(players, p)
|
||||
end
|
||||
)
|
||||
|
||||
local mt_players = {}
|
||||
function mt_players.__index(_, index)
|
||||
if type(index) == 'string' then
|
||||
return game.players[index]
|
||||
end
|
||||
end
|
||||
|
||||
players = setmetatable({}, mt_players)
|
||||
|
||||
Global.register(
|
||||
players,
|
||||
function(tbl)
|
||||
players = setmetatable(tbl, mt_players)
|
||||
Game.players = players
|
||||
end
|
||||
)
|
||||
|
||||
Game.players = players
|
||||
|
||||
return Game
|
@ -8,12 +8,12 @@ local init_data = {}
|
||||
|
||||
function Global.register(tbl, callback)
|
||||
local token = Token.register_global(tbl)
|
||||
table.insert(load_data, {tbl = tbl, callback = callback, token = token})
|
||||
table.insert(load_data, {callback = callback, token = token})
|
||||
end
|
||||
|
||||
function Global.register_init(tbl, init_handler, callback)
|
||||
local token = Token.register_global(tbl)
|
||||
table.insert(load_data, {tbl = tbl, callback = callback, token = token})
|
||||
table.insert(load_data, {callback = callback, token = token})
|
||||
|
||||
table.insert(init_data, {token = token, init_handler = init_handler, callback = callback})
|
||||
end
|
||||
|
@ -1,5 +1,6 @@
|
||||
local Token = require 'utils.global_token'
|
||||
local Event = require 'utils.event'
|
||||
local Game = require 'utils.game'
|
||||
|
||||
local Gui = {}
|
||||
|
||||
@ -81,7 +82,7 @@ local function handler_factory(event_id)
|
||||
return
|
||||
end
|
||||
|
||||
local player = game.players[event.player_index]
|
||||
local player = Game.players[event.player_index]
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
@ -1,4 +1,5 @@
|
||||
local Module = {}
|
||||
local Game = require 'utils.game'
|
||||
|
||||
Module.distance = function(pos1, pos2)
|
||||
local dx = pos2.x - pos1.x
|
||||
@ -79,7 +80,7 @@ Module.find_entities_by_last_user =
|
||||
surface = game.surfaces[surface]
|
||||
end
|
||||
if type(player) == 'number' then
|
||||
player = game.players[player]
|
||||
player = Game.players[player]
|
||||
end
|
||||
filters.force = player.force.name
|
||||
for _, e in pairs(surface.find_entities_filtered(filters)) do
|
||||
|
@ -2,6 +2,7 @@ local Event = require 'utils.event'
|
||||
local Token = require 'utils.global_token'
|
||||
local Task = require 'utils.Task'
|
||||
local PlayerStats = require 'player_stats'
|
||||
local Game = require 'utils.game'
|
||||
|
||||
local market_items = require 'resources.market_items'
|
||||
|
||||
@ -160,12 +161,12 @@ local function market_item_purchased(event)
|
||||
PlayerStats.change_fish_spent(player_index, cost)
|
||||
|
||||
if event.offer_index == 1 then -- Temporary speed bonus
|
||||
local player = game.players[player_index]
|
||||
local player = Game.players[player_index]
|
||||
boost_player_runningspeed(player, market)
|
||||
end
|
||||
|
||||
if event.offer_index == 2 then -- Temporary mining bonus
|
||||
local player = game.players[player_index]
|
||||
local player = Game.players[player_index]
|
||||
boost_player_miningspeed(player, market)
|
||||
end
|
||||
end
|
||||
@ -179,14 +180,14 @@ local function on_180_ticks()
|
||||
if global.player_speed_boost_records then
|
||||
for k, v in pairs(global.player_speed_boost_records) do
|
||||
if game.tick - v.start_tick > 3000 then
|
||||
reset_player_runningspeed(game.players[k])
|
||||
reset_player_runningspeed(Game.players[k])
|
||||
end
|
||||
end
|
||||
end
|
||||
if global.player_mining_boost_records then
|
||||
for k, v in pairs(global.player_mining_boost_records) do
|
||||
if game.tick - v.start_tick > 6000 then
|
||||
reset_player_miningspeed(game.players[k])
|
||||
reset_player_miningspeed(Game.players[k])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user