I'm using _Undefined Pointshop V2 and I have a item to set donators as Traitor and Detective but I want to set a limit to allow it only to be bought once every 20 minutes to stop overuse this is the code i have.
[code]ITEM.Name = 'Traitor'
ITEM.Price = 2000
ITEM.Material = 'VGUI/ttt/sprite_traitor.vmt'
ITEM.OneUse = true
ITEM.AllowedUserGroups = { "donator", "customrank", "admin", "superadmin" }
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[/code]
Any help is appreciated
This is the item code - not the purchase code. You shouldn't do it in here, but you'd do something like:
[CODE]
timer.Create("YourTimerName", 1200, NumberOfRepitionsHere, function()
your code here
end)
[/CODE]
[lua]
ITEM.Name = 'Traitor'
ITEM.Price = 2000
ITEM.Material = 'VGUI/ttt/sprite_traitor.vmt'
ITEM.OneUse = true
ITEM.AllowedUserGroups = { "donator", "customrank", "admin", "superadmin" }
if SERVER then
local plymeta = FindMetaTable( "Player" )
if not plymeta then return end
plymeta.inTraitorCooldown = false
end
function ITEM:CanPlayerBuy(ply)
return ply.inTraitorCooldown
end
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.inTraitorCooldown = true
timer.Simple(1200, function() ply.inTraitorCooldown = false end)
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]
I think this should do the trick.
[QUOTE=Ludicium;40318782][lua]
-snip-[/QUOTE]
That worked perfectly, thanks!
[QUOTE=Ludicium;40318782][lua]
if SERVER then
ply.inTraitorCooldown = true
timer.Simple(1200, function() ply.inTraitorCooldown = false end)
ply:PS_TakeItem(self.ID)
end
[/lua]
[/QUOTE]
If the player has disconnected by the time it is ready to run (20 min), ply will be an error.
So you could do
timer.Simple(1200, function() if ply and ply:IsValid() then ply.inTraitorCooldown = false end end)
[QUOTE=Ice Tea;40321757]If the player has disconnected by the time it is ready to run (20 min), ply will be an error.
So you could do
timer.Simple(1200, function() if ply and ply:IsValid() then ply.inTraitorCooldown = false end end)[/QUOTE]
Yup almost forgot about that, thanks a bunch.
Sorry, you need to Log In to post a reply to this thread.