/admins some what problem
#1

everyone it is my /admins command it works fine now

Код:
CMD:admins(playerid,params[])
{
    new Count = 0;
    new string[100], n[MAX_PLAYER_NAME];
    SendClientMessage(playerid, 0x00FF00FF, "__________|Admins|__________");
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(PlayerInfo[i][Level] > 0)
        {
            GetPlayerName(i,n,sizeof(n));
            format(string,sizeof(string),"Level %d: %s (ID: %d) - %s", PlayerInfo[i][Level], n, i, GetRankFromLevel(i));
            SendClientMessage(playerid, 0xFF0000FF, string);
            Count++;
        }
    }
    if(Count == 0)
    {
        SendClientMessage(playerid, 0xFF0000FF, "There Are No Administrators Online.");
    }
    SendClientMessage(playerid, 0x00FF00FF, "____________________________");
    return 1;
}
but when ever i put it in dialoges it shows only one admin name not all admin name

Код:
CMD:admins(playerid,params[])
{
    new Count = 0;
    new string[100], n[MAX_PLAYER_NAME];
    SendClientMessage(playerid, 0x00FF00FF, "__________|Admins|__________");
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(PlayerInfo[i][Level] > 0)
        {
            GetPlayerName(i,n,sizeof(n));
            format(string,sizeof(string),"Level %d: %s (ID: %d) - %s", PlayerInfo[i][Level], n, i, GetRankFromLevel(i));
            ShowPlayerDialog(playerid, 2,DIALOG_STYLE_MSGBOX, "online admins..", string, "ok", "");
            Count++;
        }
    }
    if(Count == 0)
    {
        ShowPlayerDialog(playerid, 2,DIALOG_STYLE_MSGBOX, "online admins..", "No admins online", "ok", "");
    }
    return 1;
}
please help me
Reply
#2

bump!!! please i need help
Reply
#3

You can only show one dialog at a time. Right now you're trying to show one dialog per admin; a simple modification will fix this:

pawn Код:
if(PlayerInfo[i][Level] > 0)
        {
            GetPlayerName(i,n,sizeof(n));
            format(string,sizeof(string),"%s%sLevel %d: %s (ID: %d) - %s", string, (( Count > 0 ) ? (", ") : ("")) PlayerInfo[i][Level], n, i, GetRankFromLevel(i));
            Count++;
            }
    }
    ShowPlayerDialog(playerid, 2,DIALOG_STYLE_MSGBOX, "online admins..", string, "ok", "");
Explained: First of all - I added "string" infront of the entire string so that it will add to the old string - instead of replacing.

The part you might not understand is the second '%s' which is represented by this code:
pawn Код:
(( Count > 0 ) ? (", ") : (""))
What this does is actually an if check. You can read about it https://sampforum.blast.hk/showthread.php?tid=216730]here.

This actually checks if count is higher than 0, and if it is, it should add ", " after the string. This is to separate admins with a delimiter.

An example dialog would be
Quote:

online admins..

Level <level>: CBCandyBoy (ID: <id>) - <rank>, Level <level>: LarzI (ID: <id>) - <rank>

If you want to have one admin for each line, you may simply add a "\n" at the end of the format, like so:
pawn Код:
format(string,sizeof(string),"%sLevel %d: %s (ID: %d) - %s\n", string, PlayerInfo[i][Level], n, i, GetRankFromLevel(i));
Notice that I've removed the ternary-check as this is no longer needed when you separate the admins with lines.

Now, an example dialog would be
Quote:

online admins..

Level <level>: CBCandyBoy (ID: <id>) - <rank>
Level <level>: LarzI (ID: <id>) - <rank>

Edit: Sorry Benzo - I was first!
Reply
#4

Obviously when using ShowPlayerDialog you need to create one large string, rather than multiple strings. As ShowPlayerDialog can only show a single string at once.

pawn Код:
CMD:admins(playerid,params[])
{
    new Count = 0;
    new n[MAX_PLAYER_NAME];
    new string[1000];
    SendClientMessage(playerid, 0x00FF00FF, "__________|Admins|__________");
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(!IsPlayerConnected(i)) continue;
        if(PlayerInfo[i][Level] < 1) continue;
        GetPlayerName(i,n,sizeof(n));
        format(string,sizeof(string),"%sLevel %d: %s (ID: %d) - %s\n", string, PlayerInfo[i][Level], n, i, GetRankFromLevel(i));
        Count++;
    }
    if(Count == 0)
    {
        ShowPlayerDialog(playerid, 2,DIALOG_STYLE_MSGBOX, "online admins..", "No admins online", "ok", "");
        return 1;
    }
    ShowPlayerDialog(playerid, 2,DIALOG_STYLE_MSGBOX, "online admins..", string, "ok", "");
    return 1;
}
Give this a shot. Another alternative is strcat:
https://sampwiki.blast.hk/wiki/strcat

EDIT: Nice LarzI
Reply
#5

thanks benzo and larzi rep to you both
Reply
#6

I have a few small suggestions to make about the loops.

Reset the admin variable to 0 in OnPlayerDisconnect. This will eliminate the need to call IsPlayerConnected(i) in the loop and hence make the loop execution faster.

Try using strcat (string concatenation) for appending strings to already long strings. Otherwise it'll get a lot slower when it grows bigger.
Reply
#7

Quote:
Originally Posted by BenzoAMG
Another alternative is strcat
or...

http://forum.sa-mp.com/showpost.php?...42&postcount=4
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)