Jump to content

Hi could someone help me with my script


battle309

Recommended Posts

this is my code i want to make random cars on spawn

function getCar ( thePlayer ) 
    local randomveh = [411], [602], [496], [491] 
    local RacerPed = createPed ( 252, 0, 0, 3 ) 
    local RaceVehicle = createVehicle (randomveh) 
    warpPedIntoVehicle ( RacerPed, RaceVehicle )    
end 
addEventHandler ( "onPlayerSpawn", getRootElement(), getcar ) 

Link to comment

First, the line with "local randomveh" is incorrect. If you want to get a random value from multiple possible values, the easiest way would be this:

local randomveh = ({411, 602, 496, 491})[math.random(4)] 

A table gets created, a random index from 1 to 4 is chosen and value under that index is taken from the table.

Second, you call createVehicle incorrectly. It must have position arguments specified. I guess you need it to be created in the same position as the ped, so it should look like this:

local RaceVehicle = createVehicle (randomveh, 0, 0, 3) 

And third, thePlayer parameter of getCar function is actually an X position where player spawns. Instead, player element is stored in 'source' variable.

Link to comment
function getCar ( thePlayer ) 
    local randomveh = ({411, 602, 496, 491})[math.random(4)] 
    local RacerPed = createPed ( 252, 0, 0, 3 ) 
    local RaceVehicle = createVehicle (randomveh, 0, 0, 3) 
    warpPedIntoVehicle ( RacerPed, RaceVehicle )   
end 
addEventHandler ( "onPlayerSpawn", getRootElement(), getcar ) 

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