From ecf2c59bb19fd49b6df99c30b8ea2665797858ea Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Thu, 6 May 2021 01:10:54 +0100 Subject: [PATCH] Fixed other errors --- modules/addons/afk-kick.lua | 2 +- modules/commands/search.lua | 2 +- modules/control/protection.lua | 2 +- modules/control/spectate.lua | 2 ++ 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/addons/afk-kick.lua b/modules/addons/afk-kick.lua index 9bea3b05..1c2de281 100644 --- a/modules/addons/afk-kick.lua +++ b/modules/addons/afk-kick.lua @@ -30,7 +30,7 @@ Event.on_nth_tick(config.update_time, function() -- Check for active players for _, player in ipairs(game.connected_players) do if player.afk_time < config.afk_time - or config.admin_as_active and config.player.admin + or config.admin_as_active and player.admin or config.trust_as_active and player.online_time > config.trust_time or config.active_role and Roles.player_has_role(player, config.active_role) then -- Active player was found diff --git a/modules/commands/search.lua b/modules/commands/search.lua index 62d1ab33..4eb70b57 100644 --- a/modules/commands/search.lua +++ b/modules/commands/search.lua @@ -55,7 +55,7 @@ local function sort_players(players, func) for index, player in ipairs(players) do local value = func(player) -- Check if the item will make the top 5 elements - if value > threshold or index <= 5 then + if index <= 5 or value > threshold then local inserted = false values[player] = value -- Find where in the top 5 to insert the element diff --git a/modules/control/protection.lua b/modules/control/protection.lua index 61b5f5c6..81056d7d 100644 --- a/modules/control/protection.lua +++ b/modules/control/protection.lua @@ -157,7 +157,7 @@ Event.add(defines.events.on_pre_player_mined_item, function(event) local player = game.get_player(event.player_index) -- Check if the player should be ignored if config.ignore_admins and player.admin then return end - if entity.last_user.index == player.index then return end + if entity.last_user == nil or entity.last_user.index == player.index then return end if config.ignore_permission and Roles.player_allowed(player, config.ignore_permission) then return end -- Check if the entity is protected diff --git a/modules/control/spectate.lua b/modules/control/spectate.lua index 6f9944f8..715bf1ed 100644 --- a/modules/control/spectate.lua +++ b/modules/control/spectate.lua @@ -35,9 +35,11 @@ function Public.start_spectate(player) assert(player and player.valid, 'Invalid player given to follower') if spectating[player.index] or not player.character then return false end local character = player.character + local opened = player.opened player.set_controller{ type = defines.controllers.spectator } player.associate_character(character) spectating[player.index] = character + if opened then player.opened = opened end -- Maintain opened after controller change return true end