Random Car Models at selected spawns
#1

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

pawn Код:
211 // car model
and

pawn Код:
206 // car model
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
Reply
#2

Edit.. Misread
Reply
#3

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;
}
Reply
#4

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}
};
Reply
#5

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}
;
Reply
#6

Still the same error

pawn Код:
new RandomModels[] =
{
    {400, 407, 402, 406, 610, 542}
;
Reply
#7

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.
Reply
#8

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?)
Reply
#9

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.
Reply
#10

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++)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)