Jump to content

Vehicle Respawn


Captain Cody

Recommended Posts

How can I make it so only vehicles from one resource respawn? Ive got one resource with all the servers Main vehicles spawned with it and one that is a car shop and I dont want the Resources from the car shop to respawn

Lua For Main Cars:

Server:

function spawnVehs() 
    for k, v in ipairs (getElementsByType("veh")) do 
        createVehicle(getElementData(v,"model"),getElementData(v,"posX"),getElementData(v,"posY"),getElementData(v,"posZ"),0,0,getElementData(v,"rotation")) 
    end 
    for k, v in ipairs (getElementsByType("vehicle")) do 
        toggleVehicleRespawn(v,true) 
        setVehicleIdleRespawnDelay(v,120000) 
    end 
end 
addEventHandler("onResourceStart",getResourceRootElement(),spawnVehs) 
  
function respawnVeh() 
    setTimer(respawnVehicle,5000,1,source) 
end 
addEventHandler("onVehicleExplode",getRootElement(),respawnVeh) 

Adder

function addNew(source,command) 
    if (isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)),aclGetGroup("Admin"))) then 
        if (isPedInVehicle(source)) then 
            local x,y,z = getElementPosition(getPedOccupiedVehicle(source)) 
            local model = getElementModel(getPedOccupiedVehicle(source)) 
            local rotX,rotY,rotZ = getVehicleRotation(getPedOccupiedVehicle(source)) 
            local file = xmlLoadFile("vehicles.map") 
            local veh = xmlCreateChild(file,"veh") 
            xmlNodeSetAttribute(veh,"model",model) 
            xmlNodeSetAttribute(veh,"posX",x) 
            xmlNodeSetAttribute(veh,"posY",y) 
            xmlNodeSetAttribute(veh,"posZ",z) 
            xmlNodeSetAttribute(veh,"rotation",rotZ) 
            xmlSaveFile(file) 
            xmlUnloadFile(file) 
            outputChatBox("*INFO* The vehicle has been successfully added and will be created in 5 seconds.",source,255,255,0) 
            outputDebugString(getPlayerName(source).." has mapped a "..getVehicleName(getPedOccupiedVehicle(source)).." in "..getElementZoneName(getPedOccupiedVehicle(source))..", "..getElementZoneName(getPedOccupiedVehicle(source),true)..".") 
            setTimer(function() createVehicle(model,x,y,z,0,0,rotZ) end,5000,1) 
        end 
    end 
end 
addCommandHandler("addcar",addNew) 

And the car locations are stored in a map file

Luas For car shop:https://forum.multitheftauto.com/viewtopic.php?f=91&t=78063

Look at the luas on the first post

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