Jump to content

[Help] Set Random Spawn for Vehicle


AlexWo

Recommended Posts

Hello, I played once on a Server and there was a script called "Mistery Van".

The script spawns a vehicle on Random Locations. If you enter the Van it dissapears and you get some money, armor and so on...

function spawnVan () 
misteryvan = createVehicle (482, x,y,z ) 
end 
addEventHandler ( "onResourceStart", getRootElement(), spawnVan ) 
  
function givestuff (thePlayer) 
givePlayerMoney(thePlayer, 5000) 
setPedArmor( thePlayer, 50) 
setPedHealth( thePlayer, 100) 
end 
  
addEventHandler ( "onPlayerVehicleEnter", root, givestuff ) 
  
  

Thats the script I got for now.

I don't know how to set 10 various locations for the van, and how to make it random.

Thank you for helping me :)

Link to comment

This is an example, how you can get one set of random coordinates from a table:

local locations = { 
    { 1, 4, 10 }, 
    { 33, 45, 10 }, 
    { 21, 4, 10 }, 
    { 4, 11, 30 } 
} 
  
function spawnVan () 
    local x, y, z = unpack ( locations [ math.random ( 1, #locations ) ] ) 
    misteryvan = createVehicle (482, x, y, z ) 
end 

Link to comment

Ok it works.... I changed the script to

local locations = { 
    { 1876, -1377, 13 }, 
    { 1921, -1792, 13 }, 
    { 2000, -2041, 13 } 
} 
  
function spawnVan () 
    local x, y, z = unpack ( locations [ math.random ( 1, #locations ) ] ) 
    misteryvan = createVehicle (482, x, y, z ) 
    blip = createBlipAttachedTo ( misteryvan, 37 ) 
end 
addEventHandler ( "onResourceStart", getRootElement(), spawnVan ) 
  
function givestuff (thePlayer) 
if isPedInVehicle ( thePlayer ) then 
destroyElement ( misteryvan ) 
    end 
end 
  
addEventHandler ( "onPlayerVehicleEnter", root, givestuff ) 
  

but if I enter I don't get the money... I think the "thePlayer" is not matched correctly

Link to comment

The first argument returned by the onPlayerVehicleEnter event is the vehicle. Source is the player.

And it wont give money if there isn't a function wich gives money. :)

function givestuff ( theVehicle ) 
    if theVehicle == misteryvan then 
        givePlayerMoney ( source, 100 ) 
        destroyElement ( misteryvan ) 
    end 
end 
  
addEventHandler ( "onPlayerVehicleEnter", root, givestuff ) 

Link to comment
The first argument returned by the onPlayerVehicleEnter event is the vehicle. Source is the player.

And it wont give money if there isn't a function wich gives money. :)

function givestuff ( theVehicle ) 
    if theVehicle == misteryvan then 
        givePlayerMoney ( source, 100 ) 
        destroyElement ( misteryvan ) 
    end 
end 
  
addEventHandler ( "onPlayerVehicleEnter", root, givestuff ) 

This should work, try it.

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