PDA

View Full Version : [Help]Car Spawning


DrSega69
23/12/2011, 08:06 AM
Hello everybody, i need help with car spawning.

i have the coords for where i want my cars but, i want the cars to be random so that whenever i start my server or the car gets destroyed it will be different.

What would i have to edit from this?

AddStaticVehicle(451,1765.4220,210.0302,25.6966,31 5.0654,125,125); //

Pls help, i have seen this on some servers.

park4bmx
23/12/2011, 08:15 AM
i think your looking for OnVehicleSpawn (http://wiki.sa-mp.com/wiki/OnVehicleSpawn)
it will get called when the vehicle respawns so all you have to do is save the vehicleid and then check it under OnVehicleSpawn

Ash.
23/12/2011, 08:17 AM
For it to have a random vehicle model (is what assume you mean), you'll just need to get a random number inbetween (and including) 400 and 611.

You will need the following function (or a variation of it):
stock RandomBetween(min, max)
{
return random(max - min) + min;
}

Then when you want to add a randomly chosen vehicle model, replace the "model" parameter of AddStaticVehicle (or CreateVehicle, CreateVehicleEx, AddStaticVehicleEx) with: RandomBetween(400, 611)

400 is the lowest possible vehicle model, and 611 is the highest.

DrSega69
23/12/2011, 08:19 AM
i think your looking for OnVehicleSpawn (http://wiki.sa-mp.com/wiki/OnVehicleSpawn)
it will get called when the vehicle respawns so all you have to do is save the vehicleid and then check it under OnVehicleSpawn

Is this how u would put it in ur script?

public OnVehicleSpawn(vehicleid)
{
AddStaticVehicle(1765.4220,210.0302,25.6966,315.06 54,125,125); //
return 1;
}


Im new at pawno :(

Ash.
23/12/2011, 08:22 AM
Is this how u would put it in ur script?

public OnVehicleSpawn(vehicleid)
{
AddStaticVehicle(1765.4220,210.0302,25.6966,315.06 54,125,125); //
return 1;
}


Im new at pawno :(

Using that script would just end up duplicating a vehicle everytime one respawns, which isn't good.

Do you want the vehicle models to be random? I mean do you want the models (vehicles) to change? If so, read my original post (above yours).

DrSega69
23/12/2011, 08:25 AM
Using that script would just end up duplicating a vehicle everytime one respawns, which isn't good.

Do you want the vehicle models to be random? I mean do you want the models (vehicles) to change? If so, read my original post (above yours).

Well, i want the car that spawn say the 1st time its a turismo then when server restarts or the vehicle is destroyed maybe a bullet or a random car.

park4bmx
23/12/2011, 08:27 AM
Well, i want the car that spawn say the 1st time its a turismo then when server restarts or the vehicle is destroyed maybe a bullet or a random car.

yes in that case you will need to get the random id like funky showed you but you will have to destroy your current vehicle (if you wish)

DrSega69
23/12/2011, 08:29 AM
Ok THANK YOU SO MUCH FUNKY, when i 1st read ur 1st reply that u sent i was confused.
i tested it and it worked! THANK YOU SO MUCH!

How do i give rep or what is it called?

DrSega69
23/12/2011, 08:51 AM
Found it! :D +1