Limiting Player Weapons

So well i was First triying to limit the player weapons to 3 so later he can change any of those 3 weapons for one of his like

but I have never work on player inventory stuff and yes i alredy readed the lua wiki to see if i could find someting and all that i founded was pl:stripweapons and that only works to delete all the player equipied weapons

so well any hints or at least any sort of info is very appreciated

function GM:PlayerInitialSpawn( ply )
ply.numofweapons = 0

function GM:PlayerCanPickupWeapon(ply, weapon)
for k, v in pairs(ply:GetWeapons()) do
ply.numofweapons = ply.numofweapons + 1
if numofweapons > 3 then
ply:PrintMessage( HUD_PRINTCENTER, “YOU HAVE TOO MANY WEAPONS(more than 3)” )
return false
return true

I’m not sure if this will drop the weapon he just picked up, or the weapon he was holding before he picked it up, if it drops the weapon he just picked up, can someone tell me a hook that is called when a player picks up a weapons but its not in the inventory yet? Or maybe a workaround, I would like something similar to this too


Users browsing this thread: Andriko1 TheRealc-unit

sniff he really cares :_)




-snip- facepunch lagging today…

-snip- facepunch lagging today…

why did you rate me dumb :(, and what do you mean by Boxes

EDIT: I changed it to GM:PlayerCanPickupWeapon() is it good now?

More Boxes.

He means your code/post is dumb.

Why would you set index on the players table when it only needs a variable local to the function?

The dumb rating isn’t for saying something is wrong with your code, that’s what feedback is called…

BTW you have 666 posts, that and Justin Bieber avatar looks funny lol

Please, leave already, 90% of your posts are wrong or dumb.

[editline]4th March 2011[/editline]

Also Boxes =

tried to use andriko code and i couldent even equip a weapon

Already established his code is fail.

oh nvm then

Compared to yours it’s pretty good.

local SafeGuns = {“weapon_physcannon”,“weapon_physgun”,“gmod_tool”}

function GM:PlayerCanPickupWeapon(pl,wep)
local weaponCount = pl.WeaponCount or 0
if table.HasValue(SafeGuns,wep:GetClass()) then return true end
if weaponCount > 2 then return false end
pl.WeaponCount = weaponCount + 1
return true

Try this.

man your always very helpfull! that worked pretty well but since Then how would i go to change the player equipied weapons? unless i can take out a weapon of my choice so i can freely make him unequip a weapon to equip another

okay now i only need a small advice of how to let the player Unequip his weapons i alredy got the equip part sorted out has weapon drop tutorials

well im using now concommand.Add(“pointshop_unequipitem”, function(ply, cmd, args)
local item_id = args[1]
if not item_id then return end

if not ply:PS_HasItem(item_id) then return end

ply:PS_UnequipItem(item_id, true)



function Player:PS_UnequipItem(item_id)
if self:PS_HasItem(item_id) then
for id, name in pairs(self.PS_Items) do
if name == item_id then
MsgN("Removing “, id, " from table”)


	local item = POINTSHOP.FindItemByID(item_id)
	if not item then return end
	if item.Functions and item.Functions.OnTake then
		item.Functions.OnTake(self, item)

return false


sorry for lack of lua tags but the problem is that it still isnt working but i got no errors at all! or is there any oter way to unequip a specific weapon/item from the player?