Loop problem
#1

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?
Reply
#2

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;
}
Reply
#3

Thanks man, you really helped me out!
Reply
#4

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.
Reply
#5

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)