Help with creating a Maximum ammo-pool

I can’t seem to figure out how to limit one’s maximum ammo that the player can carry.

I know Sk_ commands do not work in Gmod,
But is there an LUA script or something I can use that allows you to Cap off the ammo you are carrying?

I would really appreciate someone helping because I’ve looked all over other threads to find this out, but to no avail. :confused:

I have a script I used for my gamemode, here’s the code if you want to use it:
[lua]
– The ammo limit for each ammo type, you will have to find out the additional ones
– The ones working are listed on http://wiki.garrysmod.com/?title=Player.GiveAmmo

local AMMO_TYPES = {}

AMMO_TYPES[“Pistol”] = 168

AMMO_TYPES[“357”] = 18

AMMO_TYPES[“SMG1”] = 270

AMMO_TYPES[“SMG1_Grenade”] = 3

AMMO_TYPES[“AR2”] = 90

AMMO_TYPES[“AR2AltFire”] = 3

AMMO_TYPES[“Buckshot”] = 36

AMMO_TYPES[“XBowBolt”] = 11

AMMO_TYPES[“RPG_Round”] = 2

AMMO_TYPES[“Grenade”] = 4

– You do not need to edit anything below this line, but if you know what you’re doing, go right ahead.

local ITEM_CONV_TYPES = {}

ITEM_CONV_TYPES[“Pistol”] = “weapon_pistol”

ITEM_CONV_TYPES[“357”] = “weapon_357”

ITEM_CONV_TYPES[“SMG1”] = “weapon_smg1”

ITEM_CONV_TYPES[“AR2”] = “weapon_ar2”

ITEM_CONV_TYPES[“Buckshot”] = “weapon_shotgun”

ITEM_CONV_TYPES[“XBowBolt”] = “weapon_crossbow”

ITEM_CONV_TYPES[“Grenade”] = “weapon_frag”

ITEM_CONV_TYPES[“RPG_Round”] = “weapon_rpg”

hook.Add(“Think”, “LimitPlayerAmmo”, function()
for _,pl in pairs(player.GetAll()) do
for k,v in pairs(AMMO_TYPES) do
local ammo = pl:GetAmmoCount(k)
local plus = 0
if ITEM_CONV_TYPES[k] then
if pl:HasWeapon(ITEM_CONV_TYPES[k]) then
plus = pl:GetWeapon(ITEM_CONV_TYPES[k]):Clip1()
end
end
if (ammo+plus) > v then
pl:RemoveAmmo((ammo+plus)-v, k)
end
end
end
end)
[/lua]

Thanks a ton!

Does that really need to be in a think hook? It seems rather expensive, why not put it on a timer that runs every 0.5 seconds.