Jump to content

Help setTimer


Recommended Posts

Well I would like to use the SetTimer for when a player enter / or life / vest he takes life but can only use these two commands again after 20 seconds I have tried everything but just goes to the SetTimer function and not for command could anyone do to me?

-- Função da vida: 
function buyhealth ( thePlayer ) 
    local money = getPlayerMoney ( thePlayer ) 
    if money >= 500 then 
        outputChatBox("Você comprou Vida por 500$",thePlayer, 255, 106, 106) 
        local thePlayerhealth = getElementHealth ( thePlayer ) 
        setElementHealth ( thePlayer, 569 ) 
        takePlayerMoney ( thePlayer, 500 ) 
    else 
        outputChatBox("Não há dinheiro suficiente, necessário 500$",thePlayer, 139, 101, -- s8) -->
    end 
end 
addCommandHandler ( "vida", buyhealth ) 
  
--Função do colete: 
function buyarmor ( thePlayer ) 
    local money = getPlayerMoney ( thePlayer ) 
    if money >= 500 then 
        outputChatBox("Você comprou Colete por 500$",thePlayer, 255, 106, 106) 
        local thePlayerarmor = getPedArmor(thePlayer) 
        setPedArmor ( thePlayer, 100 ) 
        takePlayerMoney ( thePlayer, 500 ) 
    else 
        outputChatBox("Não há dinheiro suficiente, necessário 500$!",thePlayer, 139, 117, 0) 
    end 
end 
addCommandHandler ( "colete", buyarmor ) 

Link to comment

Here's an example :

local LastHandled = {           } 
  
function buyhealth ( thePlayer ) 
    if not LastHandled [ thePlayer ] then 
        LastHandled [ thePlayer ] = {       } 
    end 
    if LastHandled [ thePlayer ] == false then return outputChatBox('Please Wait 20 Sec!',thePlayer,255,0,0) end 
    local money = getPlayerMoney ( thePlayer ) 
    if money >= 500 then 
        outputChatBox("Você comprou Vida por 500$",thePlayer, 255, 106, 106) 
        local thePlayerhealth = getElementHealth ( thePlayer ) 
        setElementHealth ( thePlayer, 569 ) 
        takePlayerMoney ( thePlayer, 500 ) 
    else 
        outputChatBox("Não há dinheiro suficiente, necessário 500$",thePlayer, 139, 101, -- s8) -->
    end 
    LastHandled [ thePlayer ] = false 
    setTimer ( function ( ) LastHandled [ thePlayer ] = true end,20000,1 ) 
end 
addCommandHandler ( "vida", buyhealth ) 

This is for the health make it for anything you want .

Edited by Guest
Link to comment

Won't work either.

This one works:

local LastHandled = { } 
  
function buyhealth ( thePlayer ) 
    if ( LastHandled [ thePlayer ] == nil ) then 
        LastHandled [ thePlayer ] = { } 
    end 
  
    if ( LastHandled [ thePlayer ] == false ) then 
        return outputChatBox ( 'Please Wait 20 Sec!', thePlayer, 255, 0, 0 ) 
    end 
  
    local money = getPlayerMoney ( thePlayer ) 
    if ( money >= 500 ) then 
        outputChatBox ( "Você comprou Vida por 500$", thePlayer, 255, 106, 106 ) 
        local thePlayerhealth = getElementHealth ( thePlayer ) 
        setElementHealth ( thePlayer, 569 ) 
        takePlayerMoney ( thePlayer, 500 ) 
    else 
        outputChatBox ( "Não há dinheiro suficiente, necessário 500$", thePlayer, 139, 101, 8 ) 
    end 
    LastHandled [ thePlayer ] = false 
    setTimer ( 
        function ( ) 
            LastHandled [ thePlayer ] = true 
        end 
        ,20000, 1 
    ) 
end 
addCommandHandler ( "vida", buyhealth ) 

Link to comment
Won't work either.

This one works:

local LastHandled = { } 
  
function buyhealth ( thePlayer ) 
    if ( LastHandled [ thePlayer ] == nil ) then 
        LastHandled [ thePlayer ] = { } 
    end 
  
    if ( LastHandled [ thePlayer ] == false ) then 
        return outputChatBox ( 'Please Wait 20 Sec!', thePlayer, 255, 0, 0 ) 
    end 
  
    local money = getPlayerMoney ( thePlayer ) 
    if ( money >= 500 ) then 
        outputChatBox ( "Você comprou Vida por 500$", thePlayer, 255, 106, 106 ) 
        local thePlayerhealth = getElementHealth ( thePlayer ) 
        setElementHealth ( thePlayer, 569 ) 
        takePlayerMoney ( thePlayer, 500 ) 
    else 
        outputChatBox ( "Não há dinheiro suficiente, necessário 500$", thePlayer, 139, 101, 8 ) 
    end 
    LastHandled [ thePlayer ] = false 
    setTimer ( 
        function ( ) 
            LastHandled [ thePlayer ] = true 
        end 
        ,20000, 1 
    ) 
end 
addCommandHandler ( "vida", buyhealth ) 

Reason.

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