issue with command that lists admins available
#1

Код:
CMD:admins(playerid)
{
    new flag = 0, str[128];
    
    SendClientMessage(playerid, COLOR_AQUA, "Administrators online:");
    
    foreach(new i:Player)
    {
        if(PlayerInfo[playerid][pAdmin] > 0)
        {
            flag = 1;
             
            if(PlayerInfo[playerid][pAdmin] == KEY_ACTION)
                return format(str, sizeof(str), "{00ff6b}[Paused]{FFFFFF} %s: %s", ReturnAdminLevel(i), ReturnName(i));
    
            if(PlayerInfo[playerid][pAdminDuty] == 1)
            {
                format(str, sizeof(str), "{00ff6b}[Available]{FFFFFF} %s: %s", ReturnAdminLevel(i), ReturnName(i));
            }
            else
                format(str, sizeof(str), "{FF0000}[Unavailable]{FFFFFF} %s: %s", ReturnAdminLevel(i), ReturnName(i));
            return SendClientMessage(i, -1, str);
        }
    }
    if(flag == 0)
        return SendClientMessage(playerid, -1, "There are no admins available currently.");
    
    return 1;
}
basically, this is ment to show a list of admins online with the following tags. [Available] when an admin is on duty, [Unavailable] if they are not on duty, and [Paused] if they are paused, regardless of if they are available or not.

However, it's not working as intended, and I can't find the issue. Maybe someone can help? Much appreciated.
Reply
#2

You shouldn't use return in this loop, since it will stop the loop when the first admin is found.

The rest looks okay, so removing the return from the loop should do it (both returns).

Also

Код:
PlayerInfo[playerid][pAdmin] == KEY_ACTION
You might have a reason for this, but I don't see why you would use a define for key identifiers here.
Reply
#3

Welp, a few notes on this that could be the issue,
Код:
CMD:admins(playerid)
{
    new flag = 0, str[128];
    
    SendClientMessage(playerid, COLOR_AQUA, "Administrators online:");
    
    foreach(new i:Player)
    {
        if(PlayerInfo[playerid][pAdmin] > 0)
        {
            flag = 1;
             
            if(PlayerInfo[playerid][pAdmin] == KEY_ACTION)
                return format(str, sizeof(str), "{00ff6b}[Paused]{FFFFFF} %s: %s", ReturnAdminLevel(i), ReturnName(i));
    
            if(PlayerInfo[playerid][pAdminDuty] == 1)
            {
                format(str, sizeof(str), "{00ff6b}[Available]{FFFFFF} %s: %s", ReturnAdminLevel(i), ReturnName(i));
            }
            else
                format(str, sizeof(str), "{FF0000}[Unavailable]{FFFFFF} %s: %s", ReturnAdminLevel(i), ReturnName(i));
            return SendClientMessage(i, -1, str); 
        }
    }
    if(flag == 0)
        return SendClientMessage(playerid, -1, "There are no admins available currently.");
    
    return 1;
}
So i marked the parts i changed red, try this and if it works let me know then I'll tell you why i changed each one of them and which change of them was a must.

pawn Код:
CMD:admins(playerid)
{
    new bool:flag, str[128];
   
    SendClientMessage(playerid, COLOR_AQUA, "Administrators online:");
   
    foreach(new i:Player)
    {
        if(PlayerInfo[i][pAdmin] > 0)
        {
            flag = true;
             
            if(PlayerInfo[i][pAdmin] == KEY_ACTION)
                format(str, sizeof(str), "{00ff6b}[Paused]{FFFFFF} %s: %s", ReturnAdminLevel(i), ReturnName(i));
   
            else if(PlayerInfo[playerid][pAdminDuty] == 1)
                format(str, sizeof(str), "{00ff6b}[Available]{FFFFFF} %s: %s", ReturnAdminLevel(i), ReturnName(i));

            else
                format(str, sizeof(str), "{FF0000}[Unavailable]{FFFFFF} %s: %s", ReturnAdminLevel(i), ReturnName(i));
                SendClientMessage(i, -1, str);
        }
    }

    if(!flag)
        SendClientMessage(playerid, -1, "There are no admins available currently.");
   
    return 1;
}
EDIT: I also agree with what NaS said about the KEY_ACTION usage.
Reply
#4

Quote:
Originally Posted by RogueDrifter
Посмотреть сообщение
Welp, a few notes on this that could be the issue,
Код:
CMD:admins(playerid)
{
    new flag = 0, str[128];
    
    SendClientMessage(playerid, COLOR_AQUA, "Administrators online:");
    
    foreach(new i:Player)
    {
        if(PlayerInfo[playerid][pAdmin] > 0)
        {
            flag = 1;
             
            if(PlayerInfo[playerid][pAdmin] == KEY_ACTION)
                return format(str, sizeof(str), "{00ff6b}[Paused]{FFFFFF} %s: %s", ReturnAdminLevel(i), ReturnName(i));
    
            if(PlayerInfo[playerid][pAdminDuty] == 1)
            {
                format(str, sizeof(str), "{00ff6b}[Available]{FFFFFF} %s: %s", ReturnAdminLevel(i), ReturnName(i));
            }
            else
                format(str, sizeof(str), "{FF0000}[Unavailable]{FFFFFF} %s: %s", ReturnAdminLevel(i), ReturnName(i));
            return SendClientMessage(i, -1, str); 
        }
    }
    if(flag == 0)
        return SendClientMessage(playerid, -1, "There are no admins available currently.");
    
    return 1;
}
So i marked the parts i changed red, try this and if it works let me know then I'll tell you why i changed each one of them and which change of them was a must.

pawn Код:
CMD:admins(playerid)
{
    new bool:flag, str[128];
   
    SendClientMessage(playerid, COLOR_AQUA, "Administrators online:");
   
    foreach(new i:Player)
    {
        if(PlayerInfo[i][pAdmin] > 0)
        {
            flag = true;
             
            if(PlayerInfo[i][pAdmin] == KEY_ACTION)
                format(str, sizeof(str), "{00ff6b}[Paused]{FFFFFF} %s: %s", ReturnAdminLevel(i), ReturnName(i));
   
            else if(PlayerInfo[playerid][pAdminDuty] == 1)
                format(str, sizeof(str), "{00ff6b}[Available]{FFFFFF} %s: %s", ReturnAdminLevel(i), ReturnName(i));

            else
                format(str, sizeof(str), "{FF0000}[Unavailable]{FFFFFF} %s: %s", ReturnAdminLevel(i), ReturnName(i));
                SendClientMessage(i, -1, str);
        }
    }

    if(!flag)
        SendClientMessage(playerid, -1, "There are no admins available currently.");
   
    return 1;
}
EDIT: I also agree with what NaS said about the KEY_ACTION usage.
Still doesn't work.

The admins doesn't stack in /admins, and only themselves are shown
Reply
#5

Quote:
Originally Posted by Mo123
Посмотреть сообщение
Still doesn't work.

The admins doesn't stack in /admins, and only themselves are shown
Wait shit my bad, try this:
pawn Код:
CMD:admins(playerid)
{
    new bool:flag, str[128];
   
    SendClientMessage(playerid, COLOR_AQUA, "Administrators online:");
   
    foreach(new i:Player)
    {
        if(PlayerInfo[i][pAdmin] > 0)
        {
            flag = true;
             
            if(PlayerInfo[i][pAdmin] == KEY_ACTION)
                format(str, sizeof(str), "{00ff6b}[Paused]{FFFFFF} %s: %s", ReturnAdminLevel(i), ReturnName(i));
   
            else if(PlayerInfo[playerid][pAdminDuty] == 1)
                format(str, sizeof(str), "{00ff6b}[Available]{FFFFFF} %s: %s", ReturnAdminLevel(i), ReturnName(i));

            else
                format(str, sizeof(str), "{FF0000}[Unavailable]{FFFFFF} %s: %s", ReturnAdminLevel(i), ReturnName(i));
                SendClientMessage(playerid, -1, str);
        }
    }

    if(!flag)
        SendClientMessage(playerid, -1, "There are no admins available currently.");
   
    return 1;
}
Reply
#6

Quote:
Originally Posted by RogueDrifter
Посмотреть сообщение
Wait shit my bad, try this:
pawn Код:
CMD:admins(playerid)
{
    new bool:flag, str[128];
   
    SendClientMessage(playerid, COLOR_AQUA, "Administrators online:");
   
    foreach(new i:Player)
    {
        if(PlayerInfo[i][pAdmin] > 0)
        {
            flag = true;
             
            if(PlayerInfo[i][pAdmin] == KEY_ACTION)
                format(str, sizeof(str), "{00ff6b}[Paused]{FFFFFF} %s: %s", ReturnAdminLevel(i), ReturnName(i));
   
            else if(PlayerInfo[playerid][pAdminDuty] == 1)
                format(str, sizeof(str), "{00ff6b}[Available]{FFFFFF} %s: %s", ReturnAdminLevel(i), ReturnName(i));

            else
                format(str, sizeof(str), "{FF0000}[Unavailable]{FFFFFF} %s: %s", ReturnAdminLevel(i), ReturnName(i));
                SendClientMessage(playerid, -1, str);
        }
    }

    if(!flag)
        SendClientMessage(playerid, -1, "There are no admins available currently.");
   
    return 1;
}
works thanks
Reply
#7

Hey screw it, i'm pretty sure the last code i posted works, the only thing weird i see is the usage of KEY_ACTION and other than that it's a variable value issue that should be in other parts of the script, whether its a duty or a pause one.

One final edit(my bad forgot one error):
pawn Код:
CMD:admins(playerid)
{
    new bool:flag, str[128];
   
    SendClientMessage(playerid, COLOR_AQUA, "Administrators online:");
   
    foreach(new i:Player)
    {
        if(PlayerInfo[i][pAdmin] > 0)
        {
            flag = true;
             
            if(PlayerInfo[i][pAdmin] == KEY_ACTION)
                format(str, sizeof(str), "{00ff6b}[Paused]{FFFFFF} %s: %s", ReturnAdminLevel(i), ReturnName(i));
   
            else if(PlayerInfo[i][pAdminDuty] == 1)
                format(str, sizeof(str), "{00ff6b}[Available]{FFFFFF} %s: %s", ReturnAdminLevel(i), ReturnName(i));

            else
                format(str, sizeof(str), "{FF0000}[Unavailable]{FFFFFF} %s: %s", ReturnAdminLevel(i), ReturnName(i));
                SendClientMessage(playerid, -1, str);
        }
    }

    if(!flag)
        SendClientMessage(playerid, -1, "There are no admins available currently.");
   
    return 1;
}
Reply
#8

Quote:
Originally Posted by RogueDrifter
Посмотреть сообщение
Hey screw it, i'm pretty sure the last code i posted works, the only thing weird i see is the usage of KEY_ACTION and other than that it's a variable value issue that should be in other parts of the script, whether its a duty or a pause one.
Fixed it by editing PlayerInfo[playerid][pAdminDuty] == 1) to PlayerInfo[i][pAdminDuty] == 1)
Reply
#9

Quote:
Originally Posted by Mo123
Посмотреть сообщение
Fixed it by editing PlayerInfo[playerid][pAdminDuty] == 1) to PlayerInfo[i][pAdminDuty] == 1)
Wtf you're right



Well at least It's fixed!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)