battle309 Posted September 20, 2012 Share Posted September 20, 2012 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
DiSaMe Posted September 20, 2012 Share Posted September 20, 2012 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
Entity Posted September 20, 2012 Share Posted September 20, 2012 (edited) 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 September 20, 2012 by Guest Link to comment
DiSaMe Posted September 20, 2012 Share Posted September 20, 2012 Entity, your script is incorrect. 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