What's wrong with this loop? - 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: What's wrong with this loop? (
/showthread.php?tid=295696)
What's wrong with this loop? -
Knappen - 07.11.2011
I haven't made that many loops before, and the loops I've made has been pretty simple.
pawn Code:
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(strfind(result, NameTagInfo[playerid][nFirstName], true) != -1 || strfind(result, NameTagInfo[playerid][nLastName], true) != -1)
{
while(GetDistanceBetweenPlayers(playerid, i) < 10)
{
if(NameTagInfo[i][nFriend1] == 0)
{
NameTagInfo[i][nFriend1] = PlayerInfo[playerid][pSQLID];
SaveFriends(i);
}
else if(NameTagInfo[i][nFriend2] == 0)
{
SendClientMessage(i, COLOR_YELLOW, "It didn't work");
SendClientMessage(playerid, COLOR_YELLOW, "It didn't work");
}
}
SendClientMessage(playerid, COLOR_YELLOW, "It worked!");
return 1;
}
}
return true;
I does work, but it also affects the players that types the command, and I want it to only affect the players around the player who types in the command.
It's just something I made for fun I guess, a piece where a player have to type in their name, and then the other players in range, can see his name.
Re: What's wrong with this loop? -
Scarred - 07.11.2011
Quote:
Originally Posted by Knappen
I haven't made that many loops before, and the loops I've made has been pretty simple.
pawn Code:
for(new i = 0; i < MAX_PLAYERS; i++) { if(strfind(result, NameTagInfo[playerid][nFirstName], true) != -1 || strfind(result, NameTagInfo[playerid][nLastName], true) != -1) { while(GetDistanceBetweenPlayers(playerid, i) < 10) { if(NameTagInfo[i][nFriend1] == 0) { NameTagInfo[i][nFriend1] = PlayerInfo[playerid][pSQLID]; SaveFriends(i); } else if(NameTagInfo[i][nFriend2] == 0) { SendClientMessage(i, COLOR_YELLOW, "It didn't work"); SendClientMessage(playerid, COLOR_YELLOW, "It didn't work"); } } SendClientMessage(playerid, COLOR_YELLOW, "It worked!"); return 1; } } return true;
I does work, but it also affects the players that types the command, and I want it to only affect the players around the player who types in the command.
It's just something I made for fun I guess, a piece where a player have to type in their name, and then the other players in range, can see his name.
|
Add another check like
pawn Code:
if(i != playerid) {
//rest of your code
}
This will skip the player that typed the command.
Re: What's wrong with this loop? -
Knappen - 07.11.2011
It worked! Thank you!