Jump to content

[HELP] Respawn Vehicle on playerExit


opnaiC

Recommended Posts

function bmxS() 
local player = getPedOccupiedVehicle ( thePlayer ) 
local bmx = { [510]=true } 
   if bmx[getElementModel(source)] then 
   local = setTimer(respawnVehicle, 5000, 1, source) 
   else 
   for timerKey, timerValue in ipairs(timers) do 
   killTimer(5000) 
   end 
end 
end 
addEventHandler("onVehicleExit", root, bmxS) 

My function isnt working. When a player leaves the vehicle it should respawn, but when he is entering it again it shouldnt.

Link to comment
local bmx = { [510]=true } 
  
function bmxS(player, seat) 
    local model = getElementModel (source) 
    if bmx[model] then  
        setTimer(respawnVehicle, 5000, 1, source) 
    end  
end 
addEventHandler("onVehicleExit", root, bmxS) 

Link to comment
local bmx = { [510]=true } 
  
function bmxS(player, seat) 
    local model = getElementModel (source) 
    if bmx[model] then  
        setTimer(respawnVehicle, 5000, 1, source) 
    end  
end 
addEventHandler("onVehicleExit", root, bmxS) 

But how I can destroy the time when he enters again the vehicle

Link to comment
  
local bmx = { [510]=true } 
  
function bmxS(player, seat) 
    local model = getElementModel (source) 
    if bmx[model] then 
        timer = setTimer(respawnVehicle, 5000, 1, source) 
    end 
end 
addEventHandler("onVehicleExit", root, bmxS) 
  
function stopr () 
if bmx[model] then 
   elseif (isTimer(timer)) then killTimer(timer) 
end 
end 
addEventHandler("onVehicleEnter", root, stopr) 
  

Link to comment

you don't need to destroy it because the timesToExecute it's not 0 (infinite repetitions) , it will be destroyed after 5 seconds.

Anyways you can use smth like this if you use a timer > then 10 seconds.

local bmx = { [510]=true } 
local destroy = {} 
  
function bmxS(player, seat) 
    local model = getElementModel (source) 
    if eventName == "onVehicleExit" then  
        if bmx[model] then 
            destroy[source] = setTimer(respawnVehicle, 5000, 1, source) 
        end 
    elseif eventName == "onVehicleEnter" then  
        if isTimer (destroy[source]) then  
            killTimer(destroy[source]) 
        end  
    end  
end 
addEventHandler("onVehicleExit", root, bmxS) 
addEventHandler ("onVehicleEnter", root, bmxS) 

Edit: :fp: @swedishboy

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