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