No more warnings

This commit is contained in:
Cooldude2606
2024-09-28 03:46:14 +01:00
parent 32a8ba8f3a
commit 3145f7e904
43 changed files with 215 additions and 177 deletions

View File

@@ -60,7 +60,7 @@ end)
--- Remove the screen gui if it is present
Event.add(defines.events.on_player_joined_game, function(event)
local player = game.get_player(event.player_index)
local player = game.players[event.player_index]
local frame = player.gui.screen["afk-kick"]
if frame and frame.valid then frame.destroy() end
end)

View File

@@ -63,6 +63,7 @@ end
Event.add(defines.events.on_player_died, function(event)
local player = game.players[event.player_index]
local corpse = player.surface.find_entity("character-corpse", player.position)
if not corpse or not corpse.valid then return end
if config.use_chests_as_bodies then
local items = corpse.get_inventory(defines.inventory.character_corpse)
local chest = move_items(items, corpse.surface, corpse.position)

View File

@@ -44,7 +44,7 @@ if config.decon_area then
return
end
local player = game.get_player(e.player_index)
local player = game.players[e.player_index]
if Roles.player_has_flag(player, "deconlog-bypass") then
return
@@ -63,7 +63,7 @@ end
if config.built_entity then
Event.add(defines.events.on_built_entity, function(e)
if not e.player_index then return end
local player = game.get_player(e.player_index)
local player = game.players[e.player_index]
if Roles.player_has_flag(player, "deconlog-bypass") then
return
end
@@ -74,7 +74,7 @@ end
if config.mined_entity then
Event.add(defines.events.on_player_mined_entity, function(e)
local player = game.get_player(e.player_index)
local player = game.players[e.player_index]
if Roles.player_has_flag(player, "deconlog-bypass") then
return
end
@@ -85,11 +85,11 @@ end
if config.fired_rocket then
Event.add(defines.events.on_player_ammo_inventory_changed, function(e)
local player = game.get_player(e.player_index)
local player = game.players[e.player_index]
if Roles.player_has_flag(player, "deconlog-bypass") then
return
end
local ammo_inv = player.get_inventory(defines.inventory.character_ammo)
local ammo_inv = player.get_inventory(defines.inventory.character_ammo) --- @cast ammo_inv -nil
local item = ammo_inv[player.character.selected_gun_index]
if not item or not item.valid or not item.valid_for_read then
return
@@ -102,12 +102,12 @@ end
if config.fired_explosive_rocket then
Event.add(defines.events.on_player_ammo_inventory_changed, function(e)
local player = game.get_player(e.player_index)
local player = game.players[e.player_index]
if Roles.player_has_flag(player, "deconlog-bypass") then
return
end
local ammo_inv = player.get_inventory(defines.inventory.character_ammo)
local ammo_inv = player.get_inventory(defines.inventory.character_ammo) --- @cast ammo_inv -nil
local item = ammo_inv[player.character.selected_gun_index]
if not item or not item.valid or not item.valid_for_read then
@@ -121,13 +121,13 @@ end
if config.fired_nuke then
Event.add(defines.events.on_player_ammo_inventory_changed, function(e)
local player = game.get_player(e.player_index)
local player = game.players[e.player_index]
if Roles.player_has_flag(player, "deconlog-bypass") then
return
end
local ammo_inv = player.get_inventory(defines.inventory.character_ammo)
local ammo_inv = player.get_inventory(defines.inventory.character_ammo) --- @cast ammo_inv -nil
local item = ammo_inv[player.character.selected_gun_index]
if not item or not item.valid or not item.valid_for_read then

View File

@@ -14,7 +14,7 @@ Event.add(defines.events.on_player_mined_entity, function(event)
local item_entity = event.entity.surface.find_entity("item-on-ground", event.entity.drop_position)
if item_entity then
local player = game.get_player(event.player_index)
local player = game.players[event.player_index]
if controllers_with_inventory[player.controller_type] then
player.mine_entity(item_entity)

View File

@@ -7,7 +7,7 @@ local move_items_stack = _C.move_items_stack --- @dep expcore.common
local function clear_items(event)
local player = game.players[event.player_index]
local inv = player.get_main_inventory()
local inv = player.get_main_inventory() --- @cast inv -nil
move_items_stack(inv)
inv.clear()
end

View File

@@ -26,7 +26,7 @@ end
for _, inventory in ipairs(config.inventories) do
if #inventory.items > 0 then
Event.add(inventory.event, function(event)
local player = game.get_player(event.player_index)
local player = game.players[event.player_index]
if player and player.valid then
check_items(player, inventory.inventory)
end

View File

@@ -15,7 +15,7 @@ end)
--- When a protection is triggered increment their counter and jail if needed
Event.add(Protection.events.on_repeat_violation, function(event)
local player = game.get_player(event.player_index)
local player = game.players[event.player_index]
-- Increment the counter
if repeat_count[player.index] then

View File

@@ -16,7 +16,7 @@ local function reporter_playtime(_, by_player_name, _)
end
Event.add(Reports.events.on_player_reported, function(event)
local player = game.get_player(event.player_index)
local player = game.players[event.player_index]
local total_playtime = Reports.count_reports(player, reporter_playtime)
-- player less than 30 min

View File

@@ -62,12 +62,13 @@ local function spawn_turrets()
-- Makes a new turret if it is not found
if not turret or not turret.valid then
turret = surface.create_entity{ name = "gun-turret", position = pos, force = "spawn" }
if not turret then return end
protect_entity(turret)
end
-- Adds ammo to the turret
local inv = turret.get_inventory(defines.inventory.turret_ammo)
if inv.can_insert{ name = config.turrets.ammo_type, count = 10 } then
if inv and inv.can_insert{ name = config.turrets.ammo_type, count = 10 } then
inv.insert{ name = config.turrets.ammo_type, count = 10 }
end
end