SA-MP Forums Archive
SetPlayerInArea - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: SetPlayerInArea (/showthread.php?tid=255551)



SetPlayerInArea - xDeadlyBoy - 16.05.2011

i got this stock:
pawn Код:
stock SetPlayerInArea(playerid, Float:minx, Float:miny, Float:maxx, Float:maxy)
{
    new Float:x = floatsub(maxx,floatdiv(floatsub(maxx,minx),2));
    new Float:y = floatsub(maxy,floatdiv(floatsub(maxy,miny),2));
    return SetPlayerPosFindZ(playerid, x, y, 1000.0);
}
it teleports the player to the middle of the area.
how can i teleport the player to a random pos in the area?


Re: SetPlayerInArea - Markx - 16.05.2011

https://sampwiki.blast.hk/wiki/Random


Re: SetPlayerInArea - xDeadlyBoy - 16.05.2011

and how throwing functions at my face will it help?


Re: SetPlayerInArea - Backwardsman97 - 16.05.2011

I made this real quick. It should work but I'm pretty sure only if the coordinates are all positive.

pawn Код:
stock SetPlayerInArea(playerid, Float:minx, Float:miny, Float:maxx, Float:maxy)
{
    return SetPlayerPosFindZ(playerid, random(maxx-minx)+minx, random(maxy-miny)+miny, 1000.0);
}
Kinda useless lol.


Re: SetPlayerInArea - xDeadlyBoy - 16.05.2011

2 warnings: tag mismatch.
random meant for intger numbers.


Re: SetPlayerInArea - Backwardsman97 - 16.05.2011

Oops sorry.

pawn Код:
stock SetPlayerInArea(playerid, Float:minx, Float:miny, Float:maxx, Float:maxy)
{
    return SetPlayerPosFindZ(playerid, float(random(maxx-minx)+minx), float(random(maxy-miny)+miny), 1000.0);
}



Re: SetPlayerInArea - xDeadlyBoy - 16.05.2011

now i got 5 warnings of tag mismatch...


Re: SetPlayerInArea - [L3th4l] - 16.05.2011

You could store the positions in a variable.

pawn Код:
new
    Float:ASP[][] = {
    {minx, miny, maxx, maxy},
    {minx, miny, maxx, maxy}
};

new
    iRand = random(sizeof(RandomSpawns));

SetPlayerInArea(playerid, ASP[iRand][0], ASP[iRand][1], ASP[iRand][2], ASP[iRand][3]);

stock SetPlayerInArea(playerid, Float:minx, Float:miny, Float:maxx, Float:maxy)
{
    new Float:x = floatsub(maxx,floatdiv(floatsub(maxx,minx),2));
    new Float:y = floatsub(maxy,floatdiv(floatsub(maxy,miny),2));
    return SetPlayerPosFindZ(playerid, x, y, 1000.0);
}



Re: SetPlayerInArea - xDeadlyBoy - 16.05.2011

i don't want to store position's, i need to do something else.
anyway, i used floatrand by ****** and it's working
thank everyone.


Re: SetPlayerInArea - Backwardsman97 - 16.05.2011

That method could also work. Here's the function I made before but without warnings.

pawn Код:
stock SetPlayerInArea(playerid, Float:minx, Float:miny, Float:maxx, Float:maxy)
{
    return SetPlayerPosFindZ(playerid, float(floatround(random(floatround(maxx-minx))+minx)), float(floatround(random(floatround(maxy-miny))+miny)), 1000.0);
}
Such an ugly function for one that I don't think is very reliable...