Skip to content

Commit

Permalink
Fixed error when trying to drop ammo for weapons without AmmoEnt (#1671)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
MrXonte and Histalek authored Nov 27, 2024
1 parent 33a0011 commit 2493ff1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion gamemodes/terrortown/gamemode/server/sv_player_ext.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 2493ff1

Please sign in to comment.