From f8187005e97aad82024aa38789392454c8033b8b Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Wed, 8 Jan 2025 23:00:44 +0900 Subject: [PATCH] Decon Log Character Check (#347) * Update deconlog.lua * Update deconlog.lua * Update deconlog.lua * Update deconlog.lua * Update deconlog.lua * Move ammo_inv to maintain cast -nil --------- Co-authored-by: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com> --- exp_legacy/module/modules/addons/deconlog.lua | 66 +++++-------------- 1 file changed, 18 insertions(+), 48 deletions(-) diff --git a/exp_legacy/module/modules/addons/deconlog.lua b/exp_legacy/module/modules/addons/deconlog.lua index 08c40b8f..10442420 100644 --- a/exp_legacy/module/modules/addons/deconlog.lua +++ b/exp_legacy/module/modules/addons/deconlog.lua @@ -93,59 +93,29 @@ if config.mined_entity then end) end -if config.fired_rocket then +if config.fired_rocket or config.fired_explosive_rocket or config.fired_nuke then Event.add(defines.events.on_player_ammo_inventory_changed, function(e) 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) --- @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 - end - if item.name == "rocket" then - add_log(get_secs() .. "," .. player.name .. ",shot-rocket," .. pos_to_string(player.physical_position) .. "," .. pos_to_string(player.shooting_state.position)) - end - end) -end - -if config.fired_explosive_rocket then - Event.add(defines.events.on_player_ammo_inventory_changed, function(e) - 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) --- @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 - end - if item.name == "explosive-rocket" then - add_log(get_secs() .. "," .. player.name .. ",shot-explosive-rocket," .. pos_to_string(player.physical_position) .. "," .. pos_to_string(player.shooting_state.position)) - end - end) -end - -if config.fired_nuke then - Event.add(defines.events.on_player_ammo_inventory_changed, function(e) - 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) --- @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 - end - - if item.name == "atomic-bomb" then - add_log(get_secs() .. "," .. player.name .. ",shot-nuke," .. pos_to_string(player.physical_position) .. "," .. pos_to_string(player.shooting_state.position)) + if player.character then + local ammo_inv = player.get_inventory(defines.inventory.character_ammo) --- @cast ammo_inv -nil + local item = ammo_inv[player.character.selected_gun_index] + local action_name + if not item or not item.valid or not item.valid_for_read then + return + end + if config.fired_rocket and item.name == "rocket" then + action_name = ",shot-rocket," + elseif config.fired_explosive_rocket and item.name == "explosive-rocket" then + action_name = ",shot-explosive-rocket," + elseif config.fired_nuke and item.name == "atomic-bomb" then + action_name = ",shot-nuke," + else + return + end + add_log(get_secs() .. "," .. player.name .. action_name .. pos_to_string(player.physical_position) .. "," .. pos_to_string(player.shooting_state.position)) end end) end