SA-MP Forums Archive
Loop bug - 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: Loop bug (/showthread.php?tid=502525)



Loop bug - Lidor124 - 24.03.2014

I have loop problem with SendClientMessage - in the following picture you can see the message "All player accounts updated successfully." and it sends this message according to player numbers - we were 2 players in the server but when we will be 5 it will send 5 times.
btw when i use break; it gives me tag mismatch....



Код:
CMD:savechars(playerid, params[])
{
    if (PlayerInfo[playerid][pAdmin] >= 99999) 
	foreach(Player, i)
	{
		OnPlayerStatsUpdate(i);
        SaveEventPoints();
        SaveAccountsUpdate();
        SaveHouses();
        SendClientMessageEx(playerid, COLOR_YELLOW, "All player accounts updated successfully.");
    }
    else {
        SendTDMessage(playerid, COLOR_WHITE, "You are not authorized to use this command.");
	}
    return 1;
}



Re: Loop bug - Konstantinos - 24.03.2014

pawn Код:
CMD:savechars(playerid, params[])
{
    if (PlayerInfo[playerid][pAdmin] < 99999) return SendTDMessage(playerid, COLOR_WHITE, "You are not authorized to use this command.");
    foreach(Player, i) OnPlayerStatsUpdate(i);
    SaveEventPoints();
    SaveAccountsUpdate();
    SaveHouses();
    SendClientMessageEx(playerid, COLOR_YELLOW, "All player accounts updated successfully.");
    return 1;
}
You need to use only OnPlayerStatsUpdate to the loop. Any other function should be called only once and outside of the loop.