Jump to content

car respawn bugg


Recommended Posts

Why does all my cars destroyed when i want to respawn them? I want to respawn them, not to destroy them totally

There are no errors in debugscript script

respawnlock = false 
addEventHandler("onResourceStart", resourceRoot, function() 
    mainTimer = setTimer(respawnVehicles, 900000, 0) 
end) 
  
function respawnVehicles() 
    if not respawnlock then 
        respawnlock = true 
        exports.command:sendMessage("Respawning all unoccupied vehicles in 30 seconds!", 0, 255, 0, root) 
        setTimer ( function(msg, target, r, g, b) exports.command:sendMessage(msg, r, g, b, target) end , 10000, 1, "Respawning all unoccupied vehicles in 20 seconds!", getRootElement(), 0, 255, 0 ) 
        setTimer ( function(msg, target, r, g, b) exports.command:sendMessage(msg, r, g, b, target) end, 20000, 1, "Respawning all unoccupied vehicles in 10 seconds!", getRootElement(), 0, 255, 0 ) 
        setTimer ( function(msg, target, r, g, b) exports.command:sendMessage(msg, r, g, b, target) end, 25000, 1, "Respawning all unoccupied vehicles in 5 seconds!", getRootElement(), 0, 255, 0 ) 
        setTimer ( vehrestask, 30000, 1) 
        resetTimer(mainTimer) 
    end 
end 
  
function respawnCommand(player) 
    if not respawnlock then 
     local accName = getAccountName(getPlayerAccount(player)) -- get his account name 
     if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then -- Does he have access to Admin functions? 
            respawnVehicles() 
        end 
    else 
        exports.command:sendMessage("*vehicles* Wait for the current respawn to end!", 0, 255, 0, player) 
    end 
end 
addCommandHandler("vehiclerespawn", respawnCommand) 
  
function vehrestask() 
    local resVehicles = getElementsByType("vehicle") 
    for i,v in ipairs(resVehicles) do 
        local occupants = getVehicleOccupants(v) -- Get all vehicle occupants 
         
        local occupied = false 
         
        if occupants then 
            for seat, occupant in pairs(occupants) do 
                if occupant then 
                    occupied = true 
                    break 
                end 
            end 
        end 
         
        if getVehicleController(v) then 
            occupied = true 
        end 
         
        if not occupied then 
        if getElementID(getElementParent(getElementParent(v))) ~= "Admin" then 
          respawn = respawnVehicle(v) 
          if not respawn then 
                    destroyElement(v) 
                else 
                    destroyElement(v) 
                end 
            --[[elseif getElementData(v, "personalVehicle") then 
                exports.housing:vehicleRecache(v)]]-- 
            else 
                if not getElementData(v, "personalVehicleID") then 
                    destroyElement(v) 
                end 
            end 
        end 
    end 
    if getResourceState(getResourceFromName("publicvehicles")) == "running" then exports.publicvehicles:spawnPublicCars() end 
    exports.command:sendMessage("All unoccupied vehicles have been respawned!", 0, 255, 0, root) 
    respawnlock = false 
end 

Link to comment

It's because of this part:

if not respawn then 
                    destroyElement(v) 
                else 
                    destroyElement(v) 
                end 

What is that? You destroy it no matter what respawn is. Remove the else part.

Link to comment
it works but now the part with :

-[[elseif getElementData(v, "personalVehicle") then

exports.Mylifehousing:vehicleRecache(v)]]--

doesn't work

used the code

and all vehicles respwan all 30 sec

  
addEventHandler("onResourceStart", resourceRoot, function() 
    for i,veh in ipairs(getElementsByType("vehicle")) do 
        toggleVehicleRespawn (veh true )  
        setVehicleIdleRespawnDelay (veh, 30000 ) 
   end 
end)    

Link to comment

I need this kind of lines in the script to respawn the occopied cars into the save disk

-[[elseif getElementData(v, "personalVehicle") then

exports.Mylifehousing:vehicleRecache(v)]]--

it doesn't respawn in the save disk if i use that code from yours

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