Jump to content

How can i delay a function? Help :(


Andres99907

Recommended Posts

I have this:

 

function Salir()
    if isElement(tableVehicles[source]) then
        destroyElement(tableVehicles[source])        
    end
end

addEventHandler("onPlayerVehicleExit",getRootElement(),Salir)

 

 

This function destroys the vehicle when the player leaves, I want this to happen after a second and not immediately, i need to use "Set timer", but I do not know how to use it, I tried different ways but none of them :(

Link to comment
timers = {}

function Salir()
    if isElement(tableVehicles[source]) then
        destroyElement(tableVehicles[source])   
    	if timers[source] then
      		killTimer(timers[source])
     	end
		timers[source] = setTimer ( removeVehicle, 1000, 1, source )
    end
end

function removeVehicle(player)
  destroyElement(tableVehicles[player])
  tableVehicles[player] = nil
end

addEventHandler("onPlayerVehicleExit",getRootElement(),Salir)

Also, next time please use https://forum.multitheftauto.com/forum/71-scripting/

or the corresponding scripting section for your language (Which from what I can tell is obviously not English.)

Edited by CodyJ(L)
  • Thanks 1
Link to comment
EspañolInglésItaliano---------------Detectar idiomaAfrikáansAlbanésAlemánAmáricoÁrabeArmenioAzerbaiyanoBengalíBielorrusoBirmanoBosnioBúlgaroCanarésCatalánCebuanoChecoChino (Simplificado)Chino (Tradicional)CingalésCoreanoCorsoCriollo haitianoCroataDanésEslovacoEslovenoEspañolEsperantoEstonioEuskeraFinésFrancésFrisón occidentalGaélico escocésGalésGallegoGeorgianoGriegoGuyaratíHausaHawaianoHebreoHindiHmongHúngaroIgboIndonesioInglésIrlandésIslandésItalianoJaponésJavanésJemerKazajoKirguísKurdoLaoLatínLetónLituanoLuxemburguésMacedonioMalayalamMalayoMalgacheMaltésMaoríMaratíMongolNeerlandésNepalíNoruegoNyanjaPanyabíPastúnPersaPolacoPortuguésRumanoRusoSamoanoSerbioShonaSindhiSomalíSotho meridionalSuajiliSuecoSundanésTagaloTailandésTamilTayikoTeluguTurcoUcranianoUrduUzbekoVietnamitaXhosaYidisYorubaZulúEspañol
 
 
Thank you! , I really appreciate it C:
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...