Jump to content

Scripting Vehicles Spawns


Cyan

Recommended Posts

Posted

I need help with Scripting Vehicles Spawns. It should be like: When player goes in a marker to automaticaly get in the vehicle specified in the script. If someone can help me please post it here.

Posted

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) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
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)

My in game nick is Lemonade

Posted

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?

Business System viewtopic.php?f=108&t=35797

Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726

SQLite Tutorial viewtopic.php?f=148&t=38203

Posted

It works fine now but...I have a jobs system I create it when it is running and go to that marker you spawn as a job and when you desactivate it you can spawn a car..so what I do?

Posted

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.

Business System viewtopic.php?f=108&t=35797

Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726

SQLite Tutorial viewtopic.php?f=148&t=38203

Posted

When someone spawn a vehicle he can spawn another, and another how can i solve this bug? Players will spam with vehicles...

Posted (edited)
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

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

SolidSake, Just gunna add this... :)

Error on line 23... warpPedIntoVehicle BadArgument...

Thought id identify this to save others doing it :)

Founder of SAUR - Founder/Owner of ARC RPG

Posted

Lol, my bad, fixed.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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