Random Car Models at selected spawns -
FunnyBear - 13.04.2013
Hey guys,
I was wondering how you can make random car models at selected spawns. This is what I mean, the system picks a car spawn from an array, then there is another array which the system picks a car model from the ids put inside the array.
For example if I put
pawn Код:
9585.28444, 229.0996094,-1988.5000000
and
pawn Код:
9586.28756, 228.8000031,-1984.5999756
and in another array I put
and
How can I make the system chose a random spawn from one and a random car so they make up random car spawns.
Please help! Thanks
Re: Random Car Models at selected spawns -
Isolated - 13.04.2013
Edit.. Misread
Re: Random Car Models at selected spawns -
[XST]O_x - 13.04.2013
pawn Код:
new Float:arraySpawns[][] = {
{9585.28444, 229.0996094,-1988.5000000},
{X, Y, Z}
};
new arrayModels[] =
{400, 407, 402, 406, 610, 542}
;
public OnGameModeInit()
{
new randomPos= random(sizeof(arraySpawns));
new randomModel = random(sizeof(arrayModels));
CreateVehicle(arrayModels[randomModel], arraySpawns[randomPos][0], arraySpawns[randomPos][1], arraySpawns[randomPos][2], ANGLE, COL1, COL2, RESPAWNDELAY);
return 1;
}
Re: Random Car Models at selected spawns -
FunnyBear - 13.04.2013
Thanks, I knew it was something like that but I get
Код:
error 008: must be a constant expression; assumed zero
error line:
pawn Код:
{400, 407, 402, 406, 610, 542}
};
Re: Random Car Models at selected spawns -
[XST]O_x - 13.04.2013
Quote:
Originally Posted by FunnyBear
Thanks, I knew it was something like that but I get
Код:
error 008: must be a constant expression; assumed zero
error line:
pawn Код:
{400, 407, 402, 406, 610, 542} };
|
You've added extra brackets.
Remove them:
pawn Код:
{400, 407, 402, 406, 610, 542}
;
Re: Random Car Models at selected spawns -
FunnyBear - 13.04.2013
Still the same error
pawn Код:
new RandomModels[] =
{
{400, 407, 402, 406, 610, 542}
;
Re: Random Car Models at selected spawns -
[XST]O_x - 13.04.2013
Quote:
Originally Posted by FunnyBear
Still the same error
pawn Код:
new RandomModels[] = { {400, 407, 402, 406, 610, 542} ;
|
Why did you edit my code?
The code I gave you was:
pawn Код:
new arrayModels[] =
{400, 407, 402, 406, 610, 542}
;
You, for some reason, added extra brackets, like this:
pawn Код:
new arrayModels[] = {
{400, 407, 402, 406, 610, 542}
};
And that is what gives you the error.
Re: Random Car Models at selected spawns -
FunnyBear - 13.04.2013
Thanks it works, but I have two questions.
1. Will it only create 1 vehicle?
2. If I go in-game and go in a car and do /save at my selected location, and I put the x, y, z in the array. Will or can the car be out of order (maybe to big/small, maybe against a wall, or will it be fine?)
Re: Random Car Models at selected spawns -
[XST]O_x - 13.04.2013
1. Yep. To create more vehicles you can create a simple loop:
pawn Код:
public OnGameModeInit()
{
new randomPos, randomModel;
for(new i = 0; i < 3; i++) {
randomPos= random(sizeof(arraySpawns));
randomModel = random(sizeof(arrayModels));
CreateVehicle(arrayModels[randomModel], arraySpawns[randomPos][0], arraySpawns[randomPos][1], arraySpawns[randomPos][2], ANGLE, COL1, COL2, RESPAWNDELAY);
}
return 1;
}
2. It should be fine.
Re: Random Car Models at selected spawns -
FunnyBear - 13.04.2013
So if I want around 40 random vehicles
do I change
pawn Код:
for(new i = 0; i < 3; i++)
to
pawn Код:
for(new i = 0; i < 40; i++)