mirror of
https://github.com/Refactorio/RedMew.git
synced 2024-12-04 09:42:30 +02:00
Game.get_player_by_index -> game.get_player
This commit is contained in:
parent
500bcd1a18
commit
880c0366d1
@ -274,7 +274,7 @@ local function built_entity(event)
|
||||
return
|
||||
end
|
||||
|
||||
Game.get_player_by_index(index).teleport(entity.position)
|
||||
game.get_player(index).teleport(entity.position)
|
||||
entity.destroy()
|
||||
end
|
||||
end
|
||||
|
@ -59,7 +59,7 @@ end
|
||||
|
||||
local function on_entity_changed(event)
|
||||
local entity = event.entity or event.destination
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
if player.admin or not entity.valid then
|
||||
return
|
||||
end --Freebees for admins
|
||||
@ -109,7 +109,7 @@ Event.add(
|
||||
name = entity.name,
|
||||
position = entity.position,
|
||||
mock = true,
|
||||
last_user = Game.get_player_by_index(1),
|
||||
last_user = game.get_player(1),
|
||||
force = entity.force,
|
||||
direction = get_pre_rotate_direction(entity)
|
||||
}
|
||||
@ -156,7 +156,7 @@ Module.undo =
|
||||
if type(player) == 'nil' or type(player) == 'string' then
|
||||
return --No support for strings!
|
||||
elseif type(player) == 'number' then
|
||||
player = Game.get_player_by_index(player)
|
||||
player = game.get_player(player)
|
||||
end
|
||||
|
||||
--Remove all items from all surfaces that player placed an entity on
|
||||
|
@ -23,7 +23,7 @@ local function get_player(event)
|
||||
if not player_index then
|
||||
return nil
|
||||
end
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
if not player or not player.valid then
|
||||
return nil
|
||||
end
|
||||
@ -88,7 +88,7 @@ local function mentions(event)
|
||||
word = 'admin'
|
||||
end
|
||||
if admin_call and p.admin then
|
||||
local message = {'chat_triggers.mention_success', prefix, Game.get_player_by_index(event.player_index).name, word}
|
||||
local message = {'chat_triggers.mention_success', prefix, game.get_player(event.player_index).name, word}
|
||||
p.print(message, Color.yellow)
|
||||
p.play_sound {path = 'utility/new_objective', volume_modifier = 1}
|
||||
success = true
|
||||
@ -101,7 +101,7 @@ local function mentions(event)
|
||||
success = true
|
||||
break
|
||||
end
|
||||
p.print(prefix .. Game.get_player_by_index(event.player_index).name .. ' mentioned you!', Color.yellow)
|
||||
p.print(prefix .. game.get_player(event.player_index).name .. ' mentioned you!', Color.yellow)
|
||||
p.play_sound {path = 'utility/new_objective', volume_modifier = 1}
|
||||
success = true
|
||||
if _DEBUG then
|
||||
|
@ -16,7 +16,7 @@ Global.register(
|
||||
|
||||
local function player_died(event)
|
||||
local player_index = event.player_index
|
||||
local player = Game.get_player_by_index(player_index)
|
||||
local player = game.get_player(player_index)
|
||||
|
||||
if not player or not player.valid then
|
||||
return
|
||||
@ -113,8 +113,8 @@ local function mined_entity(event)
|
||||
return
|
||||
end
|
||||
|
||||
local player = Game.get_player_by_index(player_index)
|
||||
local corpse_owner = Game.get_player_by_index(corpse_owner_index)
|
||||
local player = game.get_player(player_index)
|
||||
local corpse_owner = game.get_player(corpse_owner_index)
|
||||
|
||||
if player and corpse_owner then
|
||||
local message = table.concat {player.name, ' has looted ', corpse_owner.name, "'s corpse"}
|
||||
@ -135,8 +135,8 @@ local function on_gui_opened(event)
|
||||
return
|
||||
end
|
||||
|
||||
local player = Game.get_player_by_index(player_index)
|
||||
local corpse_owner = Game.get_player_by_index(corpse_owner_index)
|
||||
local player = game.get_player(player_index)
|
||||
local corpse_owner = game.get_player(corpse_owner_index)
|
||||
|
||||
if player and corpse_owner then
|
||||
local message = table.concat {player.name, ' is looting ', corpse_owner.name, "'s corpse"}
|
||||
|
@ -42,7 +42,7 @@ local print_after_timeout =
|
||||
|
||||
--- When a player joins, set a 1s timer to retrieve their color before printing their welcome message
|
||||
local function player_joined(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
@ -69,7 +69,7 @@ end
|
||||
|
||||
--- Prints a message on donator death
|
||||
local function player_died(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
@ -268,7 +268,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.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
@ -169,8 +169,8 @@ local function on_tick()
|
||||
return
|
||||
end
|
||||
for table_key, camera_table in pairs(camera_users) do
|
||||
local player = Game.get_player_by_index(table_key)
|
||||
local target = Game.get_player_by_index(camera_table)
|
||||
local player = game.get_player(table_key)
|
||||
local target = game.get_player(camera_table)
|
||||
if not target.connected then
|
||||
destroy_camera({player = player})
|
||||
player.print('Target is offline, camera closed')
|
||||
|
@ -81,7 +81,7 @@ local function update_gui(player)
|
||||
end
|
||||
|
||||
local function player_joined(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
@ -665,7 +665,7 @@ local function toggle(event)
|
||||
end
|
||||
|
||||
local function player_created(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
@ -66,7 +66,7 @@ local function player_build_tile(event)
|
||||
return
|
||||
end
|
||||
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
if not player.gui.left[main_frame_name] then
|
||||
return
|
||||
end
|
||||
@ -90,7 +90,7 @@ local function player_build_tile(event)
|
||||
end
|
||||
|
||||
local function player_joined(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
@ -623,7 +623,7 @@ local function tick()
|
||||
end
|
||||
|
||||
local function player_joined(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
@ -180,7 +180,7 @@ local function redraw_poll_viewer_content(data)
|
||||
end
|
||||
|
||||
for player_index, answer in pairs(voters) do
|
||||
local p = Game.get_player_by_index(player_index)
|
||||
local p = game.get_player(player_index)
|
||||
insert(tooltips[answer], p.name)
|
||||
end
|
||||
|
||||
@ -207,7 +207,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.get_player_by_index(pi)
|
||||
local p = game.get_player(pi)
|
||||
if p and p.valid then
|
||||
insert(edit_names, p.name)
|
||||
insert(edit_names, ', ')
|
||||
@ -720,7 +720,7 @@ local function update_vote(voters, answer, direction)
|
||||
local tooltip = {}
|
||||
for pi, a in pairs(voters) do
|
||||
if a == answer then
|
||||
local player = Game.get_player_by_index(pi)
|
||||
local player = game.get_player(pi)
|
||||
insert(tooltip, player.name)
|
||||
end
|
||||
end
|
||||
@ -792,7 +792,7 @@ local function vote(event)
|
||||
end
|
||||
|
||||
local function player_joined(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
@ -22,7 +22,7 @@ local descriptions = {
|
||||
}
|
||||
|
||||
local function create_score_gui(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
if not player then
|
||||
return
|
||||
end
|
||||
|
@ -90,7 +90,7 @@ local function get_size(players, show_offline)
|
||||
size = table.size(players)
|
||||
else
|
||||
for pi, _ in pairs(players) do
|
||||
local player = Game.get_player_by_index(pi)
|
||||
local player = game.get_player(pi)
|
||||
if player and player.valid and player.connected then
|
||||
size = size + 1
|
||||
end
|
||||
@ -122,7 +122,7 @@ local delete_tag_name = Gui.uid_name()
|
||||
local close_create_tag_name = Gui.uid_name()
|
||||
|
||||
local function player_joined(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
@ -183,11 +183,11 @@ local function draw_main_frame_content(parent)
|
||||
|
||||
if players then
|
||||
for k, _ in pairs(players) do
|
||||
local p = Game.get_player_by_index(k)
|
||||
local p = game.get_player(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.get_player_by_index(k).name}
|
||||
local label = list.add {type = 'label', caption = game.get_player(k).name}
|
||||
label.style.top_padding = 8
|
||||
label.style.font_color = color
|
||||
end
|
||||
|
@ -116,7 +116,7 @@ local function get_editing_players_message(players)
|
||||
local message = {'Editing players: '}
|
||||
|
||||
for pi, _ in pairs(players) do
|
||||
local name = Game.get_player_by_index(pi).name
|
||||
local name = game.get_player(pi).name
|
||||
table.insert(message, name)
|
||||
table.insert(message, ', ')
|
||||
end
|
||||
@ -586,7 +586,7 @@ local function draw_create_task_frame(left, previous_task)
|
||||
end
|
||||
|
||||
local function player_joined(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
@ -632,7 +632,7 @@ local function player_joined(event)
|
||||
end
|
||||
|
||||
local function player_left(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
local left = player.gui.left
|
||||
|
||||
local frame = left[edit_announcements_frame_name]
|
||||
|
@ -203,7 +203,7 @@ local function gui_opened(event)
|
||||
return
|
||||
end
|
||||
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
@ -239,7 +239,7 @@ Event.add(defines.events.on_gui_opened, gui_opened)
|
||||
Event.add(
|
||||
defines.events.on_player_died,
|
||||
function(event)
|
||||
local player = Game.get_player_by_index(event.player_index or 0)
|
||||
local player = game.get_player(event.player_index or 0)
|
||||
|
||||
if not player or not player.valid then
|
||||
return
|
||||
|
@ -95,7 +95,7 @@ Event.add(defines.events.on_built_entity, function(event)
|
||||
entity.destroy()
|
||||
|
||||
-- attempt to give the item back to the player
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
@ -117,7 +117,7 @@ end
|
||||
|
||||
local function fish_earned(event, amount)
|
||||
local player_index = event.player_index
|
||||
local player = Game.get_player_by_index(player_index)
|
||||
local player = game.get_player(player_index)
|
||||
|
||||
local stack = {name = currency, count = amount}
|
||||
local inserted = player.insert(stack)
|
||||
@ -270,7 +270,7 @@ nth_tick_token =
|
||||
local tick = game.tick
|
||||
for k, v in pairs(speed_records) do
|
||||
if tick - v.start_tick > 3000 then
|
||||
local player = Game.get_player_by_index(k)
|
||||
local player = game.get_player(k)
|
||||
if player and player.valid and player.connected and player.character then
|
||||
reset_player_running_speed(player)
|
||||
end
|
||||
@ -279,7 +279,7 @@ nth_tick_token =
|
||||
|
||||
for k, v in pairs(mining_records) do
|
||||
if tick - v.start_tick > 6000 then
|
||||
local player = Game.get_player_by_index(k)
|
||||
local player = game.get_player(k)
|
||||
if player and player.valid and player.connected and player.character then
|
||||
reset_player_mining_speed(player)
|
||||
end
|
||||
@ -299,7 +299,7 @@ local function fish_player_crafted_item(event)
|
||||
end
|
||||
|
||||
local function player_created(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
|
||||
if not player or not player.valid then
|
||||
return
|
||||
|
@ -56,7 +56,7 @@ local function is_trusted(player)
|
||||
end
|
||||
|
||||
local function ammo_changed(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
if is_trusted(player) then
|
||||
return
|
||||
end
|
||||
@ -77,7 +77,7 @@ local function ammo_changed(event)
|
||||
end
|
||||
|
||||
local function on_player_deconstructed_area(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
if is_trusted(player) then
|
||||
return
|
||||
end
|
||||
@ -108,8 +108,8 @@ local function on_player_deconstructed_area(event)
|
||||
Utils.print_admins('Warning! ' .. player.name .. ' just tried to deconstruct ' .. tostring(#entities) .. ' entities!', nil)
|
||||
end
|
||||
for _, entity in pairs(entities) do
|
||||
if entity.valid and entity.to_be_deconstructed(Game.get_player_by_index(event.player_index).force) then
|
||||
entity.cancel_deconstruction(Game.get_player_by_index(event.player_index).force)
|
||||
if entity.valid and entity.to_be_deconstructed(game.get_player(event.player_index).force) then
|
||||
entity.cancel_deconstruction(game.get_player(event.player_index).force)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -125,7 +125,7 @@ end
|
||||
|
||||
local function on_capsule_used(event)
|
||||
local item = event.item
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
|
||||
if not player or not player.valid then
|
||||
return
|
||||
|
@ -73,7 +73,7 @@ Command.add(
|
||||
Event.add(
|
||||
defines.events.on_player_joined_game,
|
||||
function(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
@ -8,7 +8,7 @@ local get_random_weighted = table.get_random_weighted
|
||||
|
||||
local function player_created(event)
|
||||
local config = global.config.player_create
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
|
||||
if not player or not player.valid then
|
||||
return
|
||||
@ -76,7 +76,7 @@ if _CHEATS then
|
||||
|
||||
local function player_created_cheat_mode(event)
|
||||
local config = global.config.player_create
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
|
||||
if not player or not player.valid then
|
||||
return
|
||||
|
@ -39,7 +39,7 @@ local toast_token =
|
||||
return
|
||||
end
|
||||
|
||||
local player = Game.get_player_by_index(player_index)
|
||||
local player = game.get_player(player_index)
|
||||
if not player or not player.valid or not player.connected then
|
||||
return
|
||||
end
|
||||
@ -50,7 +50,7 @@ local toast_token =
|
||||
|
||||
local function on_player_created(event)
|
||||
local player_index = event.player_index
|
||||
local player = Game.get_player_by_index(player_index)
|
||||
local player = game.get_player(player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
@ -90,7 +90,7 @@ local function on_player_chat(event)
|
||||
return
|
||||
end
|
||||
|
||||
local player = Game.get_player_by_index(player_index)
|
||||
local player = game.get_player(player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
@ -69,7 +69,7 @@ Global.register(
|
||||
local function player_created(event)
|
||||
local index = event.player_index
|
||||
|
||||
player_last_position[index] = Game.get_player_by_index(index).position
|
||||
player_last_position[index] = game.get_player(index).position
|
||||
player_walk_distances[index] = 0
|
||||
player_coin_earned[index] = 0
|
||||
player_coin_spent[index] = 0
|
||||
|
@ -122,7 +122,7 @@ local sync_ranks_callback =
|
||||
|
||||
local function on_player_joined(event)
|
||||
local index = event.player_index
|
||||
local player = Game.get_player_by_index(index)
|
||||
local player = game.get_player(index)
|
||||
if not player then
|
||||
return
|
||||
end
|
||||
|
@ -101,7 +101,7 @@ local change_backer_name =
|
||||
local set_alt_on_create =
|
||||
Token.register(
|
||||
function(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
if not player then
|
||||
return
|
||||
end
|
||||
@ -142,7 +142,7 @@ local loader_check_token =
|
||||
--- Sets construction robots that are not part of a roboport to unminabe
|
||||
-- if the player selecting them are not the owner of them.
|
||||
local function preserve_bot(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
local entity = player.selected
|
||||
|
||||
if entity == nil or not entity.valid then
|
||||
|
@ -55,10 +55,10 @@ local function draw_report(parent, report_id)
|
||||
return
|
||||
end
|
||||
|
||||
local reported_player_name = Game.get_player_by_index(report.reported_player_index).name
|
||||
local reported_player_name = game.get_player(report.reported_player_index).name
|
||||
local reporting_player_name = '<script>'
|
||||
if report.reporting_player_index then
|
||||
reporting_player_name = Game.get_player_by_index(report.reporting_player_index).name
|
||||
reporting_player_name = game.get_player(report.reporting_player_index).name
|
||||
end
|
||||
local time = Utils.format_time(report.tick)
|
||||
local time_ago = Utils.format_time(game.tick - report.tick)
|
||||
@ -67,7 +67,7 @@ local function draw_report(parent, report_id)
|
||||
Gui.clear(parent)
|
||||
|
||||
local permission_group = game.permissions.get_group(jail_name)
|
||||
local jail_offender_button_caption = (Game.get_player_by_index(report.reported_player_index).permission_group == permission_group) and 'Unjail ' .. reported_player_name or 'Jail ' .. reported_player_name
|
||||
local jail_offender_button_caption = (game.get_player(report.reported_player_index).permission_group == permission_group) and 'Unjail ' .. reported_player_name or 'Jail ' .. reported_player_name
|
||||
|
||||
parent.add {type = 'label', caption = 'Offender: ' .. reported_player_name}
|
||||
local msg_label_pane = parent.add {type = 'scroll-pane', vertical_scroll_policy = 'auto-and-reserve-space', horizontal_scroll_policy = 'never'}
|
||||
@ -115,7 +115,7 @@ Module.show_reports =
|
||||
button_cell.add {
|
||||
type = 'button',
|
||||
name = report_tab_button_name,
|
||||
caption = Game.get_player_by_index(report.reported_player_index).name
|
||||
caption = game.get_player(report.reported_player_index).name
|
||||
}
|
||||
end
|
||||
end
|
||||
@ -418,9 +418,9 @@ Gui.on_click(
|
||||
local print = event.player.print
|
||||
|
||||
Gui.destroy(frame)
|
||||
Module.report(event.player, Game.get_player_by_index(reported_player_index), msg)
|
||||
Module.report(event.player, game.get_player(reported_player_index), msg)
|
||||
print(prefix)
|
||||
print('You have successfully reported: ' .. Game.get_player_by_index(reported_player_index).name)
|
||||
print('You have successfully reported: ' .. game.get_player(reported_player_index).name)
|
||||
print(prefix_e)
|
||||
end
|
||||
)
|
||||
|
@ -233,7 +233,7 @@ local function redraw_market_items(data)
|
||||
local count = data.count
|
||||
local market_items = data.market_items
|
||||
local player_index = data.player_index
|
||||
local player_coins = Game.get_player_by_index(player_index).get_item_count('coin')
|
||||
local player_coins = game.get_player(player_index).get_item_count('coin')
|
||||
|
||||
if size(market_items) == 0 then
|
||||
grid.add({type = 'label', caption = 'No items available at this time'})
|
||||
@ -434,7 +434,7 @@ Event.add(defines.events.on_gui_opened, function (event)
|
||||
return
|
||||
end
|
||||
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
@ -471,7 +471,7 @@ Gui.on_click(market_frame_close_button_name, function (event)
|
||||
end)
|
||||
|
||||
Event.add(defines.events.on_player_died, function (event)
|
||||
local player = Game.get_player_by_index(event.player_index or 0)
|
||||
local player = game.get_player(event.player_index or 0)
|
||||
|
||||
if not player or not player.valid then
|
||||
return
|
||||
@ -675,7 +675,7 @@ do_update_market_gui = Token.register(function(params)
|
||||
|
||||
for player_index, view_data in pairs(memory.players_in_market_view) do
|
||||
if group_name == view_data.group_name then
|
||||
local player = Game.get_player_by_index(player_index)
|
||||
local player = game.get_player(player_index)
|
||||
if player and player.valid then
|
||||
local frame = player.gui.center[market_frame_name]
|
||||
if not frame or not frame.valid then
|
||||
@ -697,7 +697,7 @@ end)
|
||||
|
||||
Event.on_nth_tick(37, function()
|
||||
for player_index, view_data in pairs(memory.players_in_market_view) do
|
||||
local player = Game.get_player_by_index(player_index)
|
||||
local player = game.get_player(player_index)
|
||||
if player and player.valid then
|
||||
local player_position = player.position
|
||||
local market_position = view_data.position
|
||||
|
@ -52,7 +52,7 @@ local function on_pre_death(event)
|
||||
end
|
||||
|
||||
local player_index = event.player_index
|
||||
local player = Game.get_player_by_index(player_index)
|
||||
local player = game.get_player(player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
@ -35,7 +35,7 @@ local death_messages = {
|
||||
}
|
||||
|
||||
local function player_died(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
@ -230,7 +230,7 @@ Event.add(
|
||||
local area = entity.bounding_box
|
||||
local left_top = area.left_top
|
||||
local right_bottom = area.right_bottom
|
||||
local p = Game.get_player_by_index(event.player_index)
|
||||
local p = game.get_player(event.player_index)
|
||||
--check for sand under all tiles in bounding box
|
||||
for x = math.floor(left_top.x), math.floor(right_bottom.x), 1 do
|
||||
for y = math.floor(left_top.y), math.floor(right_bottom.y), 1 do
|
||||
@ -258,7 +258,7 @@ Event.add(
|
||||
Event.add(
|
||||
defines.events.on_player_built_tile,
|
||||
function(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
@ -251,7 +251,7 @@ Event.add(
|
||||
Event.add(
|
||||
defines.events.on_player_died,
|
||||
function(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
set_timeout_in_ticks(1, spawn_player, player)
|
||||
end
|
||||
)
|
||||
|
@ -45,7 +45,7 @@ Event.add(CaveCollapse.events.on_collapse, function(event)
|
||||
local count = player_collapses[player_index] or 0
|
||||
count = count + 1
|
||||
player_collapses[player_index] = count
|
||||
local player = Game.get_player_by_index(player_index)
|
||||
local player = game.get_player(player_index)
|
||||
if global_primitives.autojail and count > allowed_collapses_first_hour and player.online_time < 216000 and not jailed_players[player_index] then
|
||||
Report.jail(player)
|
||||
Report.report(nil, player, format('Caused %d collapses in the first hour', count))
|
||||
|
@ -69,7 +69,7 @@ local function toggle(event)
|
||||
end
|
||||
|
||||
local function on_player_created(event)
|
||||
Game.get_player_by_index(event.player_index).gui.top.add({
|
||||
game.get_player(event.player_index).gui.top.add({
|
||||
name = 'Diggy.CoinGathering.Button',
|
||||
type = 'sprite-button',
|
||||
sprite = 'item/coin',
|
||||
|
@ -397,7 +397,7 @@ function DiggyCaveCollapse.register(cfg)
|
||||
end
|
||||
|
||||
if name == 'deconstructible-tile-proxy' or nil ~= support_beam_entities[name] then
|
||||
entity.cancel_deconstruction(Game.get_player_by_index(event.player_index).force)
|
||||
entity.cancel_deconstruction(game.get_player(event.player_index).force)
|
||||
end
|
||||
end
|
||||
)
|
||||
@ -419,7 +419,7 @@ function DiggyCaveCollapse.register(cfg)
|
||||
|
||||
if (nil ~= support_beam_entities[event.entity.name]) then
|
||||
require 'features.gui.popup'.player(
|
||||
Game.get_player_by_index(player_index),
|
||||
game.get_player(player_index),
|
||||
[[
|
||||
Mining entities such as walls, stone paths, concrete
|
||||
and rocks, can cause a cave-in, be careful miner!
|
||||
|
@ -21,7 +21,7 @@ local add_experience_percentage = ForceControl.add_experience_percentage
|
||||
local remove_experience_percentage = ForceControl.remove_experience_percentage
|
||||
local print_player_floating_text_position = Game.print_player_floating_text_position
|
||||
local get_force_data = ForceControl.get_force_data
|
||||
local get_player_by_index = Game.get_player_by_index
|
||||
local get_player_by_index = game.get_player
|
||||
local set_item = Retailer.set_item
|
||||
local disable_item = Retailer.disable_item
|
||||
local enable_item = Retailer.enable_item
|
||||
|
@ -17,7 +17,7 @@ local NightTime = {}
|
||||
-- @param event table containing the on_built_entity event specific attributes
|
||||
--
|
||||
local function on_built_entity(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
local entity = event.created_entity
|
||||
if (entity.name == 'solar-panel') then
|
||||
require 'features.gui.popup'.player(
|
||||
|
@ -190,7 +190,7 @@ local function move_qchunk(surface, x, y, x_offset, y_offset)
|
||||
surface.set_tiles(new_tiles)
|
||||
erase_qchunk(surface, x, y)
|
||||
for player_index, position in pairs(player_positions) do
|
||||
Game.get_player_by_index(player_index).teleport(position)
|
||||
game.get_player(player_index).teleport(position)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -189,14 +189,14 @@ local function toggle(player)
|
||||
end
|
||||
|
||||
local function player_joined(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
|
||||
if player.gui.top[main_button_name] ~= nil then
|
||||
return
|
||||
end
|
||||
|
||||
player.gui.top.add {name = main_button_name, type = 'sprite-button', sprite = 'utility/force_editor_icon'}
|
||||
toggle(Game.get_player_by_index(event.player_index))
|
||||
toggle(game.get_player(event.player_index))
|
||||
end
|
||||
|
||||
Gui.on_click(
|
||||
|
@ -27,7 +27,7 @@ local function transfer_body(player)
|
||||
end
|
||||
|
||||
local function player_created(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
local permissions = game.permissions
|
||||
|
||||
-- We want to create a permission group to stop players leaving their vehicles.
|
||||
@ -58,7 +58,7 @@ end
|
||||
|
||||
local function revive_player(event)
|
||||
-- When a player's car dies, return them to spawn and create a new car for them.
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
-- This check prevents a loop when we put them into a car.
|
||||
if not player.driving then
|
||||
transfer_body(player)
|
||||
|
@ -157,7 +157,7 @@ local on_built_token =
|
||||
|
||||
-- Check if we issue a refund: make sure refund is enabled, make sure we're not refunding a ghost,
|
||||
-- and revalidate the stack since we sent it to the raised event
|
||||
local player = Game.get_player_by_index(index)
|
||||
local player = game.get_player(index)
|
||||
local item_returned
|
||||
if player and player.valid and primitives.refund and not ghost and stack.valid then
|
||||
player.insert(stack)
|
||||
|
@ -10,7 +10,7 @@ local function admonish_blasphemy(event)
|
||||
return
|
||||
end
|
||||
local message = event.message:lower()
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
@ -207,7 +207,7 @@ end
|
||||
|
||||
--- Teleport the player to the redmew surface and if there is no suitable location, create an island
|
||||
local function player_created(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
local surface = global_data.surface
|
||||
|
||||
local spawn_position = global_data.spawn_position or {x = 0, y = 0}
|
||||
|
@ -35,7 +35,7 @@ Event.add(
|
||||
local surface = game.surfaces[event.surface_index]
|
||||
surface.set_tiles(new_tiles)
|
||||
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
player.insert {name = item_name, count = count}
|
||||
end
|
||||
)
|
||||
|
@ -60,7 +60,7 @@ local function player_joined_game(event)
|
||||
|
||||
local spawn = global.spawns[spawn_name]
|
||||
global.player_spawns[index] = spawn_name
|
||||
Game.get_player_by_index(index).teleport(spawn)
|
||||
game.get_player(index).teleport(spawn)
|
||||
|
||||
local count = spawn.count
|
||||
spawn.count = count + 1
|
||||
@ -88,11 +88,11 @@ local function player_respawned(event)
|
||||
return
|
||||
end
|
||||
|
||||
Game.get_player_by_index(index).teleport(spawn)
|
||||
game.get_player(index).teleport(spawn)
|
||||
end
|
||||
|
||||
local function tp_spawn(player_name, spawn_name)
|
||||
local player = Game.get_player_by_index(player_name)
|
||||
local player = game.get_player(player_name)
|
||||
if not player then
|
||||
player_name = player_name or ''
|
||||
game.player.print('player ' .. player_name .. ' does not exist.')
|
||||
@ -118,7 +118,7 @@ local function change_spawn(player_name, spawn_name)
|
||||
return
|
||||
end
|
||||
|
||||
local player = Game.get_player_by_index(player_name)
|
||||
local player = game.get_player(player_name)
|
||||
|
||||
if not player then
|
||||
player_name = player_name or ''
|
||||
@ -159,7 +159,7 @@ local function print_players_for_spawn(target_spawn_name)
|
||||
local str = ''
|
||||
for index, spawn_name in pairs(global.player_spawns) do
|
||||
if target_spawn_name == spawn_name then
|
||||
local player = Game.get_player_by_index(index)
|
||||
local player = game.get_player(index)
|
||||
if player.connected then
|
||||
str = str .. player.name .. ', '
|
||||
end
|
||||
|
@ -273,7 +273,7 @@ local function on_command(event)
|
||||
|
||||
local alternative = deprecated_command_alternatives[event.command]
|
||||
if alternative then
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
if player then
|
||||
player.print({'command.warn_deprecated_command', event.command, alternative})
|
||||
end
|
||||
@ -281,7 +281,7 @@ local function on_command(event)
|
||||
|
||||
local notification = notify_on_commands[event.command]
|
||||
if notification and event.player_index then
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
if player then
|
||||
player.print(notification)
|
||||
end
|
||||
|
@ -92,11 +92,19 @@ end
|
||||
|
||||
function Module.find_entities_by_last_user(player, surface, filters)
|
||||
if type(player) == 'string' or not player then
|
||||
error("bad argument #1 to '" .. debug.getinfo(1, 'n').name .. "' (number or LuaPlayer expected, got " .. type(player) .. ')', 1)
|
||||
error(
|
||||
"bad argument #1 to '" ..
|
||||
debug.getinfo(1, 'n').name .. "' (number or LuaPlayer expected, got " .. type(player) .. ')',
|
||||
1
|
||||
)
|
||||
return
|
||||
end
|
||||
if type(surface) ~= 'table' and type(surface) ~= 'number' then
|
||||
error("bad argument #2 to '" .. debug.getinfo(1, 'n').name .. "' (number or LuaSurface expected, got " .. type(surface) .. ')', 1)
|
||||
error(
|
||||
"bad argument #2 to '" ..
|
||||
debug.getinfo(1, 'n').name .. "' (number or LuaSurface expected, got " .. type(surface) .. ')',
|
||||
1
|
||||
)
|
||||
return
|
||||
end
|
||||
local entities = {}
|
||||
@ -105,7 +113,7 @@ function Module.find_entities_by_last_user(player, surface, filters)
|
||||
surface = game.surfaces[surface]
|
||||
end
|
||||
if type(player) == 'number' then
|
||||
player = Game.get_player_by_index(player)
|
||||
player = game.get_player(player)
|
||||
end
|
||||
filter.force = player.force.name
|
||||
for _, e in pairs(surface.find_entities_filtered(filter)) do
|
||||
@ -235,15 +243,13 @@ function Module.validate_player(player_ident)
|
||||
if is_player then
|
||||
player = player_ident
|
||||
end
|
||||
elseif data_type == 'number' then
|
||||
player = Game.get_player_by_index(player_ident)
|
||||
elseif data_type == 'string' then
|
||||
player = game.players[player_ident]
|
||||
elseif data_type == 'number' or data_type == 'string' then
|
||||
player = game.get_player(player_ident)
|
||||
else
|
||||
return
|
||||
end
|
||||
|
||||
if not player.valid then
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
local Global = require 'utils.global'
|
||||
local Color = require 'resources.color_presets'
|
||||
local pairs = pairs
|
||||
|
||||
local Game = {}
|
||||
|
||||
@ -12,55 +11,19 @@ Global.register(
|
||||
end
|
||||
)
|
||||
|
||||
--[[
|
||||
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]
|
||||
|
||||
if not p then
|
||||
return nil
|
||||
end
|
||||
if p.index == index then
|
||||
return p
|
||||
end
|
||||
|
||||
p = bad_name_players[index]
|
||||
if p then
|
||||
if p.valid then
|
||||
return p
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in pairs(game.players) do
|
||||
if k == index then
|
||||
bad_name_players[index] = v
|
||||
return v
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- Returns a valid LuaPlayer if given a number, string, or LuaPlayer. Returns nil otherwise.
|
||||
-- obj <number|string|LuaPlayer>
|
||||
function Game.get_player_from_any(obj)
|
||||
local o_type = type(obj)
|
||||
local p
|
||||
if o_type == 'number' then
|
||||
p = Game.get_player_by_index(obj)
|
||||
elseif o_type == 'string' then
|
||||
p = game.players[obj]
|
||||
if o_type == 'number' or o_type == 'string' then
|
||||
p = game.get_player(obj)
|
||||
if p and p.valid then
|
||||
return p
|
||||
end
|
||||
elseif o_type == 'table' and obj.valid and obj.is_player() then
|
||||
return obj
|
||||
end
|
||||
|
||||
if p and p.valid then
|
||||
return p
|
||||
end
|
||||
end
|
||||
|
||||
--- Prints to player or console.
|
||||
@ -104,7 +67,7 @@ end
|
||||
@return the created entity
|
||||
]]
|
||||
function Game.print_player_floating_text_position(player_index, text, color, x_offset, y_offset)
|
||||
local player = Game.get_player_by_index(player_index)
|
||||
local player = game.get_player(player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
@ -88,7 +88,7 @@ local function handler_factory(event_id)
|
||||
return
|
||||
end
|
||||
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
@ -194,7 +194,7 @@ local toggle_button_name = Gui.uid_name()
|
||||
Event.add(
|
||||
defines.events.on_player_created,
|
||||
function(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local player = game.get_player(event.player_index)
|
||||
|
||||
if not player or not player.valid then
|
||||
return
|
||||
|
@ -59,7 +59,7 @@ Public.give_reward = function(player, amount, message)
|
||||
local player_index
|
||||
if type(player) == 'number' then
|
||||
player_index = player
|
||||
player = Game.get_player_by_index(player)
|
||||
player = game.get_player(player)
|
||||
else
|
||||
player_index = player.index
|
||||
end
|
||||
@ -90,7 +90,7 @@ Public.remove_reward = function(player, amount, message)
|
||||
local player_index
|
||||
if type(player) == 'number' then
|
||||
player_index = player
|
||||
player = Game.get_player_by_index(player)
|
||||
player = game.get_player(player)
|
||||
else
|
||||
player_index = player.index
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user