• Limit Buys On Pointshop Items
    3 replies, posted
As the title clearly states, I want to know/learn the code for this particular idea. I have seen a server do this before with a certain item in the pointshop called "Traitor" or "Traitor Round". I am a Lead Administrator and Developer of a Trouble in Terrorist Town server but I'm not familiar with the code for buying a certain item in the pointshop once, every map. It has come to my attention that Traitor buying has become abusive and has annoyed a lot of members in my community and even with the community as whole together trying to lower down the buying, it isn't successful. I tried looking at the other items to see if they have a limited buy but they don't. I'd just like a certain code and like to know if it's possible to make the a item in the Pointshop Addon can be limited to buy once every map. If you need any further information, please let me know in this thread. Regards, Oiramax.
Dear Oiramax, I would use this code: [lua]Item.SingleUse = true[/lua] to make the player only buy it for the round. And to become a traitor: [lua] ITEM.Name = 'Traitor' ITEM.Price = 3000 ITEM.Material = 'VGUI/ttt/sprite_traitor.vmt' ITEM.OneUse = true function ITEM:OnEquip(ply, modifications) hook.Add("TTTBeginRound", ply:UniqueID() .. "_traitor", function() if ply:GetRoleString() != "traitor" then ply:SetRole(ROLE_TRAITOR) ply:AddCredits(GetConVarNumber("ttt_credits_starting")) end if SERVER then ply:PS_TakeItem(self.ID) end hook.Remove("TTTBeginRound", ply:UniqueID() .. "_traitor") end) end function ITEM:OnHolster(ply) hook.Remove("TTTBeginRound", ply:UniqueID() .. "_traitor") end function ITEM:OnSell(ply) hook.Remove("TTTBeginRound", ply:UniqueID() .. "_traitor") end[/lua]
Plonker, that does nothing of what the OP asks. Not to mention you tell him to use SingleUse but in your code use OneUse. What I suggest OP Is setting a variable on the player when they purchase it since you have the item code already. [lua]function ITEM:OnBuy(ply) ply.HasMapUsed = true -- Says they have used it for the map. end function ITEM:CanPlayerBuy(ply) return !ply.HasMapUsed -- Returns the opposite of what we set the value as, so if true (they have already) then it'll return it false for them. end[/lua] What this will do is on purchase, they'll have already used it. Then they cannot buy it again until their value is reset, which it'll do so on map change (return it as nil, which on PlayerCanBuy will allow them to purchase it)
[QUOTE=Nookyava;44637742]Plonker, that does nothing of what the OP asks. Not to mention you tell him to use SingleUse but in your code use OneUse. What I suggest OP Is setting a variable on the player when they purchase it since you have the item code already. [lua]function ITEM:OnBuy(ply) ply.HasMapUsed = true -- Says they have used it for the map. end function ITEM:CanPlayerBuy(ply) return !ply.HasMapUsed -- Returns the opposite of what we set the value as, so if true (they have already) then it'll return it false for them. end[/lua] What this will do is on purchase, they'll have already used it. Then they cannot buy it again until their value is reset, which it'll do so on map change (return it as nil, which on PlayerCanBuy will allow them to purchase it)[/QUOTE] Thank you so much Nookyava. I tried holstering the Item when people bought it after they bought it once but there was an error and I knew there was a easier code for it. Thank you, once again.
Sorry, you need to Log In to post a reply to this thread.