[HELP]Random Vehicle type.
#1

I was wondering how I would code a specific place for a Vehicle to spawn, but the Vehicle ID / type changes every server restart or spawn. Whatever is easier to do.
Reply
#2

pawn Код:
//top of script
new Float:gCarIDS[2][1] = {//change the 2 to how many different IDs you are using
{500},//car ids
{411}
};

//OnGameModeInIt
rand = random(sizeof(gCarIDS));
AddStaticVehicle(gCarIDS[rand][0], X, Y, Z, Angle, Colour1, Colour2);
Try that, it should work i think

Reply
#3

Quote:
Originally Posted by Gappy
pawn Код:
//top of script
new Float:gCarIDS[2][1] = {//change the 2 to how many different IDs you are using
{500},//car ids
{411}
};

//OnGameModeInIt
rand = random(sizeof(gCarIDS));
AddStaticVehicle(gCarIDS[rand][0], X, Y, Z, Angle, Colour1, Colour2);
Try that, it should work i think

77-93:
pawn Код:
{408},
{461},
{477},
{554},
{467},
{474},
{439},
{438},
{402},
{400},
{419},
{602},
{496},
{549},
{507},
{466},
{542}
185-198:
pawn Код:
rand = random(sizeof(gCarIDS));
    AddStaticVehicle(gCarIDS[rand][0], 1426.7671,-1088.7125,18.1073,179.1871,26,26);

    AddPlayerClass(68,813.5023,-1627.5933,13.5391,178.8821,0,0,0,0,0,0);
  AddStaticVehicle(gCarIDS[rand][0], 782.2957,-1630.1776,12.9648,89.5466,53,1);
  AddStaticVehicle(gCarIDS[rand][0], 782.5749,-1605.2919,13.1359,269.9319,22,1);
  AddStaticVehicle(gCarIDS[rand][0], 782.9958,-1619.5582,13.4651,269.7807,65,32);
  AddStaticVehicle(gCarIDS[rand][0], 852.1212,-1607.0485,13.2052,314.3545,2,1);
  AddStaticVehicle(gCarIDS[rand][0], 686.6292,-1570.5701,14.0047,1.5634,91,1);
  AddStaticVehicle(gCarIDS[rand][0], 815.0048,-1499.5597,13.1316,178.9463,37,78);
  AddStaticVehicle(gCarIDS[rand][0], 822.7211,-1390.1864,13.5390,271.5528,6,76);
  AddStaticVehicle(gCarIDS[rand][0], 853.0086,-1369.8126,13.5183,359.6465,39,39);
  AddStaticVehicle(gCarIDS[rand][0], 893.9571,-1520.1537,13.4012,177.3452,62,1);
  AddStaticVehicle(gCarIDS[rand][0], 888.0528,-1657.9349,13.3443,359.9665,45,75);
ERRORS:

Код:
C:\Users\Madhouse\Desktop\Server\gamemodes\MA.pwn(77) : warning 213: tag mismatch
C:\Users\Madhouse\Desktop\Server\gamemodes\MA.pwn(78) : warning 213: tag mismatch
C:\Users\Madhouse\Desktop\Server\gamemodes\MA.pwn(79) : warning 213: tag mismatch
C:\Users\Madhouse\Desktop\Server\gamemodes\MA.pwn(80) : warning 213: tag mismatch
C:\Users\Madhouse\Desktop\Server\gamemodes\MA.pwn(81) : warning 213: tag mismatch
C:\Users\Madhouse\Desktop\Server\gamemodes\MA.pwn(82) : warning 213: tag mismatch
C:\Users\Madhouse\Desktop\Server\gamemodes\MA.pwn(83) : warning 213: tag mismatch
C:\Users\Madhouse\Desktop\Server\gamemodes\MA.pwn(84) : warning 213: tag mismatch
C:\Users\Madhouse\Desktop\Server\gamemodes\MA.pwn(85) : warning 213: tag mismatch
C:\Users\Madhouse\Desktop\Server\gamemodes\MA.pwn(86) : warning 213: tag mismatch
C:\Users\Madhouse\Desktop\Server\gamemodes\MA.pwn(87) : warning 213: tag mismatch
C:\Users\Madhouse\Desktop\Server\gamemodes\MA.pwn(88) : warning 213: tag mismatch
C:\Users\Madhouse\Desktop\Server\gamemodes\MA.pwn(89) : warning 213: tag mismatch
C:\Users\Madhouse\Desktop\Server\gamemodes\MA.pwn(90) : warning 213: tag mismatch
C:\Users\Madhouse\Desktop\Server\gamemodes\MA.pwn(91) : warning 213: tag mismatch
C:\Users\Madhouse\Desktop\Server\gamemodes\MA.pwn(92) : warning 213: tag mismatch
C:\Users\Madhouse\Desktop\Server\gamemodes\MA.pwn(93) : warning 213: tag mismatch
C:\Users\Madhouse\Desktop\Server\gamemodes\MA.pwn(185) : error 017: undefined symbol "rand"
C:\Users\Madhouse\Desktop\Server\gamemodes\MA.pwn(186) : error 017: undefined symbol "rand"
C:\Users\Madhouse\Desktop\Server\gamemodes\MA.pwn(189) : error 017: undefined symbol "rand"
C:\Users\Madhouse\Desktop\Server\gamemodes\MA.pwn(190) : error 017: undefined symbol "rand"
C:\Users\Madhouse\Desktop\Server\gamemodes\MA.pwn(191) : error 017: undefined symbol "rand"
C:\Users\Madhouse\Desktop\Server\gamemodes\MA.pwn(192) : error 017: undefined symbol "rand"
C:\Users\Madhouse\Desktop\Server\gamemodes\MA.pwn(193) : error 017: undefined symbol "rand"
C:\Users\Madhouse\Desktop\Server\gamemodes\MA.pwn(194) : error 017: undefined symbol "rand"
C:\Users\Madhouse\Desktop\Server\gamemodes\MA.pwn(195) : error 017: undefined symbol "rand"
C:\Users\Madhouse\Desktop\Server\gamemodes\MA.pwn(196) : error 017: undefined symbol "rand"
C:\Users\Madhouse\Desktop\Server\gamemodes\MA.pwn(197) : error 017: undefined symbol "rand"
C:\Users\Madhouse\Desktop\Server\gamemodes\MA.pwn(198) : error 017: undefined symbol "rand"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


12 Errors.
Reply
#4

Well i forgot new lol. I tried it myself but its not working, ive never tried this before so i duno.
Reply
#5

pawn Код:
new CarIDs[2][1]={ //change the 2 to how many different IDs you are using
{500},
{411} //always leave the last without the ,
};
//OnGameModeInit
new rand = random(sizeof(CarIDs));
AddStaticVehicle(CarIDs[rand][0], X, Y, Z, Angle, Colour1, Colour2);
you only have to use float:... if its a coordinate but here its just a number Hope it helps
Reply
#6

I give up. I really don't think I'm capable of this, I would seriously get way too stressed out. For now, I'll develop the base of the script & upgrade as we move along.
Reply
#7

new float:X
new float:Y
new float:Z
new float:Angle
Reply
#8

It's pretty easy, I suppose I'll go ahead and make a script that randomizes vehicles after they spawn
pawn Код:
//At the top of your FS or GM

new Float:RandVehicles[3][4]; //X,Y,Z,A -- change [x] to the amount of random vehicles you have
new RandVehicleID[3]; // Change[x] to be the same as the previous one
new RandVAmount;

new RandVehicleModels[3] = { //Change [x] to be the amount of models you have
400,
401, //Vehicle models, all but last one has a ','
402
};

CreateRandomVehicle(Float:X,Float:Y,Float:Z,Float:A,ID)
{
  new tmp;
  if(ID==-1)tmp=RandVAmount; else tmp = ID;
  RandVehicles[tmp][0]=X;
  RandVehicles[tmp][1]=Y;
  RandVehicles[tmp][2]=Z;
  RandVehicles[tmp][3]=A;
  new rand=random(sizeof(RandVehicleModels));
  RandVehicleID[tmp]=CreateVehicle(RandVehicleModels[rand],X,Y,Z,A,-1,-1,60000);
  if(ID==-1)RandVAmount++;
}

//Inside of OnGameModeInit or OnFilterScriptInit
public OnFilterScriptInit()
{
  CreateRandomVehicle(100,100,100,100,-1); //-1 means the vehicle is new
  CreateRandomVehicle(100,100,100,100,-1); //-1 means the vehicle is new
  CreateRandomVehicle(100,100,100,100,-1); //-1 means the vehicle is new
}

//Inside of OnVehicleSpawn
public OnVehicleSpawn(vehicleid)
{
  for(new o; o<RandVAmount; o++)
  {
    if(vehicleid==RandVehicleID[o])
    {
      DestroyVehicle(RandVehicleID[o]);
      CreateRandomVehicle(RandVehicles[o][0],RandVehicles[o][1],RandVehicles[o][2],RandVehicles[o][3],o);
      break;
    }
  }
}
EDIT*Just tested it, works fine now.

EDIT** I actually really like that lol, hope someone makes good use of it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)