Jump to content

Scripting Vehicles Spawns


Cyan

Recommended Posts

So you want to make like: marker1 = vehicle Infernus? and so on?

If so, then use this.

markers = {} 
markers[1] = createMarker(-706, 966, 12, "cylinder", 1, 255, 255, 0, 200) 
markers[2] = createMarker(-709, 966, 12, "cylinder", 1, 255, 255, 0, 200) 
  
vehicles = { 
[1] = "411", 
[2] = "432" 
} 
  
function onMarkerHitGiveVehicle(hitPlayer,matchingDimension) 
for i,v in pairs(markers) do 
if (source == v) then 
if getElementType(hitPlayer) == "player" and matchingDimension then 
local x, y, z = getElementPosition(hitPlayer) 
vehicle = createVehicle(vehicles[i],x,y,z) 
warpPedIntoVehicle(hitPlayer,vehicle) 
         end 
      end 
   end 
end 
addEventHandler("onMarkerHit",getRootElement(),onMarkerHitGiveVehicle) 

Link to comment
markers = {} 
markers[1] = createMarker(-706, 966, 12, "cylinder", 1, 255, 255, 0, 200) 
markers[2] = createMarker(-709, 966, 12, "cylinder", 1, 255, 255, 0, 200) 
  
vehicles = { 
[1] = {"Civilian","411"}, 
[2] = {"Army","432"} 
} 
  
function onMarkerHitGiveVehicle(hitPlayer,matchingDimension) 
for i,v in pairs(markers) do 
if (source == v) then 
if getElementType(hitPlayer) == "player" and matchingDimension then 
local team = getPlayerTeam" class="kw2">getPlayerTeam(hitPlayer) 
if not team then return end 
local teamName = getTeamName(team) 
if vehicles[i][1] ~= teamName then return end 
local x, y, z = getElementPosition(hitPlayer) 
vehicle = createVehicle(vehicles[i][2],x,y,z) 
warpPedIntoVehicle(hitPlayer,vehicle) 
         end 
      end 
   end 
end 
addEventHandler("onMarkerHit",getRootElement(),onMarkerHitGiveVehicle) 

Btw, next time try something by yourself first.

Link to comment
Well Castillo it contains error in the line 14 says it have an infinte string...

Because it must be like this:

local team = getPlayerTeam(hitPlayer)

it's not Castillo's mistake. if you use [lua][/lua] it automatically turns it into:

local team = getPlayerTeam" class="kw2">getPlayerTeam(hitPlayer)

Link to comment

Because you just copy paste without looking -.-

If you really want to learn look at the code we give you, try to see what did you do wrong, this way you wont do it again.

Copy paste get you in a bad habit, and you won't learn anything.

Link to comment

Wow you deleted the whole line o.O

here it is -_-

markers = {} 
markers[1] = createMarker(-706, 966, 12, "cylinder", 1, 255, 255, 0, 200) 
markers[2] = createMarker(-709, 966, 12, "cylinder", 1, 255, 255, 0, 200) 
  
vehicles = { 
[1] = {"Civilian","411"}, 
[2] = {"Army","432"} 
} 
  
function onMarkerHitGiveVehicle(hitPlayer,matchingDimension) 
for i,v in pairs(markers) do 
if (source == v) then 
if getElementType(hitPlayer) == "player" and matchingDimension then 
local team = getPlayerTeam1(hitPlayer) 
if not team then return end 
local teamName = getTeamName(team) 
if vehicles[i][1] ~= teamName then return end 
local x, y, z = getElementPosition(hitPlayer) 
vehicle = createVehicle(vehicles[i][2],x,y,z) 
warpPedIntoVehicle(hitPlayer,vehicle) 
         end 
      end 
   end 
end 
addEventHandler("onMarkerHit",getRootElement(),onMarkerHitGiveVehicle) 

Remove 1 from getPlayerTeam can you do that yourself?

Link to comment

Only one way you add a handler to onResourceStart to create a marker that sets your team when you hit it,

And add a handler to onResourceStop that creates a marker in the same place and give you a car when you hit it.

Link to comment

You must use it from another script like this:

addEventHandler('onResourceStart', getResourceFromName('markerResource'), ...) 

and add onResourceStart and stop create a marker that sets your team when you hit it,

And add a handler to onResourceStop that changes the handler to a function that will spawn you a vehicle.

Link to comment
markers = {} 
markers[1] = createMarker(-706, 966, 12, "cylinder", 1, 255, 255, 0, 200) 
markers[2] = createMarker(-709, 966, 12, "cylinder", 1, 255, 255, 0, 200) 
  
vehicles = { 
[1] = {"Civilian","411"}, 
[2] = {"Army","432"} 
} 
  
playerVehicles = {} 
  
function onMarkerHitGiveVehicle(hitPlayer,matchingDimension) 
for i,v in pairs(markers) do 
if (source == v) then 
if getElementType(hitPlayer) == "player" and matchingDimension then 
local team = getPlayerTeam1(hitPlayer) 
if not team then return end 
local teamName = getTeamName(team) 
if vehicles[i][1] ~= teamName then return end 
local x, y, z = getElementPosition(hitPlayer) 
if isElement(playerVehicles[hitPlayer]) then destroyElement(playerVehicles[hitPlayer]) end 
playerVehicles[hitPlayer] = createVehicle(vehicles[i][2],x,y,z) 
warpPedIntoVehicle(hitPlayer,playerVehicles[hitPlayer]) 
         end 
      end 
   end 
end 
addEventHandler("onMarkerHit",getRootElement(),onMarkerHitGiveVehicle) 

Edited by Guest
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...