you need to imagine "i" as a variable.
the playerID is a number...
so... the "playerid" is a pre-set number (the number of the player that uses the command or that you have entered, etc.... = the ID of a specific player)...
the "for" loop will run again and again as long as the limit "i < MAX_PLAYERS" is reached..
you have this code:
pawn Код:
for(new i=0; i < MAX_PLAYERS; i++)
the "new i=0" creates the variable "i" and sets the value that is connected to it to "0" (so it would be the same as the player that has the ID 0)...
i < MAX_PLAYERS is the limit... The loop will repeat itself until the MAX_PLAYERS value is reached (I think it's 500)
i++ makes the "i value" increasing by 1 each time the loop repeats... so for the first time i is 0.. for the second it's 1, the third 2, etc...
So "i" has another value each time the loop runs, where playerid always stays the same.
If you want now enter "playerd" somewhere into the loop - example SendClientMessage(playerid......) - it will send the message to the player everytime the loop runs and gets to this point, but if you enter "i" instead - SendClientMessage(i, .........) - it will send the message to the "i" ID each time. As this ID is increasing by 1 in each round, it will always get another player.
If you have bigger codes within the loop it is stupid to make it do the defined thing for each ID ("i") untill the MAX_PLAYER limit is reached, as it doesn't have any effact to the "not connected" players.
Therefore you should enter "IsPlayerConnected(i)" before using the it, so it will only do it for players that are even connected...
however:
If the "playerid" variable is not defined yet (for example on a "public" that you created yourself by forwarding or on a "stock" that doesn't have the (playerid) variable, then you can use playerid the same way as "i"
e.g.
pawn Код:
//this will send a message to all connected players, as the "playerid" is not defined before and does the same as the "i" variable in this case
forward SendNoobMsg(text[]);
public SendNoobMsg(text[])
{
for(new playerid=0; playerid < MAX_PLAYERS; playerid++)
{
if(IsPlayerConnected(playerid))
{
SendClientMessage(playerid, COLOR, text);
}
}
return 1;
}
I hope that helped lol...