SA-MP Forums Archive
Need help with Random - 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: Need help with Random (/showthread.php?tid=458036)



Need help with Random - arjanforgames - 14.08.2013

How can I generate random coordinates like this:

Minx = 10
MinY = 2
MaxX = 20
MaxY = 4
And actually Z too but you got the idea. You have like some 3D box.
Now how do I get random coordinates in that box so I can place a random object?
I'm sorry might be easy but I suck at mathematics.


Re: Need help with Random - [XST]O_x - 14.08.2013

pawn Код:
enum _randInfo
{
    Float: minX,
    Float: minY,
    Float: minZ,
    Float: maxX,
    Float: maxY,
    Float: maxZ
}

new randInfo[2][_randInfo] = {
{10, 2, 3, 20, 4, 6},
{20, 4, 2, 40, 5, 10}
};

new rand = random(sizeof  randInfo);
/*
randInfo[rand][minX] = ...
randInfo[rand][minY] = ....
Now you can just use these randomly generated values.
Example:
*/

new gID = GangZoneCreate(randInfo[rand][minX], randInfo[rand][minY], randInfo[rand][maxX], randInfo[rand][maxY]);