help with Permanent weapons on pointshop

We currently have a few permanent pointshop weapons on our ttt server which we made by simply toggling the “SingleUse” value to false.
However this lets people re-gift themselves with the weapon. Is there any way to restrict it to only giving players weapons at the beginning of the round?

I have the same thing for admins on my server. Here is the code:
[lua]
ITEM.Name = “Humility’s Apache Revolver”
ITEM.Price = 1
ITEM.Model = ‘models/weapons/w_pist_apache_hum.mdl’
ITEM.WeaponClass = ‘weapon_ttt_lesapache’
ITEM.SingleUse = false
local id = ‘STEAM_1:1:32229416’ --only if for one person

function ITEM:OnEquip(ply) –
if ply:SteamID() == ‘id’ then –
ply:Give(self.WeaponClass)
ply:SelectWeapon(self.WeaponClass)
end
end

function ITEM:CanPlayerBuy(ply)
return ply:Alive() and ply:SteamID() == “id” – ignore the ply:SteamID part if you want everyone to be able to buy it
end

function ITEM:OnHolster(ply)
ply:StripWeapon(self.WeaponClass)
end
[/lua]

Yeah, I’m not looking to restrict the groups that can buy it, pointshop already has all the variables I need for that, I am trying to make sure it only gives the item at the beginning of a ttt round and never in the middle.

[lua]function ITEM:OnEquip(ply) –
if ply:SteamID() == ‘id’ then –
ply:Give(self.WeaponClass)
ply:SelectWeapon(self.WeaponClass)
end
end

function ITEM:CanPlayerBuy(ply)
return ply:Alive() and ply:SteamID() == “id” – ignore the ply:SteamID part if you want everyone to be able to buy it
end[/lua]

How do you expect this code to work?
Hint: It won’t…

Why won’t it? Would this work:
[lua]
fuction ITEM:OnEquip(ply)
ply:Give(self.WeaponClass)
ply:SelectWeapon(self.WeaponClass)
end

fuction ITEM:CanPlayerBuy(ply)
return ply:Alive() and ply:SteamID() == “id”
end [/lua]

No it won’t. You defined the variable id, and you are comparing the steamid with the string “id”, not with the variable.

Ack! Don’t hijack the thread.
He means that because you used quotes it will only work if the persons id is literally “id” which it won’t be.
Back to topic:
Would there be any way to check to see if it was pre-round and only give it then?

woops miss read the beginning I thought you just wanted permanent weapons.

Sorry, lol

I believe TTT has a hook for it.

There it is:
TTTPrepareRound()

Note: this is all the TTT hooks listed:

So how do I do that?

like this?



function ITEM:OnEquip(ply) --
	if TTTPrepareRound() == true then
		ply:Give(self.WeaponClass)
		ply:SelectWeapon(self.WeaponClass)
end
end


hook.Add(“TTTPrepareRound”, “yourfunc”, yourfunc) work from that

So like this then?



ITEM.Name = "Perma shotty"
ITEM.Price = 314159
ITEM.Model = 'models/weapons/w_shotty.mdl'
ITEM.WeaponClass = 'weapon_ttt_shotty'
ITEM.SingleUse = false

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

function ITEM:OnHolster(ply)
	ply:StripWeapon(self.WeaponClass)
end
hook.Add("TTTPrepareRound", "OnEquip", OnEquip)


I believe pointshop allows you to use any default hook, so you could probably do


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

Or something along those lines

But how is that called on purchase?

[lua]
function EquipPointshopItem( ply )
ply:Give(self.WeaponClass)
ply:SelectWeapon(self.WeaponClass)
end

function ITEM:OnEquip (ply)
hook.Add( “TTTPrepareRound”, “GiveMeGun”, Equip PointshopItem )
end
[/lua]

You don’t need to do that, just add


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

underneath


function ITEM:OnHolster(ply)

That’s great, that works! only problem is it gives the weapon to the player every time anyone spawns in the server meaning he gets a lot of them on map connects… any way to fix that?

[editline]31st August 2013[/editline]

also it occasionally spawns in the hands of spectators

actually it consistently spawns in the hands of spectators, any idea for a fix please?

Check if the player is spectator and if they are, strip the weapons from them or just slay them.

Make a check to see
[LUA]if ply:Alive() and ply:Team() ~= TEAM_SPECTATOR then
–give
[/LUA]