marty000123 Posted December 10, 2016 Posted December 10, 2016 (edited) Hello, this is a piece of my code aTimer = { } function hydraulics(player) if getElementType(player)=="player" then local vehicle=getPedOccupiedVehicle(player) setElementPosition(player, 199.2939453125, 1428.4794921875, 10.5859375) aTimer[source] = setTimer ( function( source ) aTimer [source] = nil end,300000,1,source ) if isTimer ( aTimer[source] ) then return false or outputChatBox( "#ff0000You can only TP to the Gun Shop once every 5 minutes!", source, r, g, b, true) end end end addEvent("hydraulics",true) addEventHandler("hydraulics",getRootElement(),hydraulics) I can just TP to the location everytime I want, while it should be allowed only once every 5 minutes. It shows the message everytime I TP to the gunshop. How can I fix this? Edited December 10, 2016 by marty000123
LoPollo Posted December 10, 2016 Posted December 10, 2016 Check your code, seriously. Think what every instruction do like if you are the computer. I don't think a real help is needed.
marty000123 Posted December 12, 2016 Author Posted December 12, 2016 On 10-12-2016 at 7:18 PM, LoPollo said: Check your code, seriously. Think what every instruction do like if you are the computer. I don't think a real help is needed. I literally can't figure it out lol
LoPollo Posted December 12, 2016 Posted December 12, 2016 your "if" checknif aTimer is a timer. You set it as timer in the previous line. also your "or" is probably an else?
EmBaby85 Posted December 12, 2016 Posted December 12, 2016 (edited) aTimer = { } function hydraulics(player) if (not getElementType(player)=="player") then return end local vehicle=getPedOccupiedVehicle(player) if (aTimer[player] and getTickCount() - aTimer[player] < 300000) then setElementPosition(player, 199.2939453125, 1428.4794921875, 10.5859375) aTimer[player] = getTickCount() else outputChatBox( "#ff0000You can only TP to the Gun Shop once every 5 minutes!", player) end end addEvent("hydraulics",true) addEventHandler("hydraulics",getRootElement(),hydraulics) Edited December 12, 2016 by Rands
Savannah Posted December 12, 2016 Posted December 12, 2016 You can perfectly use setTimer(). Here this should be a little easier for you to understand: local aTimer = {} function hydraulics(plr) if getElementType(plr) == "player" then if isTimer(aTimer[plr]) then outputChatBox("#ff0000You can only TP to the Gun Shop once every 5 minutes!", plr, 255, 255, 255, true) else setElementPosition(plr, 199.2939453125, 1428.4794921875, 10.5859375) aTimer[plr] = setTimer(function(plr) aTimer[plr] = nil end,4000,1,plr) end end end addEvent("hydraulics",true) addEventHandler("hydraulics",root,hydraulics) addCommandHandler("tp",hydraulics,false,false)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now