Get everyone except playerid
#1

I want to get everyone except the player who using the command, how can i do this?

pawn Код:
if (newkeys & KEY_CTRL_BACK){
    if(YellowFish[playerid]){
    for(new i=0;i<MAX_PLAYERS;i++){
    GetPlayerPos(playerid,pX,pY,pZ);
    if(IsPlayerInRangeOfPoint(i,7,pX,pY,pZ)){GivePlayerHealth(i,-5);}}}
    return 1;}
Reply
#2

if (newkeys & KEY_CTRL_BACK){
if(YellowFish[playerid]){
for(new i=0;i<MAX_PLAYERS;i++){
if(i != playerid) {
GetPlayerPos(playerid,pX,pY,pZ);
if(IsPlayerInRangeOfPoint(i,7,pX,pY,pZ)){GivePlaye rHealth(i,-5);}}}}
return 1;}
Reply
#3

Quote:
Originally Posted by StreetRP
Посмотреть сообщение
if (newkeys & KEY_CTRL_BACK){
if(YellowFish[playerid]){
for(new i=0;i<MAX_PLAYERS;i++){
if(i != playerid) {
GetPlayerPos(playerid,pX,pY,pZ);
if(IsPlayerInRangeOfPoint(i,7,pX,pY,pZ)){GivePlaye rHealth(i,-5);}}}}
return 1;}
ye very smart, if
pawn Код:
i != playerid
so it will cancel whole the function, i mean, it's won't damage the others too cause the playerid is around.
Reply
#4

your indentations are giving me a stroke.

pawn Код:
if (newkeys & KEY_CTRL_BACK)
{
    if(YellowFish[playerid])
    {
        for(new i=0; i<MAX_PLAYERS; i++)
        {
            GetPlayerPos(playerid,pX,pY,pZ);
            if(IsPlayerInRangeOfPoint(i,7,pX,pY,pZ) && i != playerid) GivePlayerHealth(i,-5);
        }
    }
    return 1;
}
That should work.
Reply
#5

Jesus Christ!
Wont you even check if the player is connected before getting the postion?

Код:
for(new i = 0; i != MAX_PLAYERS; i++)
{
	if (!IsPlayerConnected(i))
		continue;

	if (playerid == i)
		continue;

    GetPlayerPos(playerid, pX, pY, pZ);

    if(IsPlayerInRangeOfPoint(i, 7, pX, pY, pZ)) {
        GivePlayerHealth(i, -5);
    }
}
Reply
#6

Two suggestions though; get the position of "playerid" outside of the loop and use foreach instead as it loops through connected ONLY players (much faster)!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)