Jump to content

[Duvida] Qual modo de fazer um sleep/wait


Recommended Posts

Posted (edited)

Estou tentando fazer um evento acontecer 2 minutos após ser chamado, mas percebi que não existe uma função de wait ou sleep nativa do Lua, o evento seria mais ou menos como esse.
 

destruir = createMarker(2445.2878417969,-957.39611816406,80.04273223877 -2,"cylinder", 3.0, 128, 0, 0, 99)

function destroi ( thePlayer )
  	outputChatBox("Seu veiculo será destruido em 2 minutos!", thePlayer)
  	sleep(120000);  
  	destroyElement (thePlayer)
    outputChatBox("Veiculo destruido com sucesso!", thePlayer)

end
    addEventHandler("onMarkerHit", destruir, destroi)

Gostaria de saber como fazer algo parecido

Edited by Breevz
  • Other Languages Moderators
Posted (edited)

Ta ae, amigo:

destruir = createMarker (2445.2878417969, -957.39611816406, 80.04273223877 -2, "cylinder", 3.0, 128, 0, 0, 99)

function destroi (thePlayer)
    outputChatBox ("Seu veiculo será destruido em 2 minutos!", thePlayer)
    setTimer (function ()
        destroyElement (thePlayer)
        outputChatBox ("Veiculo destruido com sucesso!", thePlayer)
    end, 120000, 1)
end
addEventHandler ("onMarkerHit", destruir, destroi)

 

Edited by Lord Henry
Correção da minha burrice.
  • Like 1
  • Thanks 1
Posted
1 hour ago, Lord Henry said:

Ta ae, amigo:


destruir = createMarkerv (2445.2878417969, -957.39611816406, 80.04273223877 -2, "cylinder", 3.0, 128, 0, 0, 99)

function destroi (thePlayer)
    outputChatBox ("Seu veiculo será destruido em 2 minutos!", thePlayer)
    setTimer (function ()
        destroyElement (thePlayer)
        outputChatBox ("Veiculo destruido com sucesso!", thePlayer)
    end, 120000, 1)
end
addEventHandler ("onMarkerHit", destruir, destroi)

 

Quando utilizar esse script, pra não acontece de da erro, e volta aqui, remova no final do createMarker o v (Caso não identifica o erro)
 

Posted
3 hours ago, Lord Henry said:

Ta ae, amigo:


destruir = createMarkerv (2445.2878417969, -957.39611816406, 80.04273223877 -2, "cylinder", 3.0, 128, 0, 0, 99)

function destroi (thePlayer)
    outputChatBox ("Seu veiculo será destruido em 2 minutos!", thePlayer)
    setTimer (function ()
        destroyElement (thePlayer)
        outputChatBox ("Veiculo destruido com sucesso!", thePlayer)
    end, 120000, 1)
end
addEventHandler ("onMarkerHit", destruir, destroi)

 

Eita, bem fácil até, só acho que seria mais fácil se isso virasse uma função tipo sleepmta(1000), vlw ae

  • Other Languages Moderators
Posted

Você mesmo pode criar uma função sleep(). Basta usar coroutines.

  • Other Languages Moderators
Posted
9 hours ago, Angelo Pereira said:

remova no final do createMarker o v (Caso não identifica o erro)

Corrigido.

Perdão pelo vacilo.

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