Jump to content

[Help] Simple vehicle spawn *SOLVED*


SkullBreaker

Recommended Posts

Hi! I would like to learn how to make a simple vehicle spawner. I tried to make a marker, and if the player enters the marker, it will spawn a policecar and warp the player in the car. Also, I tried to script that if the player already is in a vehicle, nothing happens, but it does not work like I want it to... This is the script and a screenshot of what happens if a player enters.

local marker = createMarker(1567.3, -1609.7, 12.6, "cylinder", 2, 53, 53, 255, 255) 
  
function spawn(player) 
    if isPedInVehicle (player) then 
        outputChatBox ("You already are in a vehicle!") 
    else  
        local car1 = createVehicle(596, 1567.4, -1610.5, 14, 0, 0, 180) 
        warpPedIntoVehicle(player, car1) 
    end 
end 
addEventHandler("onMarkerHit", marker, spawn) 

and some screenshots:

tumblr_nk74x6nLCJ1tt245uo3_1280.png

tumblr_nk74x6nLCJ1tt245uo1_1280.png

tumblr_nk74x6nLCJ1tt245uo2_1280.png

Edited by Guest
Link to comment

That's because onMarkerHit triggers for any element, including vehicles.

Try this:

  
local marker = createMarker(1567.3, -1609.7, 12.6, "cylinder", 2, 53, 53, 255, 255) 
  
function spawn(player) 
    if getElementType(player) ~= "player" then return end 
    if isPedInVehicle (player) then 
        outputChatBox ("You already are in a vehicle!") 
    else 
        local car1 = createVehicle(596, 1567.4, -1610.5, 14, 0, 0, 180) 
        warpPedIntoVehicle(player, car1) 
    end 
end 
addEventHandler("onMarkerHit", marker, spawn) 

Link to comment
local marker = createMarker(1567.3, -1609.7,12.6, "cylinder", 2, 53, 53, 255, 255)  
function spawn(player)  
   if not ( isElement( car1 ) and getElementType(player) == "player" ) then 
        if isPedInVehicle (player) then 
             outputChatBox ("You already are in a vehicle!")  
       else   
            local car1 = createVehicle(596,1567.4, -1610.5, 14, 0, 0, 180)                 
            warpPedIntoVehicle(player, car1)  
       end 
    else return end 
end 
addEventHandler("onMarkerHit", marker, spawn) 

Try this code ( server side )

Edited by Guest
Link to comment

try this , not tested but it might work

  
car = {} 
local marker = createMarker(1567.3, -1609.7, 12.6, "cylinder", 2, 53, 53, 255, 255) 
  
function spawn(player) 
    if isElement(car[player]) then destroyElement(car[player]) return end  
    if getElementType(player) == "player" and not isPedInVehicle (player) then 
        car[player] = createVehicle(596, 1567.4, -1610.5, 14, 0, 0, 180) 
        warpPedIntoVehicle(player, car[player]) 
    end 
end 
addEventHandler("onMarkerHit", marker, spawn) 

Link to comment

It worked! thanks! This is my script now:

local marker = createMarker(1567.3, -1609.7, 12.6, "cylinder", 2, 53, 53, 255, 255) 
  
function spawn(player) 
    if  getElementType(player) ~="player" then return end 
    if isPedInVehicle (player) then 
        outputChatBox ("You already are in a vehicle!") 
    else  
        local car1 = createVehicle(596, 1567.4, -1610.5, 14, 0, 0, 180) 
        warpPedIntoVehicle(player, car1) 
    end 
end 
addEventHandler("onMarkerHit", marker, spawn) 

Link to comment
car = {} 
local marker = createMarker(1567.3, -1609.7, 12.6, "cylinder", 2, 53, 53, 255, 255) 
  
function spawn(player) 
    if getElementType(player) == "player" then 
        if not isPedInVehicle(player) then 
            if isElement(car[player]) then destroyElement(car[player]) car[player] = nil end 
            car[player] = createVehicle(596, 1567.4, -1610.5, 14, 0, 0, 180) 
            warpPedIntoVehicle(player, car[player]) 
        else 
            outputChatBox("You already are in a vehicle!", player) 
        end 
    end 
end 
addEventHandler("onMarkerHit", marker, spawn) 

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