• help with Permanent weapons on pointshop
    19 replies, posted
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.
[QUOTE=Humility;41995704] [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][/QUOTE] [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...
[QUOTE=freakyy;41996295][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...[/QUOTE] 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.
[QUOTE=Galactic;41996527]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?[/QUOTE] Sorry, lol I believe TTT has a hook for it. There it is: TTTPrepareRound() Note: this is all the TTT hooks listed: [url]http://ttt.badking.net/guides/hooks[/url]
So how do I do that? like this? [code] function ITEM:OnEquip(ply) -- if TTTPrepareRound() == true then ply:Give(self.WeaponClass) ply:SelectWeapon(self.WeaponClass) end end [/code]
[QUOTE=Galactic;42014081]So how do I do that? like this? [code] function ITEM:OnEquip(ply) -- if TTTPrepareRound() == true then ply:Give(self.WeaponClass) ply:SelectWeapon(self.WeaponClass) end end [/code][/QUOTE] hook.Add("TTTPrepareRound", "yourfunc", yourfunc) work from that
So like this then? [code] 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) [/code]
I believe pointshop allows you to use any default hook, so you could probably do [CODE]function ITEM:PlayerSpawn( ply ) ply:Give(self.WeaponClass) end[/CODE] Or something along those lines
But how is that called on purchase?
[QUOTE=Galactic;42024767]But how is that called on purchase?[/QUOTE] [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 [CODE]function ITEM:PlayerSpawn( ply ) ply:Give(self.WeaponClass) end[/CODE] underneath [CODE]function ITEM:OnHolster(ply)[/CODE]
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?
[QUOTE=Galactic;42038500]actually it consistently spawns in the hands of spectators, any idea for a fix please?[/QUOTE] 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]
Sorry, you need to Log In to post a reply to this thread.