[HELP] Color List
#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


Messages In This Thread
[HELP] Color List - by Larsey123IsMe - 15.12.2010, 19:01
Re: [HELP] Color List - by blackwave - 15.12.2010, 19:14
Re: [HELP] Color List - by Retardedwolf - 15.12.2010, 19:21
Re: [HELP] Color List - by Benjo - 15.12.2010, 19:26
Re: [HELP] Color List - by Larsey123IsMe - 15.12.2010, 19:29
Re: [HELP] Color List - by Retardedwolf - 15.12.2010, 19:31
Re: [HELP] Color List - by Benjo - 15.12.2010, 19:57
Re: [HELP] Color List - by The_Gangstas - 15.12.2010, 19:58
Re: [HELP] Color List - by Larsey123IsMe - 15.12.2010, 20:11
Re: [HELP] Color List - by Benjo - 15.12.2010, 20:17

Forum Jump:


Users browsing this thread: 1 Guest(s)