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



Loop problem - Jstylezzz - 11.04.2012

Hey everybody!

I am stuck on a loop function(i think).
I've made a command that shows the online helpers, now the problem is, it shows the name of the player that types the command, but it shows it for every helper, so, for example, when I type the command, and there are 4 helpers online, I see Online helpers: Jari Johnson 4 times. Or when my name is Test_Test, i see online helpers: test_test 4 times.

This is the command:

Код HTML:
CMD:helpers(playerid, params[])
{
    for(new i; i<MAX_PLAYERS; i++)
    {
    	if(GetPVarInt(i,"Helper") == 1)
		{
		    if(GetPVarInt(i,"HStatus") == 0)
		    {
			new playername[MAX_PLAYER_NAME], string[84];
			GetPlayerName(playerid, playername, sizeof(playername));
			format(string, sizeof(string), "*%s  "COL_GREEN"[AVAILABLE]",RemoveUnderScore(playerid));
			SendClientMessage(playerid, COLOR_LIGHTBLUE, string);

			}
                    if(GetPVarInt(i,"HStatus") == 1)
		    {
			new playername[MAX_PLAYER_NAME], string[84];
			GetPlayerName(playerid, playername, sizeof(playername));
			format(string, sizeof(string), "*%s  "COL_RED"[UNAVAILABLE]",RemoveUnderScore(playerid));
			SendClientMessage(playerid, COLOR_LIGHTBLUE, string);

			}
	        }
	}
    return 1;

}
Does anybody know what I am doing wrong?


Re: Loop problem - ViniBorn - 11.04.2012

pawn Код:
CMD:helpers(playerid, params[])
{
    for(new i, j = GetMaxPlayers(); i != j; i++)
        if(GetPVarInt(i,"Helper") == 1)
        {
            new playername[MAX_PLAYER_NAME], string[84];
            GetPlayerName(i, playername, sizeof(playername));
            if(GetPVarInt(i,"HStatus") == 0)
                format(string, sizeof(string), "*%s  "COL_GREEN"[AVAILABLE]",RemoveUnderScore(i));
            else
                format(string, sizeof(string), "*%s  "COL_RED"[UNAVAILABLE]",RemoveUnderScore(i));

            SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
        }

    return 1;
}



Re: Loop problem - Jstylezzz - 11.04.2012

Thanks man, you really helped me out!


Re: Loop problem - Skribblez - 11.04.2012

You've got some mistakes on getting the player's name. Try this one.
pawn Код:
CMD:helpers(playerid, params[])
{
    for(new i; i < MAX_PLAYERS; i++)
    {
        if(GetPVarInt(i, "Helper") == 1)
        {
            if(GetPVarInt(i, "HStatus") == 0) format(string, sizeof(string), "* %s "COL_GREEN"[AVAILABLE]", RemoveUnderScore(i));
            else format(string, sizeof(string), "* %s "COL_RED"[UNAVAILABLE]", RemoveUnderScore(i));
           
            SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
        }
    }
    return 1;
}
Edit: I assume that "RemoveUnderScore" already gets the player's name, so the GetPlayerName isn't necessary.


Re: Loop problem - Jstylezzz - 11.04.2012

Quote:
Originally Posted by Skribblez
Посмотреть сообщение
You've got some mistakes on getting the player's name. Try this one.
pawn Код:
CMD:helpers(playerid, params[])
{
    for(new i; i < MAX_PLAYERS; i++)
    {
        if(GetPVarInt(i, "Helper") == 1)
        {
            if(GetPVarInt(i, "HStatus") == 0) format(string, sizeof(string), "* %s "COL_GREEN"[AVAILABLE]", RemoveUnderScore(i));
            else format(string, sizeof(string), "* %s "COL_RED"[UNAVAILABLE]", RemoveUnderscore(i));
           
            SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
        }
    }
    return 1;
}
ok thanks, ill try this one as well