Spawn IN Zone
#1

Hi, how to make random spawn in the zone?

example.:

Код:
new Float:Points[12] =
    {2305.5264, 1783.7133, 2305.5264, 1882.6989, 2167.5994, 1882.6989, 2167.5994, 1859.0988, 2128.2075, 1783.7133, 2305.5264, 1783.7133};
    AdminHQArea = CreateDynamicPolygon(Points, 5.0, 15.0, sizeof(Points));
and spawn in zone (AdminHQArea) randomly.
Reply
#2

Quote:
Originally Posted by RolePlayNews
Посмотреть сообщение
Hi, how to make random spawn in the zone?

example.:

Код:
new Float:Points[12] =
    {2305.5264, 1783.7133, 2305.5264, 1882.6989, 2167.5994, 1882.6989, 2167.5994, 1859.0988, 2128.2075, 1783.7133, 2305.5264, 1783.7133};
    AdminHQArea = CreateDynamicPolygon(Points, 5.0, 15.0, sizeof(Points));
and spawn in zone (AdminHQArea) randomly.
Hello RolePlayNews,

It is a way more easier to find the coords inside rectangle, so if you don't want to overstrain, try to write a rectangle inside your polygon. Yes, with this you'll 'randomness' will be a way more inaccurate, but will always save up some priceless time c:

But, you can do it hardway. I won't write what has been already written, so I'll just give you a reference.There's C++ implementation on this problem, but I assume, that you will be able to rewrite it for your own usage, or just it will make you understand how to solve this on your own.

Good luck!
Greetings.
Reply
#3

Ahh, thanks man! You are best!
Reply
#4

It's very easy to see if a point is in a lies within a polygon.

Код:
IsPointInDynamicArea(areaid, Float:x, Float:y, Float:z);
All you need to know is rectangle size from where points would be generated from to get some samples.

pawn Код:
// x1, y1, x2, y2 - Spawn generation
GenerateRandomSpawnInArea(areaid, Float:x1, Float:y1, Float:x2, Float:y2, &Float:randx, &Float:randy)
{
    new Float:tmp, Float:randx, Float:randy, xsize, ysize, Tries;

    if(x1 > x2)
    {
        tmp = x1;
        x1 = x2;
        x2 = tmp;
    }

    if(y1 > y2)
    {
        tmp = y1;
        y1 = y2;
        y2 = tmp;
    }

    xsize = floatround(x2-x1);
    randy = floatround(y2-y1);

    // Try up to 100 times
    while(Tries < 100)
    {
        randx = float(random(xsize));
        randy = float(random(ysize));

        if(IsPointInDynamicArea(areaid, x1+randx, y1+randy, 0.0)) return 1;
        Tries++;
    }
   
    return 0;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)