Random car spawn help please:D
#1

I need 32 cars to spawn in a line, I can do that, but I want it to be random. I am using this

pawn Код:
new RandomVehicleId[][1] =
{
    {400},
    {401},
    {402},
    {411},
    {415},
    {422},
    {424},
    {434},
    {451},
    {470},
    {489},
    {495},
    {551},
    {556},
    {568},
    {573},
    {565}
};
What it does is when I for example type test, it spawns the cars, but there's a problem, I have a list of 32 spawn locations and they all use this random list, and lets say it randomly chooses 551, all the cars will be ID 551. How do I make the random for each individual car, WITHOUT having to make another 31 of these scripts? I don't want too much memory usage. I myself am running on a soon to upgraded processor that is only 2.0GHZ SINGLE CORE <<<!!!!! Yea I know. So I want it to be memory and cpu usage effecient for other unfortunate players like me with old laptops (It's decent, Lenovo n200 3000). Please help
Reply
#2

Show us your current code.
Reply
#3

pawn Код:
CreateVehicle(RandomVehicleId[rand][0], 6575.8643, 1275.2919, 20.0773, 270.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6575.8643, 1229.8170, 20.0773, 270.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6573.4219, 1181.0424, 20.0773, 0.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6524.8511, 1175.6935, 20.0773, 270.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6522.4009, 1182.7446, 20.0773, 0.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6522.4053, 1321.1924, 20.0773, 180.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6523.9053, 1328.1761, 20.0773, 270.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6572.9219, 1323.7919, 20.0773, 180.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6610.4575, 1252.5692, 20.0773, 270.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6709.1646, 1252.5692, 20.0773, 90.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6746.1880, 1229.7836, 20.0773, 90.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6746.1177, 1275.2919, 20.0773, 90.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6748.4956, 1323.7919, 20.0773, 180.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6745.1680, 1176.7889, 20.0773, 0.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6727.2222, 1265.2106, 11.1762, 90.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6738.1187, 1262.2106, 11.1762, 270.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6738.1187, 1242.9066, 11.1762, 270.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6727.2222, 1239.9591, 11.1762, 90.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6586.0640, 1242.9176, 11.1762, 90.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6586.0640, 1262.2106, 11.1762, 90.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6596.8091, 1265.1105, 11.1762, 270.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6596.8091, 1239.9432, 11.1762, 270.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6793.5283, 1328.1935, 20.0773, 90.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6800.0322, 1321.4069, 20.0773, 180.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6800.0322, 1183.0076, 20.0773, 0.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6795.3564, 1175.6935, 20.0773, 90.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6790.6738, 1309.3260, 2.8972, 180.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6790.6738, 1198.8260, 3.3972, 0.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6777.3657, 1194.4376, 3.3972, 90.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6776.6221, 1310.5172, 2.8972, 90.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6531.6934, 1307.0502, 2.8972, 180.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6544.0459, 1310.5172, 2.8972, 270.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6531.6934, 1198.5461, 2.8972, 0.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6544.2046, 1194.5643, 2.8972, 270.0000, -1, -1, 100);
Thats my current code
Reply
#4

have you defined what rand is? show us that code too
Reply
#5

pawn Код:
new RandomVehicleId[][1] =
{
    {400},
    {401},
    {402},
    {411},
    {415},
    {422},
    {424},
    {434},
    {451},
    {470},
    {489},
    {495},
    {551},
    {556},
    {568},
    {573},
    {565}
};
There. Also what I did now was this
pawn Код:
forward Spawn();
public Spawn();
{
new rand = random(sizeof(RandomVehicleId));
CreateVehicle(RandomVehicleId[rand][0], 6575.8643, 1275.2919, 20.0773, 270.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6575.8643, 1229.8170, 20.0773, 270.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6573.4219, 1181.0424, 20.0773, 0.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6524.8511, 1175.6935, 20.0773, 270.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6522.4009, 1182.7446, 20.0773, 0.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6522.4053, 1321.1924, 20.0773, 180.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6523.9053, 1328.1761, 20.0773, 270.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6572.9219, 1323.7919, 20.0773, 180.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6610.4575, 1252.5692, 20.0773, 270.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6709.1646, 1252.5692, 20.0773, 90.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6746.1880, 1229.7836, 20.0773, 90.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6746.1177, 1275.2919, 20.0773, 90.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6748.4956, 1323.7919, 20.0773, 180.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6745.1680, 1176.7889, 20.0773, 0.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6727.2222, 1265.2106, 11.1762, 90.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6738.1187, 1262.2106, 11.1762, 270.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6738.1187, 1242.9066, 11.1762, 270.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6727.2222, 1239.9591, 11.1762, 90.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6586.0640, 1242.9176, 11.1762, 90.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6586.0640, 1262.2106, 11.1762, 90.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6596.8091, 1265.1105, 11.1762, 270.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6596.8091, 1239.9432, 11.1762, 270.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6793.5283, 1328.1935, 20.0773, 90.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6800.0322, 1321.4069, 20.0773, 180.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6800.0322, 1183.0076, 20.0773, 0.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6795.3564, 1175.6935, 20.0773, 90.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6790.6738, 1309.3260, 2.8972, 180.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6790.6738, 1198.8260, 3.3972, 0.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6777.3657, 1194.4376, 3.3972, 90.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6776.6221, 1310.5172, 2.8972, 90.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6531.6934, 1307.0502, 2.8972, 180.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6544.0459, 1310.5172, 2.8972, 270.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6531.6934, 1198.5461, 2.8972, 0.0000, -1, -1, 100);
CreateVehicle(RandomVehicleId[rand][0], 6544.2046, 1194.5643, 2.8972, 270.0000, -1, -1, 100);
}
Spawn is a a function triggered by a timer, this is a filterscript. So the timer is initiated on the gamemode when /test is typed. But when I try to compile this it gives Pawn Library Compiler has stopped. Everytime, what Is wrong. I need them in this timer by the way
Reply
#6

If I take this out it works
pawn Код:
new rand = random(sizeof(RandomVehicleId));
I don't see any issues with it
Reply
#7

I sorted the compiling error, but I still need to know how to use a random for each of the CreateVehicle
Reply
#8

Replace every "RandomVehicleId[rand][0]" with "RandomVehicleId[random(sizeof(RandomVehicleId))][0]"
Edit: And remove the "new rand = random(sizeof(RandomVehicleId));"
Reply
#9

Thanks man! rep +! Now can I set a max? so it can choose one of the randoms on the list like 3 times max, each individual
Reply
#10

Ehm, I didn't get your point... Mind explaining it again?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)