SA-MP Forums Archive
Random car spawn help please:D - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Random car spawn help please:D (/showthread.php?tid=462401)



Random car spawn help please:D - Mennims - 06.09.2013

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


Re: Random car spawn help please:D - bensmart469 - 06.09.2013

Show us your current code.


Re: Random car spawn help please:D - Mennims - 07.09.2013

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


Re: Random car spawn help please:D - [HK]Ryder[AN] - 07.09.2013

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


Re: Random car spawn help please:D - Mennims - 07.09.2013

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


Re: Random car spawn help please:D - Mennims - 07.09.2013

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


Re: Random car spawn help please:D - Mennims - 08.09.2013

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


Re: Random car spawn help please:D - Dragonsaurus - 08.09.2013

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


Re: Random car spawn help please:D - Mennims - 08.09.2013

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


Re: Random car spawn help please:D - Dragonsaurus - 08.09.2013

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