Jump to content

timer


Wei

Recommended Posts

how can I make that all players on server cannot do a command like the most system on rober of ammunation and it output chat box

ammunation has been allready robbed. You need to wait (seconds) to rob it again.

Link to comment
Guest Guest4401
It's all on wiki, just read it all

https://wiki.multitheftauto.com/wiki/getTickCount

This function returns amount of time that your system has been running in milliseconds. By comparing two values of getTickCount, you can determine how much time has passed (in milliseconds) between two events. This could be used to determine how efficient your code is, or to time how long a player takes to complete a task.

Exactly, I meant the same...

When it is robbed, use getTickCount() to get current tick count.

When someone tries to rob it again, subtract previous tick count with present tick count.

Use >, <, <=, >= to see if _ seconds have passed or not.

If not passed, then tell the user that he has to wait _ seconds more

Link to comment

how can I make that player need to wait 60 minutes to type command again

CODE:

function setTimerToNextCommand(thePlayer) 
    local chance = math.random (1, 5) 
    local rand = math.random ( 1000, 7000 ) 
    if (chance == 1) then 
    outputChatBox( "YEAH! you've got $" tonumber (rand), thePlayer, 0, 255, 0) 
    givePlayerMoney(thePlayer, rand) 
    else 
    outputChatBox( "Failed", thePlayer, 0, 255, 0) 
end 
addCommandHandler("lottery buy", setTimerToNextCommand) 

Link to comment
Guest Guest4401

In this example the person can buy lottery only every 10 seconds

interval = 10 -- in seconds 
  
function setTimerToNextCommand(thePlayer) 
    if getTickCount() - (getElementData(thePlayer,"tick") or (-interval)*1000 ) > interval*1000 then -- if 10 seconds past since his last lottery 
        local chance = math.random (1, 5) 
        local rand = math.random ( 1000, 7000 ) 
        setElementData(thePlayer,"tick",getTickCount()) -- get Current tick count and save it 
        if (chance == 1) then 
        outputChatBox( "YEAH! you've got $"..tonumber (rand), thePlayer, 0, 255, 0) 
        givePlayerMoney(thePlayer, rand) 
        else 
        outputChatBox( "Failed", thePlayer, 0, 255, 0) 
        end 
    else 
        outputChatBox("Please wait "..(interval + 1) - math.ceil((getTickCount() - getElementData(thePlayer,"tick"))/1000).." seconds more to buy lottery again",thePlayer,0,255,0) 
    end 
end 
addCommandHandler("lotterybuy", setTimerToNextCommand) 

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