Jump to content

Respawn Vehicles


undefined

Recommended Posts

Hi guys.

Im work on the vehicle respawner and i have a problem.

When the respawn vehicle, not remove the upgrades.

My code:

addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), function() 
    for key,veh in ipairs(getElementsByType ("vehicle")) do 
        if not getElementData(veh, "doNotRespawn") then 
            toggleVehicleRespawn (veh, true) 
            setVehicleRespawnDelay (veh, 10000) 
            setVehicleIdleRespawnDelay (veh, 60000) 
            local color1, color2, color3, color4 = getVehicleColor (veh) 
            setVehicleColor(veh, color1, color2, color3, color4) 
            setVehiclePlateText(veh, "Saruhan") 
            setElementData(veh, "vehPaintJob", getVehiclePaintjob(veh)) 
            setElementData(veh, "vehColor1", color1) 
            setElementData(veh, "vehColor2", color2) 
            setElementData(veh, "vehColor3", color3) 
            setElementData(veh, "vehColor4", color4) 
        end 
    end 
end) 
  
addEventHandler ( "onVehicleRespawn", getRootElement(), function( exploded ) 
    if not getElementData(source, "doNotRespawn") then 
        local vehPaintJob = getElementData(source, "vehPaintJob") 
        local color1 = getElementData(source, "vehColor1") 
        local color2 = getElementData(source, "vehColor2") 
        local color3 = getElementData(source, "vehColor3") 
        local color4 = getElementData(source, "vehColor4") 
        setVehiclePaintjob(source, vehPaintJob) 
        setVehicleColor(source, color1, color2, color3, color4) 
        setVehicleEngineState(source, false) 
        setVehicleOverrideLights (source, 1) 
        setVehicleLocked(source, false) 
        setVehiclePlateText(source, "Saruhan") 
        setVehicleDoorOpenRatio(source, 0, 0, 0.5) 
        setVehicleDoorOpenRatio(source, 1, 0, 0.5) 
        setVehicleDoorOpenRatio(source, 2, 0, 0.5) 
        setVehicleDoorOpenRatio(source, 3, 0, 0.5) 
        setVehicleDoorOpenRatio(source, 4, 0, 0.5) 
        setVehicleDoorOpenRatio(source, 5, 0, 0.5) 
        for i=1000,1193 do 
        removeVehicleUpgrade (source, i) 
        end 
    end 
end) 

Where is the problem?

Link to comment
Required Arguments

theVehicle: The vehicle you wish to change the override lights setting of.

Change source to veh

#

My new code:

addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), function() 
    for key,veh in ipairs(getElementsByType ( "vehicle" )) do 
        if not getElementData(veh, "doNotRespawn") then 
            toggleVehicleRespawn ( veh, true ) 
            setVehicleRespawnDelay ( veh, 10000) 
            setVehicleIdleRespawnDelay ( veh, 60000) 
            local color1, color2, color3, color4 = getVehicleColor ( veh ) 
            setVehicleColor(veh, color1, color2, color3, color4) 
            setVehiclePlateText(veh, "Saruhan") 
            setElementData(veh, "vehPaintJob", getVehiclePaintjob(veh)) 
            setElementData(veh, "vehColor1", color1) 
            setElementData(veh, "vehColor2", color2) 
            setElementData(veh, "vehColor3", color3) 
            setElementData(veh, "vehColor4", color4) 
        end 
    end 
end) 
  
addEventHandler ( "onVehicleRespawn", getRootElement(), function( exploded ) 
        if not getElementData(veh, "doNotRespawn") then 
            local vehPaintJob = getElementData(veh, "vehPaintJob") 
            local color1 = getElementData(veh, "vehColor1") 
            local color2 = getElementData(veh, "vehColor2") 
            local color3 = getElementData(veh, "vehColor3") 
            local color4 = getElementData(veh, "vehColor4") 
            setVehiclePaintjob(veh, vehPaintJob) 
            setVehicleColor(veh, color1, color2, color3, color4) 
            setVehicleEngineState(veh, false) 
            setVehicleOverrideLights (veh, 1) 
            setVehicleLocked(veh, false) 
            setVehiclePlateText(veh, "Saruhan") 
            setVehicleDoorOpenRatio(veh, 0, 0, 0.5) 
            setVehicleDoorOpenRatio(veh, 1, 0, 0.5) 
            setVehicleDoorOpenRatio(veh, 2, 0, 0.5) 
            setVehicleDoorOpenRatio(veh, 3, 0, 0.5) 
            setVehicleDoorOpenRatio(veh, 4, 0, 0.5) 
            setVehicleDoorOpenRatio(veh, 5, 0, 0.5) 
            for i,upgrade in ipairs(getVehicleCompatibleUpgrades(veh)) do 
            removeVehicleUpgrade (veh, upgrade) 
            end 
    end 
end) 

bQD9Gn.png

Link to comment
addEventHandler ( "onResourceStart", resourceRoot, function () 
    for _,veh in ipairs ( getElementsByType ( "vehicle" ) ) do 
        if not ( getElementData ( veh, "doNotRespawn" ) ) then 
            toggleVehicleRespawn  ( veh, true ) 
            setVehicleRespawnDelay ( veh, 10000 ) 
            setVehicleIdleRespawnDelay ( veh, 60000 ) 
            local color1, color2, color3, color4 = getVehicleColor ( veh ) 
            setVehicleColor ( veh, color1, color2, color3, color4 ) 
            setVehiclePlateText ( veh, "Saruhan" ) 
            setElementData ( veh, "vehPaintJob", getVehiclePaintjob ( veh ) ) 
            setElementData ( veh, "vehColor1", color1 ) 
            setElementData ( veh, "vehColor2", color2 ) 
            setElementData ( veh, "vehColor3", color3 ) 
            setElementData ( veh, "vehColor4", color4 ) 
        end 
    end 
end) 
  
addEventHandler ( "onVehicleRespawn", root, function () 
    if not ( getElementData ( source, "doNotRespawn" ) ) then 
        local vehPaintJob = getElementData ( source, "vehPaintJob" ) 
        local color1 = getElementData ( source, "vehColor1" ) 
        local color2 = getElementData ( source, "vehColor2" ) 
        local color3 = getElementData ( source, "vehColor3" ) 
        local color4 = getElementData ( source, "vehColor4" ) 
        setVehiclePaintjob ( source, vehPaintJob ) 
        setVehicleColor ( source, color1, color2, color3, color4 ) 
        setVehicleEngineState ( source, false ) 
        setVehicleOverrideLights ( source, 1 ) 
        setVehicleLocked ( source, false ) 
        setVehiclePlateText ( source, "Saruhan" ) 
        setVehicleDoorOpenRatio ( source, 0, 0, 0.5 ) 
        setVehicleDoorOpenRatio ( source, 1, 0, 0.5 ) 
        setVehicleDoorOpenRatio ( source, 2, 0, 0.5 ) 
        setVehicleDoorOpenRatio ( source, 3, 0, 0.5 ) 
        setVehicleDoorOpenRatio ( source, 4, 0, 0.5 ) 
        setVehicleDoorOpenRatio ( source, 5, 0, 0.5 ) 
        for _,v in ipairs ( getVehicleUpgrades ( source ) ) do 
            removeVehicleUpgrade ( source, v ) 
        end 
    end 
end) 

Link to comment

try this , serverside

addEventHandler ( "onResourceStart", resourceRoot, function () 
    for _,veh in ipairs ( getElementsByType ( "vehicle" ) ) do 
        if not ( getElementData ( veh, "doNotRespawn" ) ) then 
            toggleVehicleRespawn  ( veh, true ) 
            setVehicleRespawnDelay ( veh, 10000 ) 
            setVehicleIdleRespawnDelay ( veh, 60000 ) 
            local color1, color2, color3, color4 = getVehicleColor ( veh ) 
            setVehicleColor ( veh, color1, color2, color3, color4 ) 
            setVehiclePlateText ( veh, "Saruhan" ) 
            setElementData ( veh, "vehPaintJob", getVehiclePaintjob ( veh ) ) 
            setElementData ( veh, "vehColor1", color1 ) 
            setElementData ( veh, "vehColor2", color2 ) 
            setElementData ( veh, "vehColor3", color3 ) 
            setElementData ( veh, "vehColor4", color4 ) 
        end 
    end 
end) 
  
addEventHandler ( "onVehicleRespawn", root, function () 
    if not ( getElementData ( source, "doNotRespawn" ) ) then 
    for _,veh in ipairs ( getElementsByType ( "vehicle" ) ) do 
        local vehPaintJob = getElementData ( source, "vehPaintJob" ) 
        local color1 = getElementData ( veh, "vehColor1" ) 
        local color2 = getElementData ( veh, "vehColor2" ) 
        local color3 = getElementData ( veh, "vehColor3" ) 
        local color4 = getElementData ( veh, "vehColor4" ) 
        setVehiclePaintjob ( veh, vehPaintJob ) 
        setVehicleColor ( veh, color1, color2, color3, color4 ) 
        setVehicleEngineState (source, false ) 
         playerVehicle = getPedOccupiedVehicle ( source )                 
        if ( playerVehicle ) then                                        
        if ( getVehicleOverrideLights ( playerVehicle ) ~= 2 ) then  
        setVehicleOverrideLights ( playerVehicle, 2 )   
        setVehicleLocked ( source, false ) 
        setVehiclePlateText ( source, "Saruhan" ) 
        setVehicleDoorOpenRatio ( source, 0, 0, 0.5 ) 
        setVehicleDoorOpenRatio ( source, 1, 0, 0.5 ) 
        setVehicleDoorOpenRatio ( source, 2, 0, 0.5 ) 
        setVehicleDoorOpenRatio ( source, 3, 0, 0.5 ) 
        setVehicleDoorOpenRatio ( source, 4, 0, 0.5 ) 
        setVehicleDoorOpenRatio ( source, 5, 0, 0.5 ) 
        for i=1000,1193 do 
        removeVehicleUpgrade (source, i) 
             end 
          end 
         end 
      end 
   end 
 end 
) 

/debugscript 3

Link to comment
try this , serverside

addEventHandler ( "onResourceStart", resourceRoot, function () 
    for _,veh in ipairs ( getElementsByType ( "vehicle" ) ) do 
        if not ( getElementData ( veh, "doNotRespawn" ) ) then 
            toggleVehicleRespawn  ( veh, true ) 
            setVehicleRespawnDelay ( veh, 10000 ) 
            setVehicleIdleRespawnDelay ( veh, 60000 ) 
            local color1, color2, color3, color4 = getVehicleColor ( veh ) 
            setVehicleColor ( veh, color1, color2, color3, color4 ) 
            setVehiclePlateText ( veh, "Saruhan" ) 
            setElementData ( veh, "vehPaintJob", getVehiclePaintjob ( veh ) ) 
            setElementData ( veh, "vehColor1", color1 ) 
            setElementData ( veh, "vehColor2", color2 ) 
            setElementData ( veh, "vehColor3", color3 ) 
            setElementData ( veh, "vehColor4", color4 ) 
        end 
    end 
end) 
  
addEventHandler ( "onVehicleRespawn", root, function () 
    if not ( getElementData ( source, "doNotRespawn" ) ) then 
    for _,veh in ipairs ( getElementsByType ( "vehicle" ) ) do 
        local vehPaintJob = getElementData ( source, "vehPaintJob" ) 
        local color1 = getElementData ( veh, "vehColor1" ) 
        local color2 = getElementData ( veh, "vehColor2" ) 
        local color3 = getElementData ( veh, "vehColor3" ) 
        local color4 = getElementData ( veh, "vehColor4" ) 
        setVehiclePaintjob ( veh, vehPaintJob ) 
        setVehicleColor ( veh, color1, color2, color3, color4 ) 
        setVehicleEngineState (source, false ) 
         playerVehicle = getPedOccupiedVehicle ( source )                 
        if ( playerVehicle ) then                                        
        if ( getVehicleOverrideLights ( playerVehicle ) ~= 2 ) then  
        setVehicleOverrideLights ( playerVehicle, 2 )   
        setVehicleLocked ( source, false ) 
        setVehiclePlateText ( source, "Saruhan" ) 
        setVehicleDoorOpenRatio ( source, 0, 0, 0.5 ) 
        setVehicleDoorOpenRatio ( source, 1, 0, 0.5 ) 
        setVehicleDoorOpenRatio ( source, 2, 0, 0.5 ) 
        setVehicleDoorOpenRatio ( source, 3, 0, 0.5 ) 
        setVehicleDoorOpenRatio ( source, 4, 0, 0.5 ) 
        setVehicleDoorOpenRatio ( source, 5, 0, 0.5 ) 
        for i=1000,1193 do 
        removeVehicleUpgrade (source, i) 
             end 
          end 
         end 
      end 
   end 
 end 
) 

/debugscript 3

It's not give error or warning on debug.

And...

It's remove the upgrades for 1 times.

It's not work. :cry:

:cry:

Link to comment
  • 3 weeks later...

Up!

addEventHandler ( "onResourceStart", resourceRoot, function () 
    for _,veh in ipairs ( getElementsByType ( "vehicle" ) ) do 
        if not ( getElementData ( veh, "doNotRespawn" ) ) then 
            toggleVehicleRespawn  ( veh, true ) 
            setVehicleRespawnDelay ( veh, 10000 ) 
            setVehicleIdleRespawnDelay ( veh, 60000 ) 
            local r1, g1, b1, r2, g2, b2, r3, g3, b3, r4, g4, b4 = getVehicleColor ( veh ) 
            setVehicleColor ( veh, r1, g1, b1, r2, g2, b2, r3, g3, b3, r4, g4, b4 ) 
            setVehiclePlateText ( veh, "Saruhan" ) 
            setElementData ( veh, "vehPaintJob", getVehiclePaintjob ( veh ) ) 
            setElementData ( veh, "colorR1", r1 ) 
            setElementData ( veh, "colorR2", r2 ) 
            setElementData ( veh, "colorR3", r3 ) 
            setElementData ( veh, "colorR4", r4 ) 
            setElementData ( veh, "colorG1", g1 ) 
            setElementData ( veh, "colorG2", g2 ) 
            setElementData ( veh, "colorG3", g3 ) 
            setElementData ( veh, "colorG4", g4 ) 
            setElementData ( veh, "colorB1", b1 ) 
            setElementData ( veh, "colorB2", b2 ) 
            setElementData ( veh, "colorB3", b3 ) 
            setElementData ( veh, "colorB4", b4 ) 
            for k=1000,1193 do 
                if removeVehicleUpgrade(veh, k) then 
                    setElementData(veh, "upgrade"..k, true) 
                    addVehicleUpgrade(veh, k) 
                end 
            end 
        end 
    end 
end) 
  
function onExpRes() 
    if not ( getElementData ( source, "doNotRespawn" ) ) then 
        local vehPaintJob = getElementData ( source, "vehPaintJob" ) 
        local r1 = getElementData ( source, "colorR1" ) 
        local r2 = getElementData ( source, "colorR2" ) 
        local r3 = getElementData ( source, "colorR3" ) 
        local r4 = getElementData ( source, "colorR4" ) 
        local g1 = getElementData ( source, "colorG1" ) 
        local g2 = getElementData ( source, "colorG2" ) 
        local g3 = getElementData ( source, "colorG3" ) 
        local g4 = getElementData ( source, "colorG4" ) 
        local b1 = getElementData ( source, "colorB1" ) 
        local b2 = getElementData ( source, "colorB2" ) 
        local b3 = getElementData ( source, "colorB3" ) 
        local b4 = getElementData ( source, "colorB4" ) 
         
        setVehiclePaintjob ( source, vehPaintJob ) 
        setVehicleColor ( source, r1, g1, b1, r2, g2, b2, r3, g3, b3, r4, g4, b4 ) 
        setVehicleEngineState ( source, false ) 
        setVehicleOverrideLights ( source, 1 ) 
        setVehicleLocked ( source, false ) 
        setVehiclePlateText ( source, "Saruhan" ) 
        setVehicleDoorOpenRatio ( source, 0, 0, 0.5 ) 
        setVehicleDoorOpenRatio ( source, 1, 0, 0.5 ) 
        setVehicleDoorOpenRatio ( source, 2, 0, 0.5 ) 
        setVehicleDoorOpenRatio ( source, 3, 0, 0.5 ) 
        setVehicleDoorOpenRatio ( source, 4, 0, 0.5 ) 
        setVehicleDoorOpenRatio ( source, 5, 0, 0.5 ) 
        for k=1000,1193 do 
            removeVehicleUpgrade ( source, k ) 
            if getElementData(source, "upgrade"..k) then 
                addVehicleUpgrade(source, k) 
            end 
        end 
    end 
end 
addEventHandler ( "onVehicleRespawn", root, onExpRes ) 

1-) It's not give error or warning.

2-) Line 62 is not work.

3-) Line 50 is not set vehicle lights color.

4-) Line 52 is not work.

Where is the problem? :oops::oops::oops::oops::oops::oops::cry::cry::cry::cry::cry::cry::cry:

Link to comment

change

for k=1000,1193 do 
   removeVehicleUpgrade ( source, k ) 
   if getElementData(source, "upgrade"..k) then 
          addVehicleUpgrade(source, k) 
   end 
end 

to

for _,v in ipairs ( getVehicleUpgrades ( source ) ) do 
     removeVehicleUpgrade ( source, v ) 
end 

Link to comment
But r1-g1-b1 is work.
2-) Line 62 is not work.
        local r1 = getElementData ( source, "colorR1" ) 
        local r2 = getElementData ( source, "colorR2" ) 
        local r3 = getElementData ( source, "colorR3" ) 
        local r4 = getElementData ( source, "colorR4" ) 
        local g1 = getElementData ( source, "colorG1" ) 
        local g2 = getElementData ( source, "colorG2" ) 
        local g3 = getElementData ( source, "colorG3" ) 
        local g4 = getElementData ( source, "colorG4" ) 
        local b1 = getElementData ( source, "colorB1" ) 
        local b2 = getElementData ( source, "colorB2" ) 
        local b3 = getElementData ( source, "colorB3" ) 
        local b4 = getElementData ( source, "colorB4" ) 
        setVehicleColor ( source, r1, g1, b1, r2, g2, b2, r3, g3, b3, r4, g4, b4 ) --62 

Link to comment
change
for k=1000,1193 do 
   removeVehicleUpgrade ( source, k ) 
   if getElementData(source, "upgrade"..k) then 
          addVehicleUpgrade(source, k) 
   end 
end 

to

for _,v in ipairs ( getVehicleUpgrades ( source ) ) do 
     removeVehicleUpgrade ( source, v ) 
end 

I already test it but it's removed the upgrade for 1 times.

And MTA:Editor is set vehicle data color-upgrades-plate-paintjob-model. I use the this code for setVehicleColor:

local color = getElementData(source, "color") 
setVehicleColor(source, color) -- Line 448 

It's give this warning and isn't set color.

WARNING: Jack\task_s.lua:448: Bad usage @ 'setVehicleColor' [Incorrect number of color arguments] 

When the i add this code:

outputChatBox(color) -- It is say 0,0,0,245,245,245,0,0,0,0,0,0. 

So four color number.

Where is the my mistake?

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