Ignore certain ID's in a loop
#1

I need to ignore certain id's in a loop, I thought maybe 'continue' would escape the id's that do not meet the criteria, however it escapes the whole process.

Here is the code i tested with:

pawn Код:
// Under OnPlayerDeath

new Float:x, Float:y, Float:z;
GetPlayerPos(killerid, x, y, z);

for(new i = 0; i < MAX_PLAYERS; i++)
{
      if(!IsPlayerConnected(i) || i != killerid || i != playerid) continue; // Here is where I am trying to ignore id's that don't meet the criteria.
           
      if(IsPlayerInRangeOfPoint(i, 100.0, x, y, z)) // checking if the players that are connected and are not the killer or the victim but still within 100 meters of the killerid.
      {
             print("Kill witnessed"); // someone witnessed the kill
      }

      else // this always gets called atm as the check to ignore id's is wrong
      {
             print("Kill not witnessed");
      }
}
So to clarify, I need to ignore id's that are not connected, that are the playerid and that are the killerid, then process all the remaining id's and check if they are in range of the killerid.

I can tell before I post this I probably havn't explained this very well, but any help is appreciated.
Reply
#2

pawn Код:
if(!IsPlayerConnected(i) || i != killerid || i != playerid) continue;
With this only the 'killerid' and 'playerid' will work...

Wouldn't be this?
pawn Код:
if(!IsPlayerConnected(i) || i == killerid || i == playerid) continue;
Reply
#3

Quote:
Originally Posted by Viniborn
Посмотреть сообщение
pawn Код:
if(!IsPlayerConnected(i) || i != killerid || i != playerid) continue;
With this only the 'killerid' and 'playerid' will work...

Wouldn't be this?
pawn Код:
if(!IsPlayerConnected(i) || i == killerid || i == playerid) continue;
Ha, that could explain a few things, thanks for pointing that out mate.

Edit: The issue I have still stands though, I need an alterate way of bypassing id's in a loop as continue doesn't work the way I thought it would.
Reply
#4

Quote:
Originally Posted by WIKI
continue basically skips a loop iteration
so it's just perfect if you use it correctly.


Quote:
Originally Posted by Infamous
I need to ignore id's that are not connected, that are the playerid and that are the killerid, then process all the remaining id's and check if they are in range of the killerid.
So what's wrong with the code which Viniborn gave you?

pawn Код:
if(!IsPlayerConnected(i) || i == killerid || i == playerid) continue;
Reply
#5

wouldnt it be nice to know the amount players who witnessed a death?
Код:
new WitnessFound:
for(new i = 0; i < MAX_PLAYERS; i++)
{
	if(IsPlayerConnected(i) && i!=killerid && i!=playerid)
	{	
		if(IsPlayerInRangeOfPoint(i, 100.0, x, y, z)) // checking if the players that are connected and are not the killer or the victim but still within 100 meters of the killerid.
		{
			WitnessFound++;
		}
	}
}
if(WitnessFound>0)
{
	new watchers[128];
	format(watchers,sizeof(watchers),"Kill witnessed by %d players",WitnessFound);
	print(watchers); // someone witnessed the kill
}
else
{
	print("Kill not witnessed");
}
Reply
#6

Quote:
Originally Posted by HellSphinX
Посмотреть сообщение
So what's wrong with the code which Viniborn gave you?

pawn Код:
if(!IsPlayerConnected(i) || i == killerid || i == playerid) continue;
That part is just fine now, although for some reason no witnesses are ever detected and it always skips to the 'else' statement.

Quote:
Originally Posted by Babul
Посмотреть сообщение
wouldnt it be nice to know the amount players who witnessed a death?
Код:
-snip-
That's a great idea thanks


Edit: Fixed now, had another typo in the loop, thanks for the help guys.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)