SA-MP Forums Archive
issue with command that lists admins available - 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: issue with command that lists admins available (/showthread.php?tid=662198)



issue with command that lists admins available - Stefhan - 25.12.2018

Код:
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.


Re: issue with command that lists admins available - NaS - 25.12.2018

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.


Re: issue with command that lists admins available - RogueDrifter - 25.12.2018

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.


Re: issue with command that lists admins available - Mo123 - 25.12.2018

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


Re: issue with command that lists admins available - RogueDrifter - 25.12.2018

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;
}



Re: issue with command that lists admins available - Mo123 - 25.12.2018

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


Re: issue with command that lists admins available - RogueDrifter - 25.12.2018

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;
}



Re: issue with command that lists admins available - Mo123 - 25.12.2018

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)


Re: issue with command that lists admins available - RogueDrifter - 25.12.2018

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!