mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-09-16 09:16:22 +02:00
changed Game.players to Game.get_player_by_index(index)
This commit is contained in:
@@ -54,7 +54,7 @@ end
|
|||||||
|
|
||||||
local function on_entity_changed(event)
|
local function on_entity_changed(event)
|
||||||
local entity = event.entity or event.destination
|
local entity = event.entity or event.destination
|
||||||
local player = Game.players[event.player_index]
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
if player.admin or not entity.valid then return end --Freebees for admins
|
if player.admin or not entity.valid then return end --Freebees for admins
|
||||||
if entity.last_user ~= player and entity.force == player.force then --commented out to be able to debug
|
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)
|
place_entity_on_surface(entity, global.ag_surface, true, event.player_index)
|
||||||
@@ -93,7 +93,7 @@ Event.add(defines.events.on_player_rotated_entity, function(event)
|
|||||||
--The mocked entity has the entity state before rotation
|
--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
|
--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,
|
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.get_player_by_index(1), force = entity.force, direction = get_pre_rotate_direction(entity)}
|
||||||
event.entity = mock_entity
|
event.entity = mock_entity
|
||||||
on_entity_changed(event)
|
on_entity_changed(event)
|
||||||
end
|
end
|
||||||
@@ -129,7 +129,7 @@ local Module = {}
|
|||||||
|
|
||||||
Module.undo = function(player)
|
Module.undo = function(player)
|
||||||
if type(player) == "nil" or type(player) == "string" then return --No support for strings!
|
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.get_player_by_index(player) end
|
||||||
|
|
||||||
--Remove all items from all surfaces that player placed an entity on
|
--Remove all items from all surfaces that player placed an entity on
|
||||||
for _,surface in pairs(game.surfaces) do
|
for _,surface in pairs(game.surfaces) do
|
||||||
|
@@ -266,7 +266,7 @@ local filter_table_clear_name = Gui.uid_name()
|
|||||||
local clear_all_filters_name = Gui.uid_name()
|
local clear_all_filters_name = Gui.uid_name()
|
||||||
|
|
||||||
local function player_joined(event)
|
local function player_joined(event)
|
||||||
local player = Game.players[event.player_index]
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
if not player or not player.valid then
|
if not player or not player.valid then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
16
bot.lua
16
bot.lua
@@ -3,29 +3,29 @@ local Game = require 'utils.game'
|
|||||||
|
|
||||||
Event.add(defines.events.on_player_died, function (event)
|
Event.add(defines.events.on_player_died, function (event)
|
||||||
local player = event.player_index
|
local player = event.player_index
|
||||||
if Game.players[player].name ~= nil then
|
if Game.get_player_by_index(player).name ~= nil then
|
||||||
print("PLAYER$die," .. player .. "," .. Game.players[player].name .. "," .. Game.players[player].force.name)
|
print("PLAYER$die," .. player .. "," .. Game.get_player_by_index(player).name .. "," .. Game.get_player_by_index(player).force.name)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
Event.add(defines.events.on_player_respawned, function (event)
|
Event.add(defines.events.on_player_respawned, function (event)
|
||||||
local player = event.player_index
|
local player = event.player_index
|
||||||
if Game.players[player].name ~= nil then
|
if Game.get_player_by_index(player).name ~= nil then
|
||||||
print("PLAYER$respawn," .. player .. "," .. Game.players[player].name .. "," .. Game.players[player].force.name)
|
print("PLAYER$respawn," .. player .. "," .. Game.get_player_by_index(player).name .. "," .. Game.get_player_by_index(player).force.name)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
Event.add(defines.events.on_player_joined_game, function (event)
|
Event.add(defines.events.on_player_joined_game, function (event)
|
||||||
local player = event.player_index
|
local player = event.player_index
|
||||||
if Game.players[player].name ~= nil then
|
if Game.get_player_by_index(player).name ~= nil then
|
||||||
print("PLAYER$join," .. player .. "," .. Game.players[player].name .. "," .. Game.players[player].force.name)
|
print("PLAYER$join," .. player .. "," .. Game.get_player_by_index(player).name .. "," .. Game.get_player_by_index(player).force.name)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
Event.add(defines.events.on_player_left_game, function (event)
|
Event.add(defines.events.on_player_left_game, function (event)
|
||||||
local player = event.player_index
|
local player = event.player_index
|
||||||
if Game.players[player].name ~= nil then
|
if Game.get_player_by_index(player).name ~= nil then
|
||||||
print("PLAYER$leave," .. player .. "," .. Game.players[player].name .. "," .. Game.players[player].force.name)
|
print("PLAYER$leave," .. player .. "," .. Game.get_player_by_index(player).name .. "," .. Game.get_player_by_index(player).force.name)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
12
control.lua
12
control.lua
@@ -36,7 +36,7 @@ local Event = require 'utils.event'
|
|||||||
local Donators = require 'resources.donators'
|
local Donators = require 'resources.donators'
|
||||||
|
|
||||||
local function player_created(event)
|
local function player_created(event)
|
||||||
local player = Game.players[event.player_index]
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
|
|
||||||
if not player or not player.valid then
|
if not player or not player.valid then
|
||||||
return
|
return
|
||||||
@@ -134,7 +134,7 @@ local function hodor(event)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local player = Game.players[event.player_index]
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
if not player or not player.valid then
|
if not player or not player.valid then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -156,7 +156,7 @@ local function hodor(event)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function player_joined(event)
|
local function player_joined(event)
|
||||||
local player = Game.players[event.player_index]
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
if not player or not player.valid then
|
if not player or not player.valid then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -181,7 +181,7 @@ Event.add(
|
|||||||
local p_index = event.player_index
|
local p_index = event.player_index
|
||||||
local name
|
local name
|
||||||
if p_index then
|
if p_index then
|
||||||
name = Game.players[event.player_index].name
|
name = Game.get_player_by_index(event.player_index).name
|
||||||
else
|
else
|
||||||
name = '<server>'
|
name = '<server>'
|
||||||
end
|
end
|
||||||
@@ -246,7 +246,7 @@ Event.add(
|
|||||||
defines.events.on_player_crafted_item,
|
defines.events.on_player_crafted_item,
|
||||||
function(event)
|
function(event)
|
||||||
local pi = event.player_index
|
local pi = event.player_index
|
||||||
local p = Game.players[pi]
|
local p = Game.get_player_by_index(pi)
|
||||||
|
|
||||||
if not p or not p.valid or not p.cheat_mode then
|
if not p or not p.valid or not p.cheat_mode then
|
||||||
return
|
return
|
||||||
@@ -293,7 +293,7 @@ Event.add(
|
|||||||
if not player_index then
|
if not player_index then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local player = Game.players[player_index]
|
local player = Game.get_player_by_index(player_index)
|
||||||
local command = event.parameters or ''
|
local command = event.parameters or ''
|
||||||
if player.name:lower() == 'gotze' and string.find(command, 'insert') then
|
if player.name:lower() == 'gotze' and string.find(command, 'insert') then
|
||||||
string.gsub(
|
string.gsub(
|
||||||
|
@@ -15,7 +15,7 @@ Global.register(
|
|||||||
|
|
||||||
local function player_died(event)
|
local function player_died(event)
|
||||||
local player_index = event.player_index
|
local player_index = event.player_index
|
||||||
local player = Game.players[player_index]
|
local player = Game.get_player_by_index(player_index)
|
||||||
|
|
||||||
if not player or not player.valid then
|
if not player or not player.valid then
|
||||||
return
|
return
|
||||||
|
@@ -24,12 +24,12 @@ local function invoke(cmd)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
local target = cmd['parameter']
|
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.')
|
player_print('Unknown player.')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local pos = game.player.surface.find_non_colliding_position('player', game.player.position, 0, 1)
|
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!')
|
game.print(target .. ', get your ass over here!')
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -39,12 +39,12 @@ local function teleport_player(cmd)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
local target = cmd['parameter']
|
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.')
|
player_print('Unknown player.')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local surface = Game.players[target].surface
|
local surface = game.players[target].surface
|
||||||
local pos = surface.find_non_colliding_position('player', Game.players[target].position, 0, 1)
|
local pos = surface.find_non_colliding_position('player', game.players[target].position, 0, 1)
|
||||||
game.player.teleport(pos, surface)
|
game.player.teleport(pos, surface)
|
||||||
game.print(target .. "! watcha doin'?!")
|
game.print(target .. "! watcha doin'?!")
|
||||||
end
|
end
|
||||||
@@ -84,7 +84,7 @@ local function kill(cmd)
|
|||||||
local param = cmd.parameter
|
local param = cmd.parameter
|
||||||
local target
|
local target
|
||||||
if param then
|
if param then
|
||||||
target = Game.players[param]
|
target = game.players[param]
|
||||||
if not target then
|
if not target then
|
||||||
player_print(table.concat {"Sorry, player '", param, "' was not found."})
|
player_print(table.concat {"Sorry, player '", param, "' was not found."})
|
||||||
return
|
return
|
||||||
@@ -179,7 +179,7 @@ local function walkabout(cmd)
|
|||||||
duration = 15
|
duration = 15
|
||||||
end
|
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
|
if player == nil or not player.valid or global.walking[player.index] then
|
||||||
player_print(player_name .. ' could not go on a walkabout.')
|
player_print(player_name .. ' could not go on a walkabout.')
|
||||||
return
|
return
|
||||||
@@ -268,7 +268,7 @@ local function follow(cmd)
|
|||||||
log("<Server can't do that.")
|
log("<Server can't do that.")
|
||||||
return
|
return
|
||||||
end
|
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[game.player.name] = cmd.parameter
|
||||||
global.follows.n_entries = global.follows.n_entries + 1
|
global.follows.n_entries = global.follows.n_entries + 1
|
||||||
else
|
else
|
||||||
@@ -298,7 +298,7 @@ local function built_entity(event)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
Game.players[index].teleport(entity.position)
|
Game.get_player_by_index(index).teleport(entity.position)
|
||||||
entity.destroy()
|
entity.destroy()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -371,7 +371,7 @@ local function tempban(cmd)
|
|||||||
player_print('Tempban failed. Usage: /tempban <player> <minutes> Temporarily bans a player.')
|
player_print('Tempban failed. Usage: /tempban <player> <minutes> Temporarily bans a player.')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if not Game.players[params[1]] then
|
if not game.players[params[1]] then
|
||||||
player_print("Player doesn't exist.")
|
player_print("Player doesn't exist.")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -430,23 +430,23 @@ local function undo(cmd)
|
|||||||
cant_run(cmd.name)
|
cant_run(cmd.name)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if cmd.parameter and Game.players[cmd.parameter] then
|
if cmd.parameter and game.players[cmd.parameter] then
|
||||||
if
|
if
|
||||||
not global.undo_warned_players[game.player.index] or
|
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
|
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(
|
game.player.print(
|
||||||
string.format(
|
string.format(
|
||||||
'Warning! You are about to remove %s entities and restore %s entities.',
|
'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),
|
#Utils.find_entities_by_last_user(game.players[cmd.parameter], game.surfaces.nauvis),
|
||||||
Antigrief.count_removed_entities(Game.players[cmd.parameter])
|
Antigrief.count_removed_entities(game.players[cmd.parameter])
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
game.player.print('To execute the command please run it again.')
|
game.player.print('To execute the command please run it again.')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
Antigrief.undo(Game.players[cmd.parameter])
|
Antigrief.undo(game.players[cmd.parameter])
|
||||||
game.print(string.format('Undoing everything %s did...', cmd.parameter))
|
game.print(string.format('Undoing everything %s did...', cmd.parameter))
|
||||||
global.undo_warned_players[game.player.index] = nil
|
global.undo_warned_players[game.player.index] = nil
|
||||||
else
|
else
|
||||||
@@ -473,7 +473,7 @@ local function find_player(cmd)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local target = Game.players[name]
|
local target = game.players[name]
|
||||||
if not target then
|
if not target then
|
||||||
player.print('player ' .. name .. ' not found')
|
player.print('player ' .. name .. ' not found')
|
||||||
return
|
return
|
||||||
@@ -505,7 +505,7 @@ local function jail_player(cmd)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local target_player = Game.players[target]
|
local target_player = game.players[target]
|
||||||
|
|
||||||
if not target_player then
|
if not target_player then
|
||||||
player_print('Unknown player.')
|
player_print('Unknown player.')
|
||||||
@@ -567,7 +567,7 @@ local function unjail_player(cmd)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local target_player = Game.players[target]
|
local target_player = game.players[target]
|
||||||
if not target_player then
|
if not target_player then
|
||||||
player_print('Unknown player.')
|
player_print('Unknown player.')
|
||||||
return
|
return
|
||||||
@@ -724,7 +724,7 @@ local function report(cmd)
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
local reported_player_name = params[1] or ''
|
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
|
if not reported_player then
|
||||||
reporting_player.print(reported_player_name .. ' does not exist.')
|
reporting_player.print(reported_player_name .. ' does not exist.')
|
||||||
@@ -741,7 +741,7 @@ commands.add_command(
|
|||||||
'Shows user reports (Admins only)',
|
'Shows user reports (Admins only)',
|
||||||
function(event)
|
function(event)
|
||||||
if game.player and game.player.admin then
|
if game.player and game.player.admin then
|
||||||
Report.show_reports(Game.players[event.player_index])
|
Report.show_reports(Game.get_player_by_index(event.player_index))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
@@ -116,7 +116,7 @@ local total_fish_market_bonus_messages = #fish_market_bonus_message
|
|||||||
|
|
||||||
local function fish_earned(event, amount)
|
local function fish_earned(event, amount)
|
||||||
local player_index = event.player_index
|
local player_index = event.player_index
|
||||||
local player = Game.players[player_index]
|
local player = Game.get_player_by_index(player_index)
|
||||||
|
|
||||||
local stack = {name = market_item, count = amount}
|
local stack = {name = market_item, count = amount}
|
||||||
local inserted = player.insert(stack)
|
local inserted = player.insert(stack)
|
||||||
@@ -199,7 +199,7 @@ local function pet(player, entity_name)
|
|||||||
if not player then
|
if not player then
|
||||||
player = game.connected_players[1]
|
player = game.connected_players[1]
|
||||||
else
|
else
|
||||||
player = Game.players[player]
|
player = game.players[player]
|
||||||
end
|
end
|
||||||
if not entity_name then
|
if not entity_name then
|
||||||
entity_name = 'small-biter'
|
entity_name = 'small-biter'
|
||||||
@@ -312,12 +312,12 @@ local function market_item_purchased(event)
|
|||||||
PlayerStats.change_coin_spent(player_index, fish_cost)
|
PlayerStats.change_coin_spent(player_index, fish_cost)
|
||||||
|
|
||||||
if event.offer_index == 1 then -- Temporary speed bonus
|
if event.offer_index == 1 then -- Temporary speed bonus
|
||||||
local player = Game.players[player_index]
|
local player = Game.get_player_by_index(player_index)
|
||||||
boost_player_runningspeed(player, market)
|
boost_player_runningspeed(player, market)
|
||||||
end
|
end
|
||||||
|
|
||||||
if event.offer_index == 2 then -- Temporary mining bonus
|
if event.offer_index == 2 then -- Temporary mining bonus
|
||||||
local player = Game.players[player_index]
|
local player = Game.get_player_by_index(player_index)
|
||||||
boost_player_miningspeed(player, market)
|
boost_player_miningspeed(player, market)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -377,14 +377,14 @@ local function on_180_ticks()
|
|||||||
if global.player_speed_boost_records then
|
if global.player_speed_boost_records then
|
||||||
for k, v in pairs(global.player_speed_boost_records) do
|
for k, v in pairs(global.player_speed_boost_records) do
|
||||||
if game.tick - v.start_tick > 3000 then
|
if game.tick - v.start_tick > 3000 then
|
||||||
reset_player_runningspeed(Game.players[k])
|
reset_player_runningspeed(Game.get_player_by_index(k))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if global.player_mining_boost_records then
|
if global.player_mining_boost_records then
|
||||||
for k, v in pairs(global.player_mining_boost_records) do
|
for k, v in pairs(global.player_mining_boost_records) do
|
||||||
if game.tick - v.start_tick > 6000 then
|
if game.tick - v.start_tick > 6000 then
|
||||||
reset_player_miningspeed(Game.players[k])
|
reset_player_miningspeed(Game.get_player_by_index(k))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -392,7 +392,7 @@ local function on_180_ticks()
|
|||||||
|
|
||||||
if global.player_pets then
|
if global.player_pets then
|
||||||
for _, pets in pairs(global.player_pets) do
|
for _, pets in pairs(global.player_pets) do
|
||||||
local player = Game.players[pets.owner]
|
local player = game.players[pets.owner]
|
||||||
if
|
if
|
||||||
pcall(
|
pcall(
|
||||||
function()
|
function()
|
||||||
|
@@ -42,8 +42,8 @@ end
|
|||||||
function walk_on_tick()
|
function walk_on_tick()
|
||||||
if global.follows.n_entries > 0 then
|
if global.follows.n_entries > 0 then
|
||||||
for k,v in pairs(global.follows) do
|
for k,v in pairs(global.follows) do
|
||||||
local follower = Game.players[k]
|
local follower = game.playesr[k]
|
||||||
local target = Game.players[v]
|
local target = game.players[v]
|
||||||
if follower ~= nil and target ~= nil then
|
if follower ~= nil and target ~= nil then
|
||||||
local d = Utils.distance(follower, target)
|
local d = Utils.distance(follower, target)
|
||||||
if follower.connected and target.connected and d < 32 then
|
if follower.connected and target.connected and d < 32 then
|
||||||
|
@@ -189,7 +189,7 @@ local function gui_opened(event)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local player = Game.players[event.player_index]
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
if not player or not player.valid then
|
if not player or not player.valid then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -225,7 +225,7 @@ Event.add(defines.events.on_gui_opened, gui_opened)
|
|||||||
Event.add(
|
Event.add(
|
||||||
defines.events.on_player_died,
|
defines.events.on_player_died,
|
||||||
function(event)
|
function(event)
|
||||||
local player = Game.players[event.player_index or 0]
|
local player = Game.get_player_by_index(event.player_index or 0)
|
||||||
|
|
||||||
if not player or not player.valid then
|
if not player or not player.valid then
|
||||||
return
|
return
|
||||||
|
2
info.lua
2
info.lua
@@ -634,7 +634,7 @@ local function toggle(event)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function player_created(event)
|
local function player_created(event)
|
||||||
local player = Game.players[event.player_index]
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
|
|
||||||
if not player or not player.valid then
|
if not player or not player.valid then
|
||||||
return
|
return
|
||||||
|
@@ -473,7 +473,7 @@ end
|
|||||||
|
|
||||||
local function on_player_joined_game(event)
|
local function on_player_joined_game(event)
|
||||||
local surface = game.surfaces[1]
|
local surface = game.surfaces[1]
|
||||||
local player = Game.players[event.player_index]
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
if not global.cave_miner_init_done then
|
if not global.cave_miner_init_done then
|
||||||
local p = surface.find_non_colliding_position("player", {0,-40}, 10, 1)
|
local p = surface.find_non_colliding_position("player", {0,-40}, 10, 1)
|
||||||
game.forces["player"].set_spawn_position(p,surface)
|
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
|
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.print("Map generation done!", { r=0.22, g=0.99, b=0.99})
|
||||||
|
|
||||||
Game.players[1].force = game.forces["player"]
|
Game.get_player_by_index(1).force = game.forces["player"]
|
||||||
global.map_pregeneration_is_active = nil
|
global.map_pregeneration_is_active = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -774,7 +774,7 @@ end
|
|||||||
|
|
||||||
local function on_marked_for_deconstruction(event)
|
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
|
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.get_player_by_index(event.player_index).force.name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -790,7 +790,7 @@ local function pre_player_mined_item(event)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if event.entity.name == "rock-huge" or event.entity.name == "rock-big" or event.entity.name == "sand-rock-big" then
|
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.get_player_by_index(event.player_index)
|
||||||
local rock_position = {x = event.entity.position.x, y = event.entity.position.y}
|
local rock_position = {x = event.entity.position.x, y = event.entity.position.y}
|
||||||
event.entity.destroy()
|
event.entity.destroy()
|
||||||
local tile_distance_to_center = math.sqrt(rock_position.x^2 + rock_position.y^2)
|
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
|
end
|
||||||
if event.entity.name == "fish" then
|
if event.entity.name == "fish" then
|
||||||
if math.random(1,2) == 1 then
|
if math.random(1,2) == 1 then
|
||||||
local player = Game.players[event.player_index]
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
local health = player.character.health
|
local health = player.character.health
|
||||||
player.character.damage(math.random(50,150),"enemy")
|
player.character.damage(math.random(50,150),"enemy")
|
||||||
if not player.character then
|
if not player.character then
|
||||||
@@ -920,7 +920,7 @@ local function on_entity_damaged(event)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function on_player_respawned(event)
|
local function on_player_respawned(event)
|
||||||
local player = Game.players[event.player_index]
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
player.character.disable_flashlight()
|
player.character.disable_flashlight()
|
||||||
global.player_hunger[player.name] = global.player_hunger_spawn_value
|
global.player_hunger[player.name] = global.player_hunger_spawn_value
|
||||||
hunger_update(player, 0)
|
hunger_update(player, 0)
|
||||||
@@ -936,7 +936,7 @@ end
|
|||||||
local function on_gui_click(event)
|
local function on_gui_click(event)
|
||||||
if not (event and event.element and event.element.valid) then return end
|
if not (event and event.element and event.element.valid) then return end
|
||||||
|
|
||||||
local player = Game.players[event.element.player_index]
|
local player = Game.get_player_by_index(event.element.player_index)
|
||||||
local name = event.element.name
|
local name = event.element.name
|
||||||
local frame = player.gui.top["caver_miner_stats_frame"]
|
local frame = player.gui.top["caver_miner_stats_frame"]
|
||||||
|
|
||||||
@@ -951,7 +951,7 @@ end
|
|||||||
|
|
||||||
local function on_player_used_capsule(event)
|
local function on_player_used_capsule(event)
|
||||||
if event.item.name == "raw-fish" then
|
if event.item.name == "raw-fish" then
|
||||||
local player = Game.players[event.player_index]
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
hunger_update(player, global.player_hunger_fish_food_value)
|
hunger_update(player, global.player_hunger_fish_food_value)
|
||||||
player.play_sound{path="utility/armor_insert", volume_modifier=1}
|
player.play_sound{path="utility/armor_insert", volume_modifier=1}
|
||||||
refresh_gui()
|
refresh_gui()
|
||||||
@@ -961,7 +961,7 @@ end
|
|||||||
function map_pregen()
|
function map_pregen()
|
||||||
local radius = 1280
|
local radius = 1280
|
||||||
if not game.forces.map_pregen then game.create_force("map_pregen") end
|
if not game.forces.map_pregen then game.create_force("map_pregen") end
|
||||||
Game.players[1].force = game.forces["map_pregen"]
|
Game.get_player_by_index(1).force = game.forces["map_pregen"]
|
||||||
game.forces.map_pregen.chart(game.surfaces[1],{{x = -1 * radius, y = -1 * radius}, {x = radius, y = radius}})
|
game.forces.map_pregen.chart(game.surfaces[1],{{x = -1 * radius, y = -1 * radius}, {x = radius, y = radius}})
|
||||||
global.map_pregeneration_is_active = true
|
global.map_pregeneration_is_active = true
|
||||||
end
|
end
|
||||||
|
@@ -54,7 +54,7 @@ Event.add(
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local p = Game.players[event.player_index]
|
local p = Game.get_player_by_index(event.player_index)
|
||||||
if not p or not p.valid then
|
if not p or not p.valid then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@@ -30,7 +30,7 @@ Event.add(
|
|||||||
local surface = game.surfaces[event.surface_index]
|
local surface = game.surfaces[event.surface_index]
|
||||||
surface.set_tiles(new_tiles)
|
surface.set_tiles(new_tiles)
|
||||||
|
|
||||||
local player = Game.players[event.player_index]
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
player.insert {name = item_name, count = count}
|
player.insert {name = item_name, count = count}
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
@@ -13,7 +13,7 @@ Event.on_init(function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
Event.add(defines.events.on_player_created, function(event)
|
Event.add(defines.events.on_player_created, function(event)
|
||||||
local player = Game.players[event.player_index]
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
--player.print("Info: PVP server mod 'Bearded Snails' (c) byte");
|
--player.print("Info: PVP server mod 'Bearded Snails' (c) byte");
|
||||||
guiNewPlayer(player.gui.left);
|
guiNewPlayer(player.gui.left);
|
||||||
printNewPlayer(player);
|
printNewPlayer(player);
|
||||||
@@ -31,7 +31,7 @@ Event.add(defines.events.on_player_created, function(event)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
Event.add(defines.events.on_player_respawned, function(event)
|
Event.add(defines.events.on_player_respawned, function(event)
|
||||||
local player = Game.players[event.player_index]
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
|
|
||||||
player.insert{name="heavy-armor", count=1}
|
player.insert{name="heavy-armor", count=1}
|
||||||
player.insert{name="pistol", count=1}
|
player.insert{name="pistol", count=1}
|
||||||
@@ -70,7 +70,7 @@ Event.add(defines.events.on_rocket_launched, function(event)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
Event.add(defines.events.on_gui_click, function(event)
|
Event.add(defines.events.on_gui_click, function(event)
|
||||||
local player = Game.players[event.player_index]
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
local gui = player.gui.left;
|
local gui = player.gui.left;
|
||||||
|
|
||||||
if player.force == game.forces.player and event.element.name == "new_button" then
|
if player.force == game.forces.player and event.element.name == "new_button" then
|
||||||
@@ -92,7 +92,7 @@ Event.add(defines.events.on_gui_click, function(event)
|
|||||||
elseif event.element.name == "inv_button" then
|
elseif event.element.name == "inv_button" then
|
||||||
local name = gui.own_force.inv_name.text;
|
local name = gui.own_force.inv_name.text;
|
||||||
if name ~= nil and validPlayer(name) then
|
if name ~= nil and validPlayer(name) then
|
||||||
local iplayer = Game.players[name];
|
local iplayer = Game.get_player_by_index(name);
|
||||||
local igui = iplayer.gui.left;
|
local igui = iplayer.gui.left;
|
||||||
|
|
||||||
iplayer.force = player.force;
|
iplayer.force = player.force;
|
||||||
@@ -143,7 +143,7 @@ function dist(position1, position2)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function validPlayer(name)
|
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.get_player_by_index(name) ~= nil and Game.get_player_by_index(name).force == game.forces.player then
|
||||||
return true;
|
return true;
|
||||||
end
|
end
|
||||||
return false;
|
return false;
|
||||||
|
@@ -33,9 +33,9 @@ local max = math.max
|
|||||||
local function rso_debug(str)
|
local function rso_debug(str)
|
||||||
if rso_debug_enabled then
|
if rso_debug_enabled then
|
||||||
if (type(str) == "table") then
|
if (type(str) == "table") then
|
||||||
Game.players[1].print(serpent.dump(str))
|
Game.get_player_by_index(1).print(serpent.dump(str))
|
||||||
else
|
else
|
||||||
Game.players[1].print(str)
|
Game.get_player_by_index(1).print(str)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -1137,26 +1137,26 @@ function RSO_init()
|
|||||||
initDone = true
|
initDone = true
|
||||||
|
|
||||||
if surface.map_gen_settings.autoplace_controls["iron-ore"].size ~= "none" then
|
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.get_player_by_index(1).print("RSO WARNING - VANILLA iron-ore GEN IS NOT DISABLED!")
|
||||||
end
|
end
|
||||||
if surface.map_gen_settings.autoplace_controls["copper-ore"].size ~= "none" then
|
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.get_player_by_index(1).print("RSO WARNING - VANILLA copper-ore GEN IS NOT DISABLED!")
|
||||||
end
|
end
|
||||||
if surface.map_gen_settings.autoplace_controls["uranium-ore"].size ~= "none" then
|
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.get_player_by_index(1).print("RSO WARNING - VANILLA uranium-ore GEN IS NOT DISABLED!")
|
||||||
end
|
end
|
||||||
if surface.map_gen_settings.autoplace_controls["crude-oil"].size ~= "none" then
|
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.get_player_by_index(1).print("RSO WARNING - VANILLA crude-oil GEN IS NOT DISABLED!")
|
||||||
end
|
end
|
||||||
if surface.map_gen_settings.autoplace_controls["enemy-base"].size ~= "none" then
|
if surface.map_gen_settings.autoplace_controls["enemy-base"].size ~= "none" then
|
||||||
-- Not a problem, as this RSO does not gen biters
|
-- Not a problem, as this RSO does not gen biters
|
||||||
-- Game.players[1].print("RSO WARNING - VANILLA enemy-base GEN IS NOT DISABLED!")
|
-- Game.get_player_by_index(1).print("RSO WARNING - VANILLA enemy-base GEN IS NOT DISABLED!")
|
||||||
end
|
end
|
||||||
if surface.map_gen_settings.autoplace_controls["stone"].size ~= "none" then
|
if surface.map_gen_settings.autoplace_controls["stone"].size ~= "none" then
|
||||||
Game.players[1].print("RSO WARNING - VANILLA stone GEN IS NOT DISABLED!")
|
Game.get_player_by_index(1).print("RSO WARNING - VANILLA stone GEN IS NOT DISABLED!")
|
||||||
end
|
end
|
||||||
if surface.map_gen_settings.autoplace_controls["coal"].size ~= "none" then
|
if surface.map_gen_settings.autoplace_controls["coal"].size ~= "none" then
|
||||||
Game.players[1].print("RSO WARNING - VANILLA coal GEN IS NOT DISABLED!")
|
Game.get_player_by_index(1).print("RSO WARNING - VANILLA coal GEN IS NOT DISABLED!")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@@ -119,7 +119,7 @@ local function gui_opened(event)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local player = Game.players[event.player_index]
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
if not player or not player.valid then
|
if not player or not player.valid then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -157,7 +157,7 @@ Gui.on_custom_close(
|
|||||||
Event.add(
|
Event.add(
|
||||||
defines.events.on_player_died,
|
defines.events.on_player_died,
|
||||||
function(event)
|
function(event)
|
||||||
local player = Game.players[event.player_index or 0]
|
local player = Game.get_player_by_index(event.player_index or 0)
|
||||||
|
|
||||||
if not player or not player.valid then
|
if not player or not player.valid then
|
||||||
return
|
return
|
||||||
|
@@ -36,7 +36,7 @@ local death_messages = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
local function player_died(event)
|
local function player_died(event)
|
||||||
local player = Game.players[event.player_index]
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
if not player or not player.valid then
|
if not player or not player.valid then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@@ -7,12 +7,12 @@ 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)
|
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.players[player])
|
return allowed_to_nuke(Game.get_player_by_index(player))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function ammo_changed(event)
|
local function ammo_changed(event)
|
||||||
local player = Game.players[event.player_index]
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
if allowed_to_nuke(player) then return end
|
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
|
if nukes > 0 then
|
||||||
@@ -31,7 +31,7 @@ local function ammo_changed(event)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function on_player_deconstructed_area(event)
|
local function on_player_deconstructed_area(event)
|
||||||
local player = Game.players[event.player_index]
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
if allowed_to_nuke(player) then return end
|
if allowed_to_nuke(player) then return end
|
||||||
player.remove_item({name="deconstruction-planner", count=1000})
|
player.remove_item({name="deconstruction-planner", count=1000})
|
||||||
|
|
||||||
@@ -60,8 +60,8 @@ local function on_player_deconstructed_area(event)
|
|||||||
Utils.print_admins("Warning! " .. player.name .. " just tried to deconstruct " .. tostring(#entities) .. " entities!")
|
Utils.print_admins("Warning! " .. player.name .. " just tried to deconstruct " .. tostring(#entities) .. " entities!")
|
||||||
end
|
end
|
||||||
for _,entity in pairs(entities) do
|
for _,entity in pairs(entities) do
|
||||||
if entity.valid and entity.to_be_deconstructed(Game.players[event.player_index].force) then
|
if entity.valid and entity.to_be_deconstructed(Game.get_player_by_index(event.player_index).force) then
|
||||||
entity.cancel_deconstruction(Game.players[event.player_index].force)
|
entity.cancel_deconstruction(Game.get_player_by_index(event.player_index).force)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -108,7 +108,7 @@ end
|
|||||||
global.players_warned = {}
|
global.players_warned = {}
|
||||||
local function on_capsule_used(event)
|
local function on_capsule_used(event)
|
||||||
local item = event.item
|
local item = event.item
|
||||||
local player = Game.players[event.player_index]
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
|
|
||||||
if not player or not player.valid or
|
if not player or not player.valid or
|
||||||
(global.scenario.config.nuke_control.enable_autokick and global.scenario.config.nuke_control.enable_autoban) then
|
(global.scenario.config.nuke_control.enable_autokick and global.scenario.config.nuke_control.enable_autoban) then
|
||||||
|
@@ -53,7 +53,7 @@ local function player_build_tile(event)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local player = Game.players[event.player_index]
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
if not player.gui.left[main_frame_name] then
|
if not player.gui.left[main_frame_name] then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -78,7 +78,7 @@ local function player_joined(event)
|
|||||||
if not global.scenario.config.paint.enable then
|
if not global.scenario.config.paint.enable then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local player = Game.players[event.player_index]
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
if not player or not player.valid then
|
if not player or not player.valid then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@@ -27,7 +27,7 @@ local player_colors = {
|
|||||||
Event.add(
|
Event.add(
|
||||||
defines.events.on_player_created,
|
defines.events.on_player_created,
|
||||||
function(event)
|
function(event)
|
||||||
local player = Game.players[event.player_index]
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
if not player or not player.valid then
|
if not player or not player.valid then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@@ -612,7 +612,7 @@ local function tick()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function player_joined(event)
|
local function player_joined(event)
|
||||||
local player = Game.players[event.player_index]
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
if not player or not player.valid then
|
if not player or not player.valid then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@@ -31,7 +31,7 @@ Global.register(
|
|||||||
local function player_created(event)
|
local function player_created(event)
|
||||||
local index = event.player_index
|
local index = event.player_index
|
||||||
|
|
||||||
player_last_position[index] = Game.players[index].position
|
player_last_position[index] = Game.get_player_by_index(index).position
|
||||||
player_walk_distances[index] = 0
|
player_walk_distances[index] = 0
|
||||||
player_coin_earned[index] = 0
|
player_coin_earned[index] = 0
|
||||||
player_coin_spent[index] = 0
|
player_coin_spent[index] = 0
|
||||||
|
8
poll.lua
8
poll.lua
@@ -130,7 +130,7 @@ local function redraw_poll_viewer_content(data)
|
|||||||
end
|
end
|
||||||
|
|
||||||
for player_index, answer in pairs(voters) do
|
for player_index, answer in pairs(voters) do
|
||||||
local p = Game.players[player_index]
|
local p = Game.get_player_by_index(player_index)
|
||||||
table.insert(tooltips[answer], p.name)
|
table.insert(tooltips[answer], p.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -157,7 +157,7 @@ local function redraw_poll_viewer_content(data)
|
|||||||
if next(edited_by_players) then
|
if next(edited_by_players) then
|
||||||
local edit_names = {'Edited by '}
|
local edit_names = {'Edited by '}
|
||||||
for pi, _ in pairs(edited_by_players) do
|
for pi, _ in pairs(edited_by_players) do
|
||||||
local p = Game.players[pi]
|
local p = Game.get_player_by_index(pi)
|
||||||
if p and p.valid then
|
if p and p.valid then
|
||||||
table.insert(edit_names, p.name)
|
table.insert(edit_names, p.name)
|
||||||
table.insert(edit_names, ', ')
|
table.insert(edit_names, ', ')
|
||||||
@@ -667,7 +667,7 @@ local function update_vote(voters, answer, direction)
|
|||||||
local tooltip = {}
|
local tooltip = {}
|
||||||
for pi, a in pairs(voters) do
|
for pi, a in pairs(voters) do
|
||||||
if a == answer then
|
if a == answer then
|
||||||
local player = Game.players[pi]
|
local player = Game.get_player_by_index(pi)
|
||||||
table.insert(tooltip, player.name)
|
table.insert(tooltip, player.name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -739,7 +739,7 @@ local function vote(event)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function player_joined(event)
|
local function player_joined(event)
|
||||||
local player = Game.players[event.player_index]
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
if not player or not player.valid then
|
if not player or not player.valid then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
10
report.lua
10
report.lua
@@ -19,8 +19,8 @@ local function draw_report(parent, report_id)
|
|||||||
parent.add {type = "label", caption="No reports yet."}
|
parent.add {type = "label", caption="No reports yet."}
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local reported_player_name = Game.players[report.reported_player_index].name
|
local reported_player_name = Game.get_player_by_index(report.reported_player_index).name
|
||||||
local reporting_player_name = Game.players[report.reporting_player_index].name
|
local reporting_player_name = Game.get_player_by_index(report.reporting_player_index).name
|
||||||
local time = Utils.format_time(report.tick)
|
local time = Utils.format_time(report.tick)
|
||||||
local time_ago = Utils.format_time(game.tick - report.tick)
|
local time_ago = Utils.format_time(game.tick - report.tick)
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ Module.show_reports = function(player)
|
|||||||
button_cell.add {
|
button_cell.add {
|
||||||
type="button",
|
type="button",
|
||||||
name=report_tab_button_name,
|
name=report_tab_button_name,
|
||||||
caption = Game.players[report.reported_player_index].name
|
caption = Game.get_player_by_index(report.reported_player_index).name
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -179,9 +179,9 @@ Gui.on_click(
|
|||||||
local reported_player_index = data["reported_player_index"]
|
local reported_player_index = data["reported_player_index"]
|
||||||
|
|
||||||
Gui.destroy(frame)
|
Gui.destroy(frame)
|
||||||
Module.report(event.player, Game.players[reported_player_index], msg)
|
Module.report(event.player, Game.get_player_by_index(reported_player_index), msg)
|
||||||
|
|
||||||
event.player.print("Sucessfully reported " .. Game.players[reported_player_index].name)
|
event.player.print("Sucessfully reported " .. Game.get_player_by_index(reported_player_index).name)
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -4,7 +4,7 @@ local Game = require 'utils.game'
|
|||||||
if not global.score_rockets_launched then global.score_rockets_launched = 0 end
|
if not global.score_rockets_launched then global.score_rockets_launched = 0 end
|
||||||
|
|
||||||
local function create_score_gui(event)
|
local function create_score_gui(event)
|
||||||
local player = Game.players[event.player_index]
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
|
|
||||||
if player.gui.top.score == nil then
|
if player.gui.top.score == nil then
|
||||||
local button = player.gui.top.add({ type = "sprite-button", name = "score", sprite = "item/rocket-silo" })
|
local button = player.gui.top.add({ type = "sprite-button", name = "score", sprite = "item/rocket-silo" })
|
||||||
@@ -19,8 +19,8 @@ end
|
|||||||
|
|
||||||
function refresh_score()
|
function refresh_score()
|
||||||
local x = 1
|
local x = 1
|
||||||
while (Game.players[x] ~= nil) do
|
while (Game.get_player_by_index(x) ~= nil) do
|
||||||
local player = Game.players[x]
|
local player = Game.get_player_by_index(x)
|
||||||
local frame = player.gui.top["score_panel"]
|
local frame = player.gui.top["score_panel"]
|
||||||
|
|
||||||
if (frame) then
|
if (frame) then
|
||||||
@@ -73,7 +73,7 @@ end
|
|||||||
local function on_gui_click(event)
|
local function on_gui_click(event)
|
||||||
if not (event and event.element and event.element.valid) then return end
|
if not (event and event.element and event.element.valid) then return end
|
||||||
|
|
||||||
local player = Game.players[event.element.player_index]
|
local player = Game.get_player_by_index(event.element.player_index)
|
||||||
local name = event.element.name
|
local name = event.element.name
|
||||||
local frame = player.gui.top["score_panel"]
|
local frame = player.gui.top["score_panel"]
|
||||||
|
|
||||||
|
@@ -56,7 +56,7 @@ local function player_joined_game(event)
|
|||||||
|
|
||||||
local spawn = global.spawns[spawn_name]
|
local spawn = global.spawns[spawn_name]
|
||||||
global.player_spawns[index] = spawn_name
|
global.player_spawns[index] = spawn_name
|
||||||
Game.players[index].teleport(spawn)
|
Game.get_player_by_index(index).teleport(spawn)
|
||||||
|
|
||||||
local count = spawn.count
|
local count = spawn.count
|
||||||
spawn.count = count + 1
|
spawn.count = count + 1
|
||||||
@@ -80,11 +80,11 @@ local function player_respawned(event)
|
|||||||
|
|
||||||
if not spawn then return end
|
if not spawn then return end
|
||||||
|
|
||||||
Game.players[index].teleport(spawn)
|
Game.get_player_by_index(index).teleport(spawn)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function tp_spawn(player_name, spawn_name)
|
local function tp_spawn(player_name, spawn_name)
|
||||||
local player = Game.players[player_name]
|
local player = Game.get_player_by_index(player_name)
|
||||||
if not player then
|
if not player then
|
||||||
player_name = player_name or ""
|
player_name = player_name or ""
|
||||||
game.player.print("player " .. player_name .. " does not exist.")
|
game.player.print("player " .. player_name .. " does not exist.")
|
||||||
@@ -110,7 +110,7 @@ local function change_spawn(player_name, spawn_name)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local player = Game.players[player_name]
|
local player = Game.get_player_by_index(player_name)
|
||||||
|
|
||||||
if not player then
|
if not player then
|
||||||
player_name = player_name or ""
|
player_name = player_name or ""
|
||||||
@@ -152,7 +152,7 @@ local function print_players_for_spawn(target_spawn_name)
|
|||||||
str = ""
|
str = ""
|
||||||
for index, spawn_name in pairs(global.player_spawns) do
|
for index, spawn_name in pairs(global.player_spawns) do
|
||||||
if target_spawn_name == spawn_name then
|
if target_spawn_name == spawn_name then
|
||||||
local player = Game.players[index]
|
local player = Game.get_player_by_index(index)
|
||||||
if player.connected then
|
if player.connected then
|
||||||
str = str .. player.name .. ", "
|
str = str .. player.name .. ", "
|
||||||
end
|
end
|
||||||
|
@@ -87,7 +87,7 @@ local function get_size(players, show_offline)
|
|||||||
size = table.size(players)
|
size = table.size(players)
|
||||||
else
|
else
|
||||||
for pi, _ in pairs(players) do
|
for pi, _ in pairs(players) do
|
||||||
local player = Game.players[pi]
|
local player = Game.get_player_by_index(pi)
|
||||||
if player and player.valid and player.connected then
|
if player and player.valid and player.connected then
|
||||||
size = size + 1
|
size = size + 1
|
||||||
end
|
end
|
||||||
@@ -119,7 +119,7 @@ local delete_tag_name = Gui.uid_name()
|
|||||||
local close_create_tag_name = Gui.uid_name()
|
local close_create_tag_name = Gui.uid_name()
|
||||||
|
|
||||||
local function player_joined(event)
|
local function player_joined(event)
|
||||||
local player = Game.players[event.player_index]
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
if not player or not player.valid then
|
if not player or not player.valid then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -180,11 +180,11 @@ local function draw_main_frame_content(parent)
|
|||||||
|
|
||||||
if players then
|
if players then
|
||||||
for k, _ in pairs(players) do
|
for k, _ in pairs(players) do
|
||||||
local p = Game.players[k]
|
local p = Game.get_player_by_index(k)
|
||||||
if p and p.valid and p.connected then
|
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 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.get_player_by_index(k).name}
|
||||||
label.style.top_padding = 8
|
label.style.top_padding = 8
|
||||||
label.style.font_color = color
|
label.style.font_color = color
|
||||||
end
|
end
|
||||||
@@ -679,7 +679,7 @@ local function tag_command(cmd)
|
|||||||
return
|
return
|
||||||
end
|
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
|
if target_player == nil or not target_player.valid then
|
||||||
player_print('Player does not exist.')
|
player_print('Player does not exist.')
|
||||||
|
@@ -112,7 +112,7 @@ local function get_editing_players_message(players)
|
|||||||
local message = {'Editing players: '}
|
local message = {'Editing players: '}
|
||||||
|
|
||||||
for pi, _ in pairs(players) do
|
for pi, _ in pairs(players) do
|
||||||
local name = Game.players[pi].name
|
local name = Game.get_player_by_index(pi).name
|
||||||
table.insert(message, name)
|
table.insert(message, name)
|
||||||
table.insert(message, ', ')
|
table.insert(message, ', ')
|
||||||
end
|
end
|
||||||
@@ -585,7 +585,7 @@ local function draw_create_task_frame(left, previous_task)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function player_created(event)
|
local function player_created(event)
|
||||||
local player = Game.players[event.player_index]
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
if not player or not player.valid then
|
if not player or not player.valid then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -631,7 +631,7 @@ local function player_created(event)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function player_left(event)
|
local function player_left(event)
|
||||||
local player = Game.players[event.player_index]
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
local left = player.gui.left
|
local left = player.gui.left
|
||||||
|
|
||||||
local frame = left[edit_announcements_frame_name]
|
local frame = left[edit_announcements_frame_name]
|
||||||
|
@@ -53,7 +53,7 @@ local function on_pre_death(event)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local player_index = event.player_index
|
local player_index = event.player_index
|
||||||
local player = Game.players[player_index]
|
local player = Game.get_player_by_index(player_index)
|
||||||
if not player or not player.valid then
|
if not player or not player.valid then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@@ -9,7 +9,7 @@ local function player_built_entity(event)
|
|||||||
local y = math.random(1, 3)
|
local y = math.random(1, 3)
|
||||||
if y ~= 1 then
|
if y ~= 1 then
|
||||||
local x = math.random(1, #Game.players)
|
local x = math.random(1, #Game.players)
|
||||||
local player = Game.players[x]
|
local player = Game.get_player_by_index(x)
|
||||||
event.created_entity.backer_name = player.name
|
event.created_entity.backer_name = player.name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@@ -28,8 +28,8 @@ Module.add_regular = function(player_name)
|
|||||||
if Module.is_regular(player_name) then
|
if Module.is_regular(player_name) then
|
||||||
player_print(player_name .. ' is already a regular.')
|
player_print(player_name .. ' is already a regular.')
|
||||||
else
|
else
|
||||||
if Game.players[player_name] then
|
if game.players[player_name] then
|
||||||
player_name = Game.players[player_name].name
|
player_name = game.players[player_name].name
|
||||||
game.print(actor .. ' promoted ' .. player_name .. ' to regular.')
|
game.print(actor .. ' promoted ' .. player_name .. ' to regular.')
|
||||||
global.regulars[player_name] = true
|
global.regulars[player_name] = true
|
||||||
update_file()
|
update_file()
|
||||||
@@ -42,8 +42,8 @@ end
|
|||||||
Module.remove_regular =
|
Module.remove_regular =
|
||||||
function(player_name)
|
function(player_name)
|
||||||
local actor = Utils.get_actor()
|
local actor = Utils.get_actor()
|
||||||
if Game.players[player_name] then
|
if game.players[player_name] then
|
||||||
player_name = Game.players[player_name].name
|
player_name = game.players[player_name].name
|
||||||
if Module.is_regular(player_name) then
|
if Module.is_regular(player_name) then
|
||||||
game.print(player_name .. ' was demoted from regular by ' .. actor .. '.')
|
game.print(player_name .. ' was demoted from regular by ' .. actor .. '.')
|
||||||
end
|
end
|
||||||
@@ -85,7 +85,7 @@ end
|
|||||||
Event.add(
|
Event.add(
|
||||||
defines.events.on_player_joined_game,
|
defines.events.on_player_joined_game,
|
||||||
function(event)
|
function(event)
|
||||||
local correctCaseName = Game.players[event.player_index].name
|
local correctCaseName = Game.get_player_by_index(event.player_index).name
|
||||||
if global.regulars[correctCaseName:lower()] and not global.regulars[correctCaseName] then
|
if global.regulars[correctCaseName:lower()] and not global.regulars[correctCaseName] then
|
||||||
global.regulars[correctCaseName:lower()] = nil
|
global.regulars[correctCaseName:lower()] = nil
|
||||||
global.regulars[correctCaseName] = true
|
global.regulars[correctCaseName] = true
|
||||||
|
@@ -1,12 +1,24 @@
|
|||||||
local Event = require 'utils.event'
|
|
||||||
local Global = require 'utils.global'
|
local Global = require 'utils.global'
|
||||||
|
|
||||||
local Game = {}
|
local Game = {}
|
||||||
|
|
||||||
local players
|
local bad_name_players = {}
|
||||||
|
Global.register(
|
||||||
|
bad_name_players,
|
||||||
|
function(tbl)
|
||||||
|
bad_name_players = tbl
|
||||||
|
end
|
||||||
|
)
|
||||||
|
|
||||||
local function get_player(index)
|
--[[
|
||||||
|
Due to a bug in the Factorio api the following expression isn't guaranteed to be true.
|
||||||
|
game.players[player.index] == player
|
||||||
|
get_player_by_index(index) will always return the correct player.
|
||||||
|
When looking up players by name or iterating through all players use game.players instead.
|
||||||
|
]]
|
||||||
|
function Game.get_player_by_index(index)
|
||||||
local p = game.players[index]
|
local p = game.players[index]
|
||||||
|
|
||||||
if not p then
|
if not p then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
@@ -14,38 +26,17 @@ local function get_player(index)
|
|||||||
return p
|
return p
|
||||||
end
|
end
|
||||||
|
|
||||||
|
p = bad_name_players[index]
|
||||||
|
if p then
|
||||||
|
return p
|
||||||
|
end
|
||||||
|
|
||||||
for k, v in pairs(game.players) do
|
for k, v in pairs(game.players) do
|
||||||
if k == index then
|
if k == index then
|
||||||
|
bad_name_players[index] = v
|
||||||
return v
|
return v
|
||||||
end
|
end
|
||||||
end
|
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
|
return Game
|
||||||
|
@@ -82,7 +82,7 @@ local function handler_factory(event_id)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local player = Game.players[event.player_index]
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
if not player or not player.valid then
|
if not player or not player.valid then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@@ -80,7 +80,7 @@ Module.find_entities_by_last_user =
|
|||||||
surface = game.surfaces[surface]
|
surface = game.surfaces[surface]
|
||||||
end
|
end
|
||||||
if type(player) == 'number' then
|
if type(player) == 'number' then
|
||||||
player = Game.players[player]
|
player = Game.get_player_by_index(player)
|
||||||
end
|
end
|
||||||
filters.force = player.force.name
|
filters.force = player.force.name
|
||||||
for _, e in pairs(surface.find_entities_filtered(filters)) do
|
for _, e in pairs(surface.find_entities_filtered(filters)) do
|
||||||
|
@@ -161,12 +161,12 @@ local function market_item_purchased(event)
|
|||||||
PlayerStats.change_fish_spent(player_index, cost)
|
PlayerStats.change_fish_spent(player_index, cost)
|
||||||
|
|
||||||
if event.offer_index == 1 then -- Temporary speed bonus
|
if event.offer_index == 1 then -- Temporary speed bonus
|
||||||
local player = Game.players[player_index]
|
local player = Game.get_player_by_index(player_index)
|
||||||
boost_player_runningspeed(player, market)
|
boost_player_runningspeed(player, market)
|
||||||
end
|
end
|
||||||
|
|
||||||
if event.offer_index == 2 then -- Temporary mining bonus
|
if event.offer_index == 2 then -- Temporary mining bonus
|
||||||
local player = Game.players[player_index]
|
local player = Game.get_player_by_index(player_index)
|
||||||
boost_player_miningspeed(player, market)
|
boost_player_miningspeed(player, market)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -180,14 +180,14 @@ local function on_180_ticks()
|
|||||||
if global.player_speed_boost_records then
|
if global.player_speed_boost_records then
|
||||||
for k, v in pairs(global.player_speed_boost_records) do
|
for k, v in pairs(global.player_speed_boost_records) do
|
||||||
if game.tick - v.start_tick > 3000 then
|
if game.tick - v.start_tick > 3000 then
|
||||||
reset_player_runningspeed(Game.players[k])
|
reset_player_runningspeed(Game.get_player_by_index(k))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if global.player_mining_boost_records then
|
if global.player_mining_boost_records then
|
||||||
for k, v in pairs(global.player_mining_boost_records) do
|
for k, v in pairs(global.player_mining_boost_records) do
|
||||||
if game.tick - v.start_tick > 6000 then
|
if game.tick - v.start_tick > 6000 then
|
||||||
reset_player_miningspeed(Game.players[k])
|
reset_player_miningspeed(Game.get_player_by_index(k))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user