Jump to content

How to put Time to get a command


Isaias1999

Recommended Posts

Hi,i'm new here ,and i'm noob ,i wanna  know how to put a time of 3 minutes to get this command what i gave of this forum ,i wanna know then i can put that and the player could'nt abuse of this command ,i'm going to leave this ,please help me (sorry for mi noob english)

 


function fix (playerSource) 
    local theVehicle = getPedOccupiedVehicle (playerSource) 
    if theVehicle and getVehicleController ( theVehicle ) == playerSource then  
         fixVehicle (theVehicle)  
         outputChatBox ("Your vehicle has been repaired !" , thePlayer) 
    end 
end 
addCommandHandler ("repair" , fix) 

Link to comment
  • 2 months later...

this isnt the correct page to do this ask,  but you can try to use setTimer like this


timer = {} --\\ create a table for all timers
function fix (playerSource) 
    if isTimer(timer[playerSource]) then return outputChatBox("Wait just a litte.",playerSource) end --\\ send an error msg to player, if he is spamming
    local interval = 15000 --\\ set up the interval in milliseconds
    local theVehicle = getPedOccupiedVehicle (playerSource) 
    if theVehicle and getVehicleController ( theVehicle ) == playerSource then  
         fixVehicle (theVehicle)  
         outputChatBox ("Your vehicle has been repaired !" , thePlayer) 
        
        timer[playerSource] = setTimer(function(playerSource)  --\\ finally create the timer when player type the command.
            timer[playerSource] = nil 
        end,interval,1,playerSource)
    end
end
addCommandHandler ("repair" , fix) 

Edited by iDannz
Link to comment

With getTickCount() the script is more efficient:

local SECONDS = 20 -- 20 seconds between command use
local tick = {}

function fix(playerSource) 
    local theVehicle = getPedOccupiedVehicle(playerSource) 
    if theVehicle and getVehicleController ( theVehicle ) == playerSource then  
		if getTickCount() - (tick[playerSource] or 0) >= SECONDS * 1000 then
			fixVehicle (theVehicle)  
			tick[playerSource] = getTickCount()
			outputChatBox ("Your vehicle has been repaired !" , thePlayer) 
		else
			outputChatBox ("Don't abuse the command!" , thePlayer) 
		end
    end 
end 
addCommandHandler("repair" , fix)

Change 'SECONDS' variable to whatever you need.

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...