How to spawn a vehicle in a random position?
#1

HiHo, could anyone tell me how to make a vehicle spawn randomly in one of the given coordinates?
Reply
#2

you can do it like this
pawn Код:
//some random positions..u can keep adding more
new Float:RandomSpawn[][4] =
{
    // Positions, (X, Y, Z and Facing Angle)
    {-2796.9854, 1224.8180, 20.5429, 192.0335},
    {-2454.2170, 503.8759, 30.0790, 267.2932},
    {-2669.7322, -6.0874, 6.1328, 89.8853}
};
//now under ongamemodeinit
new rand = Random(sizeof(RandomSpawn));
CreateVehicle(510/*i m adding a hydra, change it*/, RandomSpawn[rand][0], RandomSpawn[rand][1], RandomSpawn[rand][2], RandomSpawn[rand][3], 0, 1, 60);
Reply
#3

Spawn a Car in Game use then /save goto your GTA San Andreas User Files Folder, and copy the X, Y and Z coordinate, and paste it in the script with "AddStaticVehicle". Maybe i understand that false, so make that what [HK]Ryder[AN] says.
Reply
#4

Quote:
Originally Posted by Blackazur
Посмотреть сообщение
Spawn a Car in Game use then /save goto your GTA San Andreas User Files Folder, and copy the X, Y and Z coordinate, and paste it in the script with "AddStaticVehicle".
he wants to make it at a RANDOM location..learn to read


EDIT - Just saw your edit..
Reply
#5

Quote:
Originally Posted by [HK]Ryder[AN]
Посмотреть сообщение
you can do it like this
pawn Код:
//some random positions..u can keep adding more
new Float:RandomSpawn[][4] =
{
    // Positions, (X, Y, Z and Facing Angle)
    {-2796.9854, 1224.8180, 20.5429, 192.0335},
    {-2454.2170, 503.8759, 30.0790, 267.2932},
    {-2669.7322, -6.0874, 6.1328, 89.8853}
};
//now under ongamemodeinit
new rand = Random(sizeof(RandomSpawn));
CreateVehicle(510/*i m adding a hydra, change it*/, RandomSpawn[rand][0], RandomSpawn[rand][1], RandomSpawn[rand][2], RandomSpawn[rand][3], 0, 1, 60);
I place the new rand... on the top of my gamemode.

I create a vehicle by using your line in one of the GUI dialogs and I get these errors for new rand...

Код:
error 012: invalid function call, not a valid address
error 008: must be a constant expression; assumed zero
Reply
#6

Bumpsy
Reply
#7

Who said you to make on top of the GamemodeInit ?? Do like this

pawn Код:
new Float:RandomSpawn[][4] =
{
    // Positions, (X, Y, Z and Facing Angle)
    {-2796.9854, 1224.8180, 20.5429, 192.0335},
    {-2454.2170, 503.8759, 30.0790, 267.2932},
    {-2669.7322, -6.0874, 6.1328, 89.8853}
};

public OnGameModeInit()
{
   new rand = Random(sizeof(RandomSpawn));
   CreateVehicle(510, RandomSpawn[rand][0], RandomSpawn[rand][1], RandomSpawn[rand][2], RandomSpawn[rand][3], 0, 1,1000);
   return 1;
}
Reply
#8

I get this when I place new rand = random(sizeof(RandomSpawn)); under OnDialogResponse (I place it there, because that's where my car shop is).

Код:
error 012: invalid function call, not a valid address
error 001: expected token: ";", but found "sizeof"
warning 215: expression has no effect
error 001: expected token: ";", but found ")"
fatal error 107: too many error messages on one line
Reply
#9

Might be the 'random' it shouldn't have a capital.
Reply
#10

Quote:
Originally Posted by -Luis
Посмотреть сообщение
Might be the 'random' it shouldn't have a capital.
It works now, lol
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)