Random selection help
#1

Hello, so I have a script that creates 42 random vehicles with no more than 3 duplicate vehicle types and no duplicate spawn locations. Here it is
Код:
new Float:RandomVehiclePos[][4] = //It never chooses a random selection from this more than once
{
	{6575.8643, 1275.2919, 20.0773, 270.0000},
	{6575.8643, 1229.8170, 20.0773, 270.0000},
	{6573.4219, 1181.0424, 20.0773, 0.0000},
	{6524.8511, 1175.6935, 20.0773, 270.0000},
	{6522.4009, 1182.7446, 20.0773, 0.0000},
	{6522.4053, 1321.1924, 20.0773, 180.0000},
	{6523.9053, 1328.1761, 20.0773, 270.0000},
	{6572.9219, 1323.7919, 20.0773, 180.0000},
	{6610.4575, 1252.5692, 20.0773, 270.0000},
	{6709.1646, 1252.5692, 20.0773, 90.0000},
	{6746.1880, 1229.7836, 20.0773, 90.0000},
	{6746.1177, 1275.2919, 20.0773, 90.0000},
	{6748.4956, 1323.7919, 20.0773, 180.0000},
	{6745.1680, 1176.7889, 20.0773, 0.0000},
	{6727.2222, 1265.2106, 11.1762, 90.0000},
	{6738.1187, 1262.2106, 11.1762, 270.0000},
	{6738.1187, 1242.9066, 11.1762, 270.0000},
	{6727.2222, 1239.9591, 11.1762, 90.0000},
	{6586.0640, 1242.9176, 11.1762, 90.0000},
	{6586.0640, 1262.2106, 11.1762, 90.0000},
	{6596.8091, 1265.1105, 11.1762, 270.0000},
	{6596.8091, 1239.9432, 11.1762, 270.0000},
	{6793.5283, 1328.1935, 20.0773, 90.0000},
	{6800.0322, 1321.4069, 20.0773, 180.0000},
	{6800.0322, 1183.0076, 20.0773, 0.0000},
	{6795.3564, 1175.6935, 20.0773, 90.0000},
	{6790.6738, 1309.3260, 2.8972, 180.0000},
	{6790.6738, 1198.8260, 3.3972, 0.0000},
	{6777.3657, 1194.4376, 3.3972, 90.0000},
	{6776.6221, 1310.5172, 2.8972, 90.0000},
	{6531.6934, 1307.0502, 2.8972, 180.0000},
	{6544.0459, 1310.5172, 2.8972, 270.0000},
	{6531.6934, 1198.5461, 2.8972, 0.0000},
	{6544.2046, 1194.5643, 2.8972, 270.0000}
};
Код:
new RandomVehicleId[][1] = //It never chooses a random selection from this more than three times
{
	{400},
	{401},
	{402},
	{411},
	{415},
	{422},
	{424},
	{434},
	{451},
	{470},
	{489},
	{495},
	{551},
	{556},
	{568},
	{573},
	{565}
};
Код:
for(new i = 0; i < sizeof(RandomVehiclePos); i++)
					{
						selectrand: new id = random(sizeof(RandomVehicleId));
						new rand = RandomVehicleId[id][0];
						if(rand == RandomVehicleId[id][0]) CarMaxSpawn[id]++;
						if(CarMaxSpawn[id] > 3) goto selectrand;
						CreateVehicle(rand, RandomVehiclePos[i][0], RandomVehiclePos[i][1], RandomVehiclePos[i][2], RandomVehiclePos[i][3], -1, -1, -1);
                                       }
Now that is all the code for spawning all the vehicles, but I would like it to create a certain number of vehicles. RandomVehiclePos has 34 sets of coords in it, I want to be able to control how many cars it spawns, so in other words I want it to choose (example) only 12 of the sets of coords in RandomVehiclePos. But I want the (example) 12 to be held in a variable. I hope I made it clear to you
Reply
#2

I don't sure but try this... Maybe this can work!

pawn Код:
new randomspawn = random(sizeof(RandomVehiclePos));
rand = random(sizeof(RandomVehicleId));
CreateVehicle(rand,RandomVehiclePos[randomspawn][0],RandomVehiclePos[randomspawn][1],RandomVehiclePos[randomspawn][2],RandomVehiclePos[randomspawn][3],-1,-1,15);
Reply
#3

Doesn't work at all, and what I am seeing it does nothing of what I am asking for, I am looking to keep my current code or modify it slightly to change the amount of randoms it pics from RandomVehiclePos.
Reply
#4

I have been thinking, I don't even think it is possible, is it?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)