Hi people. Yesterday I was struggling with an SWEP that wasn’t working for no reason. Apparently, the game refused to create its custom ammo type. After some experimentation, I noticed that there’s a hardcoded limit of 128 ammo types. My first suggestion is to increase that limit a bit, as it can be easily reached with a few SWEP packs. However, I assume there’s a reason to keep that limit (or perhaps it is a limitation of the engine itself) so maybe increasing it is not option.
I also noticed that my game was full of duplicated ammo types. This is the original function, located in “lua/includes/extensions/game.lua”:
game.AddAmmoType = function ( tbl ) if ( !tbl.name ) then return end table.insert( AmmoTypes, tbl ) end
As you can see, it doesn’t check if the new ammo type already exists, making the list quickly fill up with duplicates. Since we use a string to set our weapon ammo type, it probably only uses the first occurrence, and the rest of duplicates will never be used. I suggest adding this to that function:
game.AddAmmoType = function ( tbl ) if ( !tbl.name ) then return end for i=1, #AmmoTypes do if AmmoTypes*.name == tbl.name then return end end table.insert( AmmoTypes, tbl ) end
This way it won’t create duplicated ammo types, and we can use more weapons at the same time. I did it in my GMOD instalation and it works perfectly. Perhaps it is a good idea to include that in the default game files.