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? [CODE]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
[/CODE]
Edit: I also tried [CODE]function ITEM:PlayerSpawn(ply)
player:Give(self.WeaponClass)
end
[/CODE]
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 = [U]false[/U]
[QUOTE=robeth;45086549]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 = [U]false[/U][/QUOTE]
. not :
Oh wow, i'm dumb. Thanks a lot
[QUOTE=brandonj4;45086636]. not :[/QUOTE]
and it's [URL="http://pointshop.burt0n.net/items"]function ITEM:OnEquip(ply, modifications) end[/URL]
Could you give me an example? I'm not entirely sure how that would be used. Thanks, -rob
[QUOTE=robeth;45086687]Now it says: "attempt to call method 'Give' <a nil value>" Hmmmm[/QUOTE]
No code, no help.
[QUOTE=brandonj4;45086704]No code, no help.[/QUOTE] 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
[QUOTE=robeth;45086724]Sorry, didn't see your new post here's my current code: ITEM.Name = 'Iceaxe'
ITEM.Price = 750
ITEM.Model = 'models/weapons/w_iceaxe.mdl'
ITEM.WeaponClass = 'weapon_iceaxe'
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[/QUOTE]
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: [CODE]player:Give(ply.WeaponClass)[/CODE] ?? I was thinking about what you said and I couldn't quite figure it out. Thanks for the help anyways, -Rob
[QUOTE=robeth;45087014]could I do something like: [CODE]player:Give(ply.WeaponClass)[/CODE] ?? I was thinking about what you said and I couldn't quite figure it out. Thanks for the help anyways, -Rob[/QUOTE]
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]
[QUOTE=brandonj4;45087036]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][/QUOTE]
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]
[QUOTE=brandonj4;45087036]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][/QUOTE]
I am spawning with the items, but I lose them when I join a team, so the problem is in the gamemode... I [I]guess[/I] 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.
Sorry, you need to Log In to post a reply to this thread.