SkullBreaker Posted February 22, 2015 Share Posted February 22, 2015 (edited) 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: Edited February 23, 2015 by Guest Link to comment
MIKI785 Posted February 22, 2015 Share Posted February 22, 2015 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
nxFairlywell Posted February 23, 2015 Share Posted February 23, 2015 (edited) 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 February 23, 2015 by Guest Link to comment
JR10 Posted February 23, 2015 Share Posted February 23, 2015 Try this code With your code, only the first player who hits the marker will have a car, the others won't. Link to comment
LaCosTa Posted February 23, 2015 Share Posted February 23, 2015 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
SkullBreaker Posted February 23, 2015 Author Share Posted February 23, 2015 Hmm I'll try those out today! Thanks for your help guys! Link to comment
SkullBreaker Posted February 23, 2015 Author Share Posted February 23, 2015 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
TAPL Posted February 23, 2015 Share Posted February 23, 2015 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now