SetPlayerInArea
#1

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?
Reply
#2

https://sampwiki.blast.hk/wiki/Random
Reply
#3

and how throwing functions at my face will it help?
Reply
#4

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.
Reply
#5

2 warnings: tag mismatch.
random meant for intger numbers.
Reply
#6

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);
}
Reply
#7

now i got 5 warnings of tag mismatch...
Reply
#8

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);
}
Reply
#9

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.
Reply
#10

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...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)