Jump to content

SPAWN VEHICLE [FIXED]


bosslorenz

Recommended Posts

I have script spawn vehicle but it only spawns 1 vehicle for all players. What I want is to spawn vehicle for every ACCOUNT and GUEST

local marker = createMarker( 1920.599609375, 1310.099609375,8, "cylinder", 2, 0 ,0, 255, 155)

function vehicle(thePlayer)

if getElementType(thePlayer) == "player" then

if isPedInVehicle(thePlayer)==true then return end

if isElement( veh ) then destroyElement( veh ) end

local x,y,z = getElementPosition(thePlayer)

veh = createVehicle(470, 1921.599609375, 1298.599609375, 9.3999996185303, 0, 0, 270)

outputChatBox ( "This is a free vehicle. Spawning another one will destroy this vehicle.", thePlayer, 0, 0, 255 )

warpPedIntoVehicle(thePlayer, veh)

end

end

addEventHandler("onMarkerHit", marker, vehicle)

Edited by Guest
Link to comment

Don't see why you used getElementPosition when you're not gonna use it.

local theVehicle = {} 
local marker = createMarker( 1920.599609375, 1310.099609375,8, "cylinder", 2, 0 ,0, 255, 155) 
  
function vehicle(thePlayer) 
    if (getElementType(thePlayer) == "player") then 
        if ( isPedInVehicle(thePlayer) ) then return end 
        if isElement( theVehicle[thePlayer] ) then destroyElement( theVehicle[thePlayer] ) end 
        theVehicle[thePlayer] = createVehicle(470, 1921.599609375, 1298.599609375, 9.3999996185303, 0, 0, 270 ) 
        outputChatBox ( "This is a free vehicle. Spawning another one will destroy this vehicle.", thePlayer, 0, 0, 255 )    
        warpPedIntoVehicle(thePlayer, theVehicle[thePlayer]) 
    end 
end 
addEventHandler("onMarkerHit", marker, vehicle) 

Link to comment
Don't see why you used getElementPosition when you're not gonna use it.
local theVehicle = {} 
local marker = createMarker( 1920.599609375, 1310.099609375,8, "cylinder", 2, 0 ,0, 255, 155) 
  
function vehicle(thePlayer) 
    if (getElementType(thePlayer) == "player") then 
        if ( isPedInVehicle(thePlayer) ) then return end 
        if isElement( theVehicle[thePlayer] ) then destroyElement( theVehicle[thePlayer] ) end 
        theVehicle[thePlayer] = createVehicle(470, 1921.599609375, 1298.599609375, 9.3999996185303, 0, 0, 270 ) 
        outputChatBox ( "This is a free vehicle. Spawning another one will destroy this vehicle.", thePlayer, 0, 0, 255 )    
        warpPedIntoVehicle(thePlayer, theVehicle[thePlayer]) 
    end 
end 
addEventHandler("onMarkerHit", marker, vehicle) 

Still wont work, once I step into the marker, other players car vanishes

Link to comment
local theVehicle = {}local marker = createMarker( 1920.599609375, 1310.099609375,8, "cylinder", 2, 0 ,0,255, 155)function vehicle(thePlayer)    if (getElementType(thePlayer) == "player") then  if isElement( theVehicle[thePlayer] ) then destroyElement(theVehicle[thePlayer] ) end           if ( isPedInVehicle(thePlayer) ) then return end    theVehicle[thePlayer] = createVehicle(470, 1921.599609375, 1298.599609375,9.3999996185303, 0, 0, 270 )        outputChatBox ( "This is a free vehicle. Spawning another one will destroy this vehicle.", thePlayer, 0, 0, 255 )          warpPedIntoVehicle(thePlayer, theVehicle[thePlayer])    endendaddEventHandler("onMarkerHit", marker, vehicle) 
  
  

Link to comment
local theVehicle = {} 
local marker = createMarker( 1920.599609375, 1310.099609375,8, "cylinder", 2, 0 ,0, 255, 155) 
  
function vehicle(hitElement) 
    if (getElementType(hitElement) == "player") and not isPedInVehicle(hitElement) then 
     
        if isElement( theVehicle[hitElement] ) then destroyElement( theVehicle[hitElement] ) end 
        theVehicle[hitElement] = createVehicle(470, 1921.599609375, 1298.599609375, 9.3999996185303, 0, 0, 270 ) 
        outputChatBox ( "This is a free vehicle. Spawning another one will destroy this vehicle.", hitElement, 0, 0, 255 )   
        warpPedIntoVehicle(hitElement, theVehicle[hitElement]) 
    end 
end 
addEventHandler("onMarkerHit", marker, vehicle) 

Link to comment
local theVehicle = {} 
local marker = createMarker( 1920.599609375, 1310.099609375,8, "cylinder", 2, 0 ,0, 255, 155) 
  
function vehicle(hitElement) 
    if (getElementType(hitElement) == "player") and not isPedInVehicle(hitElement) then 
     
        if isElement( theVehicle[hitElement] ) then destroyElement( theVehicle[hitElement] ) end 
        theVehicle[hitElement] = createVehicle(470, 1921.599609375, 1298.599609375, 9.3999996185303, 0, 0, 270 ) 
        outputChatBox ( "This is a free vehicle. Spawning another one will destroy this vehicle.", hitElement, 0, 0, 255 )   
        warpPedIntoVehicle(hitElement, theVehicle[hitElement]) 
    end 
end 
addEventHandler("onMarkerHit", marker, vehicle) 

Its working now, but not destroyed after OnPlayerQuit,OnPlayerWasted and OnPlayerLogout

Link to comment

try this

local theVehicle = {} 
local marker = createMarker( 1920.599609375, 1310.099609375,8, "cylinder", 2, 0 ,0, 255, 155) 
  
function vehicle(hitElement) 
    if (getElementType(hitElement) == "player") and not isPedInVehicle(hitElement) then 
    
        if isElement( theVehicle[hitElement] ) then destroyElement( theVehicle[hitElement] ) end 
        theVehicle[hitElement] = createVehicle(470, 1921.599609375, 1298.599609375, 9.3999996185303, 0, 0, 270 ) 
        outputChatBox ( "This is a free vehicle. Spawning another one will destroy this vehicle.", hitElement, 0, 0, 255 )   
        warpPedIntoVehicle(hitElement, theVehicle[hitElement]) 
    end 
end 
addEventHandler("onMarkerHit", marker, vehicle) 
  
addEventHandler("onPlayerWasted",root,function() 
    if isElement( theVehicle[source]) then  
        destroyElement(theVehicle[source]) 
        theVehicle[source] = nil  
    end 
end ) 
  
addEventHandler("onPlayerQuit",root,function() 
    if isElement( theVehicle[source]) then  
        destroyElement(theVehicle[source]) 
        theVehicle[source] = nil  
    end 
end )  

Link to comment
try this
local theVehicle = {} 
local marker = createMarker( 1920.599609375, 1310.099609375,8, "cylinder", 2, 0 ,0, 255, 155) 
  
function vehicle(hitElement) 
    if (getElementType(hitElement) == "player") and not isPedInVehicle(hitElement) then 
    
        if isElement( theVehicle[hitElement] ) then destroyElement( theVehicle[hitElement] ) end 
        theVehicle[hitElement] = createVehicle(470, 1921.599609375, 1298.599609375, 9.3999996185303, 0, 0, 270 ) 
        outputChatBox ( "This is a free vehicle. Spawning another one will destroy this vehicle.", hitElement, 0, 0, 255 )   
        warpPedIntoVehicle(hitElement, theVehicle[hitElement]) 
    end 
end 
addEventHandler("onMarkerHit", marker, vehicle) 
  
addEventHandler("onPlayerWasted",root,function() 
    if isElement( theVehicle[source]) then  
        destroyElement(theVehicle[source]) 
        theVehicle[source] = nil  
    end 
end ) 
  
addEventHandler("onPlayerQuit",root,function() 
    if isElement( theVehicle[source]) then  
        destroyElement(theVehicle[source]) 
        theVehicle[source] = nil  
    end 
end )  

Very very helpful, now I got no bad argument anymore THANKS :0

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