From 2493ff1392906e6085faf21fbae6da34476e96e5 Mon Sep 17 00:00:00 2001 From: Konstantin Gitschthaler <31093949+MrXonte@users.noreply.github.com> Date: Wed, 27 Nov 2024 16:29:18 +0100 Subject: [PATCH] Fixed error when trying to drop ammo for weapons without AmmoEnt (#1671) When trying to drop ammo on a weapon with no AmmoEnt (aka AmmoEnt = ""), an error appears in the console from trying to create a non-existent entity. --------- Co-authored-by: Histalek <16392835+Histalek@users.noreply.github.com> --- CHANGELOG.md | 1 + gamemodes/terrortown/gamemode/server/sv_player_ext.lua | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d451d7dff..42814b8d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel - Fixed weapon pickup through walls (by @MrXonte) - Fixed spectating player still being visible through thermalvision after killing that player (by @MrXonte) - Fixed Magneto-stick not using C_Hands (by @SvveetMavis) +- Fixed console error when dropping ammo for weapons with no AmmoEnt (by @MrXonte) ### Changed diff --git a/gamemodes/terrortown/gamemode/server/sv_player_ext.lua b/gamemodes/terrortown/gamemode/server/sv_player_ext.lua index 6d9fe488b..81de60e53 100644 --- a/gamemodes/terrortown/gamemode/server/sv_player_ext.lua +++ b/gamemodes/terrortown/gamemode/server/sv_player_ext.lua @@ -1407,7 +1407,10 @@ end -- @return boolean Returns if this weapon's ammo can be dropped -- @realm server function plymeta:CanSafeDropAmmo(wep) - if not IsValid(self) or not (IsValid(wep) and wep.AmmoEnt) then + -- We explicitly check for the two common non-existent ammo ents (`nil` and `empty string`) here + -- to prevent these from leading to a console error later once they are fed into `ents.Create`. + -- There is currently no way to check if the AmmoEnt exists, so this is the best we can do. + if not IsValid(self) or not IsValid(wep) or not wep.AmmoEnt or wep.AmmoEnt == "" then return false end