[HELP] Color List
#1

This code only show my name when i am 'Blue', it dont show the other players who is blue too


pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/blue", cmdtext, true, 10) == 0)
    {
        if(GetPlayerColor(playerid) == 0x00137FAA) //0x00137FFAA = Blue color
        {
            SendClientMessageToAll(0xDEEE20FF, "|_List of blue players_|");
            new names[MAX_PLAYER_NAME], string[44];
            GetPlayerName(playerid, names, sizeof(names));
            format(string, sizeof(string), "%s(%d)",names ,playerid);
            SendClientMessage(playerid, 0x7F0037AA, string);
        }
        return 1;
    }
    return 0;
}

//Like:

// |_List of blue players_|
// PLAYERNAME(ID)
// PLAYERNAME(ID)
// PLAYERNAME(ID)
// PLAYERNAME(ID)
// PLAYERNAME(ID)
// ect...
Reply
#2

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
     for(new i = 0; i < MAX_PLAYERS; i++)
     if (strcmp("/blue", cmdtext, true, 10) == 0)
    {
        if(GetPlayerColor(i) == 0x00137FAA) //0x00137FFAA = Blue color
        {
            SendClientMessageToAll(0xDEEE20FF, "|_List of blue players_|");
            new names[MAX_PLAYER_NAME], string[44];
            GetPlayerName(playerid, names, sizeof(names));
            format(string, sizeof(string), "%s(%d)",names ,playerid);
            SendClientMessage(playerid, 0x7F0037AA, string);
        }
        return 1;
    }
    return 0;
}
Reply
#3

pawn Код:
#include <a_samp>
#include <zcmd>
#include <foreach>

COMMAND:blue( playerid, params [ ] )
{
    new
        string [ 10 + MAX_PLAYER_NAME ],
        pName  [ MAX_PLAYER_NAME ]
    ;

    SendClientMessage ( playerid, 0xFFFFFFAA, "|_List of blue players_|" );
    foreach (Player, i)
    {
        if ( GetPlayerColor ( i ) == 0x00137FAA )
        {
            GetPlayerName       ( i, pName, MAX_PLAYER_NAME );
            format              ( string, sizeof ( string ), "%s - ( %d ), " );
            SendClientMessage   ( playerid, 0xFFFFFFAA, string );
        }
    }
    return 1;
}
Reply
#4

This one should work properly, and does not require the use of any additional plugins/includes (even though the ones used in Retardedwolf's solution are very useful ):

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/blue", cmdtext, true, 5) == 0)
    {
        SendClientMessageToAll(0xDEEE20FF, "|_List of blue players_|");
        for(new i=0; i<MAX_PLAYERS; i++)
        {
            if(GetPlayerColor(i) == 0x00137FAA) //0x00137FFAA = Blue color
            {
                new names[MAX_PLAYER_NAME], string[44];
                GetPlayerName(i, names, sizeof(names));
                format(string, sizeof(string), "%s(%d)",names ,playerid);
                SendClientMessage(playerid, 0x7F0037AA, string);
            }
        }
        return 1;
    }
    return 0;
}
Reply
#5

**How to say "No blue players online" when no blue players is online?**


Thanks, and is it possible to add an password to it, like:

When i type /blue, then a INPUT_DIALOG show so i can type a password there

and if he type wrong password then the color list dont show

Please do it in strcmp and not on dcmd, zcmd, sscanf or whatever :P

Sorry for dumb questions =/
Reply
#6

@Benjo, you're creating a string which is 65 characters long, 500 times which is a total waste of CPU/Memory and people could just spam the command all day long and imagine the lag you get.
Reply
#7

Quote:
Originally Posted by Retardedwolf
Посмотреть сообщение
@Benjo, you're creating a string which is 65 characters long, 500 times which is a total waste of CPU/Memory and people could just spam the command all day long and imagine the lag you get.
Ah yes my bad, of course the variable declarations should not be inside the for loop. This is why it's always good to have several sets of eyes on a piece of code



Anyway Larsey, regarding your last post, yes that is possible. Bear with me as I'm pretty rusty with dialogs:

Defines at the top:
pawn Код:
#define DIALOG_LOGIN_BLUE   1           // This is the dialogid
#define BLUE_PASSWORD       "qwerty1"   // changethis
The callback that runs when a player has responded to the dialog:
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case(DIALOG_LOGIN_BLUE):
        if(!response) { /* user cancelled */ } else
        {
            if(strcmp(inputtext, BLUE_PASSWORD, false, strlen(BLUE_PASSWORD)) == 0)
            {
                SendClientMessageToAll(0xDEEE20FF, "|_List of blue players_|");
                new names[MAX_PLAYER_NAME], string[44];
                for(new i=0; i<MAX_PLAYERS; i++)
                {
                    if(GetPlayerColor(i) == 0x00137FAA) //0x00137FFAA = Blue color
                    {
                        GetPlayerName(i, names, sizeof(names));
                        format(string, sizeof(string), "%s(%d)",names ,playerid);
                        SendClientMessage(playerid, 0x7F0037AA, string);
                    }
                }
            } else {
                SendClientMessage(playerid, 0xDEEE20FF, "Incorrect password.");
            }
        }
        default:{printf("DEBUG: Undefined dialogid.");}
    }
   
}
The much more simple looking code inside the original strcmp function:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/blue", cmdtext, true, 5) == 0)
    {
        ShowPlayerDialog(playerid, DIALOG_LOGIN_BLUE, DIALOG_STYLE_INPUT, "Authentication", "Please type the password for the blue team.", "Ok", "Cancel");
        return 1;
    }
    return 0;
}
This isn't the best way to do this, but it should work. Also, I can't remember whether dialogids are static amongst all players once created, or whether each player has a different dialogid. I've assumed the former for this solution so be prepared to make corrections! ^_^
Reply
#8

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/blue", cmdtext, true, 5) == 0)
    {
        SendClientMessage(playerid,0xDEEE20FF, "|_List Of Blue Players_|");
        for(new i=0; i<MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i))
            {
                if(GetPlayerColor(i) == 0x00137FAA) //0x00137FFAA = Blue color
                {
                    new names[MAX_PLAYER_NAME], string[MAX_PLAYER_NAME+7];
                    GetPlayerName(i, names, sizeof(names));
                    format(string, sizeof(string), "%s(%d)",names ,playerid);
                    SendClientMessage(playerid, 0x7F0037AA, string);
                }
            }
        }
        return 1;
    }
    return 0;
}
Reply
#9

All i can say is: Thx, i really Appreciate this
Reply
#10

Quote:
Originally Posted by Larsey123IsMe
Посмотреть сообщение
**How to say "No blue players online" when no blue players is online?**
Sorry, didn't notice that before. Modified the OnDialogResponse callback to include that:
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case(DIALOG_LOGIN_BLUE):
        if(!response) { /* user cancelled */ } else
        {
            if(strcmp(inputtext, BLUE_PASSWORD, false, strlen(BLUE_PASSWORD)) == 0 && strlen(inputtext) > 0)
            {
                new names[MAX_PLAYER_NAME], string[44], bool:flag = false; // <--- ADDED flag VARIABLE HERE
                for(new i=0; i<MAX_PLAYERS; i++)
                {
                    if(GetPlayerColor(i) == 0x00137FAA) //0x00137FFAA = Blue color
                    {
                        if(!flag)
                        {
                            SendClientMessageToAll(0xDEEE20FF, "|_List of blue players_|");
                            flag = true;
                        }
                        GetPlayerName(i, names, sizeof(names));
                        format(string, sizeof(string), "%s(%d)",names ,playerid);
                        SendClientMessage(playerid, 0x7F0037AA, string);
                    }
                }
                if(!flag)
                {
                    SendClientMessageToAll(0xDEEE20FF, "There are no players on the blue team.");
                }
            } else {
                SendClientMessage(playerid, 0xDEEE20FF, "Incorrect password.");
            }
            return 1;
        }
        default:{printf("DEBUG: Undefined dialogid.");}
    }
   
    return 0;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)