SA-MP Forums Archive
Radius of circle? - 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: Radius of circle? (/showthread.php?tid=345172)



Radius of circle? - Kitten - 24.05.2012

I've been trying to fix this code for a while now i can't really find a way of getting the players in a radius of circle

Код:
..............
.            .
.      . < ---- Player in middle
.             .
...............
Fail example of a circle but all the dots around him would be pushed i've created this code only seems to push only 1 person.

pawn Код:
if(PRESSED(KEY_WALK))
    {
        if(gTeam[playerid] == TEAM_ZOMBIE)
        {
            if(Classes[playerid][StomperZombie] == 1)
            {
                if(iInfo[playerid][StomperPush] == 1)
                {
                    new Float:x,Float:y,Float:z,Float:angle;
                    GetPlayerVelocity(playerid,Float:x,Float:y,Float:z);
                    GetPlayerPos(playerid,Float:x,Float:y,Float:z);
                    GetPlayerFacingAngle(playerid,Float:angle);
                    foreach(Player,i)
                    {
                        GetClosestPlayer(i);
                        if(IsPlayerConnected(i))
                        {
                            new skinid = GetPlayerSkin(i);
                            if(skinid == 2 || skinid == 5 || skinid == 21 || skinid == 260 || skinid == 281 || skinid == 287 || skinid == 230 || skinid == 274 || skinid == 29 || skinid == 179 || skinid == 27 || skinid == 276 || skinid == 22 || skinid == 22 || skinid == 56 || skinid == 108 || skinid == 165)
                            {
                                if(IsPlayerInRangeOfPoint(i,4.3,Float:x,Float:y,Float:z))
                                {
                                    GetPlayerVelocity(i,Float:x,Float:y,Float:z);
                                    SetPlayerVelocity(i,Float:x+0.2,Float:y+0.2,Float:z+0.1);
                                    SetPlayerFacingAngle(i,Float:angle);
                                }
                            }
                        }
                    }
                    iInfo[playerid][StomperPush] = 0;
                    SetTimerEx("StomperReset",7000,0,"i",playerid);
                }
                else
                {
                    GameTextForPlayer(playerid,"~g~ Still recovering",4000,5);
                }
            }
        }
    }



Re: Radius of circle? - Azazelo - 24.05.2012

Definition of foreach use:

foreach (new i : Player)
{
printf("%d", i);
}

Maybe this help.


Re: Radius of circle? - jessejanssen - 24.05.2012

Quote:
Originally Posted by Azazelo
Посмотреть сообщение
Definition of foreach use:

foreach (new i : Player)
{
printf("%d", i);
}

Maybe this help.
His way of using foreach is fine, I always use it like that too so I actually think the way you're telling it it doens't work ( Maybe it does, I'm not sure, but I am sure the way he uses it works. ).
I don't really see something wrong in the code, but you could try this to start with this:
pawn Код:
if(PRESSED(KEY_WALK))
{
    if(gTeam[playerid] == TEAM_ZOMBIE)
        {
        if(Classes[playerid][StomperZombie] == 1)
            {
            if(iInfo[playerid][StomperPush] == 1)
                {
                new Float:Vx,Float:Vy,Float:Vz, Float:Px, Float: Py, Float:Pz, Float:Angle;
                GetPlayerPos(playerid, Px, Py, Pz);
                foreach(Player, i)
                    {
                    GetClosestPlayer(i);
                    if(IsPlayerConnected(i))
                        {
                        new skinid = GetPlayerSkin(i);
                        if(skinid == 2 || skinid == 5 || skinid == 21 || skinid == 260 || skinid == 281 || skinid == 287 || skinid == 230 || skinid == 274 || skinid == 29 || skinid == 179 || skinid == 27 || skinid == 276 || skinid == 22 || skinid == 22 || skinid == 56 || skinid == 108 || skinid == 165)
                            {
                            if(IsPlayerInRangeOfPoint(i,4.3, Px, Py, Pz))
                                {
                                GetPlayerFacingAngle(i, Angle);
                                GetPlayerVelocity(i, Vx, Vy, Vz);
                                SetPlayerVelocity(i, Vx+0.2, Vy+0.2, Vz+0.1);
                                SetPlayerFacingAngle(i, Angle);
                                }
                            }
                        }
                    }
                iInfo[playerid][StomperPush] = 0;
                SetTimerEx("StomperReset",7000,0,"i",playerid);
                }
             else
                {
                GameTextForPlayer(playerid,"~g~ Still recovering",4000,5);
                }
            }
        }
}
Best regards,
Jesse


Re: Radius of circle? - MP2 - 24.05.2012

You don't need to use IsPlayerConnected in foreach. It's just making it less efficient - which is what it was created for.

As for your code, you should debug it with prints to see what exactly is happening.