Jump to content

Help with setTimer


xXMADEXx

Recommended Posts

I don't know how to destroy the timer :S so "The crack time has ended" spams.

function crack(player) 
    if (not isPedInVehicle(player)) then 
        outputChatBox("you're jump height has been set to double.",player,0,255,0) 
        setTimer( 
            function () 
                setPedGravity ( source, 50 ) 
                outputChatBox("The crack time has ended.",source,255,255,0) 
            end 
        ,5000,0) 
    else 
        outputChatBox("You cannot use crack in a vehicle.",player,255,0,0) 
    end 
end 
addCommandHandler("crack",crack) 
  

Link to comment

try

function crack(player) 
    if (not isPedInVehicle(player)) then 
        outputChatBox("you're jump height has been set to double.",player,0,255,0) 
        setTimer( 
            function () 
                setPedGravity ( source, 50 ) 
                outputChatBox("The crack time has ended.",source,255,255,0) 
            end 
        ,5000,1) 
    else 
        outputChatBox("You cannot use crack in a vehicle.",player,255,0,0) 
    end 
end 
addCommandHandler("crack",crack) 

Link to comment
save the timer in memory by storing it in a variable.

When you need to destroy it:

if isTimer(timer) then 
     killTimer(timer           
end 

I tried this, but it didn't work.

        setTimer( 
            function () 
                setPedGravity ( source, 50 ) 
                outputChatBox("The crack time has ended.",source,255,255,0) 
                if isTimer(timer) then 
                    killTimer(timer)        
                end 
            end 
        ,5000,0) 

Link to comment
timer = setTimer( 
            function () 
                setPedGravity ( source, 50 ) 
                outputChatBox("The crack time has ended.",source,255,255,0) 
                if isTimer(timer) then 
                    killTimer(timer)       
                end 
            end 
        ,5000,0) 

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