Gmod Pointshop issues

I am having problems with my Garry’s mod pointshop. I have a TDM server and I want to add permanent weapons, but whenever you respawn, you lose the weapons and have to sell them and then buy them back. Here is the code for one of the weapons. Does anybody have any suggestions?


ITEM.Name = 'Crossbow'
ITEM.Price = 20000
ITEM.Model = 'models/weapons/w_crossbow.mdl'
ITEM.WeaponClass = 'weapon_crossbow'
ITEM.SingleUse = false

function ITEM:OnBuy(player)
	player:Give(self.WeaponClass)
	player:SelectWeapon(self.WeaponClass)
end

function ITEM:OnSell(player)
	player:StripWeapon(self.WeaponClass)
end

function GAMEMODE:PlayerSpawn(player)
	player:Give(self.WeaponClass)
end



Edit: I also tried


function ITEM:PlayerSpawn(ply)
	player:Give(self.WeaponClass)
end



Thanks, -Rob

Hmm I believe the pointshop equips the items on the playerspawn hook so it should give them the weapon on respawn if you have add an equip function there. So you should add in a part for ITEM:Equip to give the player the weapon.

That solved one of my problems, but now the items disappear from the pointshop and leave this error: “function arguments expected near ‘=’” even though I have ITEM:Equip = false

. not :

Oh wow, i’m dumb. Thanks a lot

and it’s function ITEM:OnEquip(ply, modifications) end

Could you give me an example? I’m not entirely sure how that would be used. Thanks, -rob

No code, no help.

Sorry, didn’t see your new post here’s my current code: ITEM.Name = ‘Crossbow’
ITEM.Price = 20000
ITEM.Model = ‘models/weapons/w_crossbow.mdl’
ITEM.WeaponClass = ‘weapon_crossbow’
ITEM.SingleUse = false
ITEM.Equip = false

function ITEM:OnBuy(player)
player:Give(self.WeaponClass)
player:SelectWeapon(self.WeaponClass)
end

function ITEM:OnSell(player)
player:StripWeapon(self.WeaponClass)
end

function ITEM:PlayerSpawn(ply)
player:Give(self.WeaponClass)
player:SelectWeapon(self.WeaponClass)
end

ITEM.Equip does nothing so I’m not sure why you added that.

You’re using Give on the variable player which doesn’t exist.

Hint: Look at your argument name. (ply)

could I do something like:


player:Give(ply.WeaponClass)

?? I was thinking about what you said and I couldn’t quite figure it out. Thanks for the help anyways, -Rob

I can see that you don’t understand the language.

[lua]
function ITEM:PlayerSpawn(ply)
player:Give(self.WeaponClass)
player:SelectWeapon(self.WeaponClass)
end
[/lua]

should be

[lua]
function ITEM:PlayerSpawn(ply)
ply:Give(self.WeaponClass)
ply:SelectWeapon(self.WeaponClass)
end
[/lua]

Yeah, I’m a noob. I’ve had a tab open for the last half-hour trying to figure out the difference between ply and player. I was convinced there wasn’t any. Thanks for your help, -Rob

[editline]12th June 2014[/editline]

I am spawning with the items, but I lose them when I join a team, so the problem is in the gamemode… I guess this is solved? BTW the gamemode is Very Basic TDM. I get the weapons when I join the server, but whenever I die, I lose them.