Jump to content

tp only once every 5 min


marty000123

Recommended Posts

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 by marty000123
Link to comment
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 by Rands
Link to comment

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)

 

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...