Dynamic Dialog Pages
#1

Hello everyone.
I have a little problem.

I am trying to figure out on how to make a dynamic dialog pages system.
For example, I need to make a dialog that shows the members of a faction, the point is that I'd wish to list only 20 members per page, and then do make another page.

I load the members from a MySQL database.

The problem is that I have no idea on how to make the second page, do you guys have any suggestion?

Thank you in advance.
Reply
#2

I can't just limit the query, because in that case the gamemode doesn't know if there are more than 20 members or not, and I wouldn't know if I need to make a second page or not.

This is what I have done so far:

pawn Code:
CMD:fmembers(playerid, params[]) {

    if(playerVariables[playerid][pFaction] == -1)
        return SendErrorMessage(playerid, "You're not part of a faction.");

    playerVariables[playerid][pDialogPage] = 0;

    format(szQueryInput, sizeof(szQueryInput), "SELECT `playerName`, `playerStatus` FROM `account_characters` WHERE `playerFaction` = '%i'",
    playerVariables[playerid][pFaction], playerVariables[playerid][pInternalID]);
    mysql_function_query(connection, szQueryInput, true, "FactionMemberList", "i", playerid, playerVariables[playerid][pDialogPage]);
   
    //format(szQueryInput, sizeof(szQueryInput), "SELECT `playerName`, `playerStatus` FROM `account_characters` WHERE `playerFaction` = '%i' LIMIT %d, %d",
    //playerVariables[playerid][pFaction], playerVariables[playerid][pInternalID], --playerVariables[playerid][pDialogPage]*20, ++playerVariables[playerid][pDialogPage]*20);
    //mysql_function_query(connection, szQueryInput, true, "FactionMemberList", "i", playerid, playerVariables[playerid][pDialogPage]);
    return 1;
}

forward FactionMemberList(playerid, page);
public FactionMemberList(playerid, page)
{
    new rows, fields, bool: firstRow = true, nameFound[MAX_PLAYER_NAME], nameStatus;
    cache_get_data(rows, fields);
   
    if(rows) {
   
        for(new i = 0; i < rows; i++) {

            cache_get_field_content(i, "playerName", nameFound);
            cache_get_field_content(i, "playerStatus", szQueryOutput), nameStatus = strval(szQueryOutput);

            if(firstRow)
                if(nameStatus)
                    format(szDialogString, sizeof(szDialogString), "{33AA33}%s", nameFound);
                else
                    format(szDialogString, sizeof(szDialogString), "{FF0000}%s", nameFound);
            else
                if(nameStatus)
                    format(szDialogString, sizeof(szDialogString), "%s\n{33AA33}%s", szDialogString, nameFound);
                else
                    format(szDialogString, sizeof(szDialogString), "%s\n{FF0000}%s", szDialogString, nameFound);

            //if(rows > 20)
                if(i == --rows)
                {
                    format(szDialogString, sizeof(szDialogString), "%s\n{FFFFFF}Next Page", szDialogString);
                    break;
                }
                else
                    rows++
        }
       
        ShowPlayerDialog(playerid, DIALOG_FMEMBERS, DIALOG_STYLE_LIST, "Faction Members", szDialogString, "Select", "Exit");
       
    } else
        ShowPlayerDialog(playerid, DIALOG_NULL, DIALOG_STYLE_LIST, "Faction Members", "No players found.", "Select", "Exit");
   
    return 1;
}
Reply
#3

This is my SQL based radio station script, it gets the data from the database. It works pretty good.

pawn Code:
public ShowRadio(playerid)
{
        new query[400],title[64];
        format(title,sizeof(title),"{FF9900}Radio Stations");
        format(query, sizeof(query), "SELECT NULL FROM radio");
        mysql_query(query);
        mysql_store_result();
        new tRows = mysql_num_rows();
        if(mysql_num_rows() > 0) {
            mysql_free_result();
            Num1[playerid] = 0;
            Num2[playerid] = 11;
            mysql_free_result();
            format(query, sizeof(query), "SELECT `Name`, `ID`, `Hits` FROM `radio` ORDER BY `Hits` DESC LIMIT %d, %d", Num1[playerid],Num2[playerid]);
            mysql_query(query);
            mysql_store_result();
            new
                szMessageString[1500], // 32 * 15 = 480, 1 extra character for \n
                sName[128],
                sHits,
                sID;
            while(mysql_fetch_row(query))
            {
                sscanf(query, "p<|>s[128]dd", sName, sID, sHits);
                //format(szMessageString, sizeof(szMessageString), "\n");
                format(szMessageString, sizeof(szMessageString), "%s[ID:%d] %s \t\t(%d Hits)\n", szMessageString, sID, sName, sHits);
            }
            if(tRows > 11) { format(szMessageString,sizeof(szMessageString), "%sNext Page", szMessageString); }
            format(szMessageString,sizeof(szMessageString), "The Pilots World Radio\n%s", szMessageString);
            ShowPlayerDialog(playerid, radio1, DIALOG_STYLE_LIST, title, szMessageString, "Select", "Close");
            mysql_free_result();
            return 1;
        }
        else
        {
            mysql_free_result();
            SendClientMessage(playerid, COLOR_ERROR, "There are no radio stations added yet! Ask an administrator to add them.");
            return 1;
        }
}
EDIT The dialog response part:
pawn Code:
if(response)
        {
            if(!strcmp(inputtext, "The Pilots World Radio"))
            {
                PlayAudioStreamForPlayer(playerid, "http://64.31.59.12:8000/listen.pls");
                ListeningToRadio[playerid] = 1;
                new query[128];
                format(query,sizeof(query),"You are now listening to: {FF9900}The Pilots World Radio. {FFFFFF}[/cancelradio to turn off.]");
                SendClientMessage(playerid, COLOR_WHITE, query);
                return 1;
            }
            if(!strcmp(inputtext, "Next Page"))
            {
                new query[200],title[64];
                Num1[playerid] += 11;
                Num2[playerid] += 11;
                format(title,sizeof(title),"{FF9900}Radio Stations");
                format(query, sizeof(query), "SELECT `Name`, `ID`, `Hits` FROM `radio` ORDER BY `Hits` DESC LIMIT %d, 11", Num1[playerid]);
                mysql_query(query);
                mysql_store_result();
                new tRows = mysql_num_rows();

                new
                    szMessageString[1500], // 32 * 15 = 480, 1 extra character for \n
                    sName[128],
                    sHits,
                    sID;

                while(mysql_fetch_row(query))
                {
                    sscanf(query, "p<|>s[128]dd", sName, sID, sHits);
                    //format(szMessageString, sizeof(szMessageString), "\n");
                    format(szMessageString, sizeof(szMessageString), "%s[ID:%d] %s \t\t(%d Hits)\n", szMessageString, sID, sName, sHits);
                }
                if(tRows > 11) { format(szMessageString,sizeof(szMessageString), "%sNext Page", szMessageString); }
                ShowPlayerDialog(playerid, radio1, DIALOG_STYLE_LIST, title, szMessageString, "Select", "Close");
                mysql_free_result();
                return 1;
            }
            else
            {
                Num1[playerid] = 0;
                Num2[playerid] = 0;
                new name[128], shit[64], shit2[64];
                sscanf(inputtext, "s[64]s[128]s[64]", shit,name,shit2);
                ListeningToRadio[playerid] = 1;
                new query[256];
                format(query,sizeof(query),"SELECT URL FROM radio WHERE Name = '%s'", name);
                mysql_query(query);
                mysql_store_result();
                mysql_retrieve_row();
                new url[256];
                mysql_get_field("URL",url);
                PlayAudioStreamForPlayer(playerid, url);
                mysql_free_result();
                format(query,sizeof(query),"You are now listening to: {FF9900}%s. {FFFFFF}[/cancelradio to turn off.]", name);
                SendClientMessage(playerid, COLOR_WHITE, query);
                format(query,sizeof(query),"UPDATE radio SET Hits = Hits + 1 WHERE Name = '%s'", name);
                mysql_query(query);
                return 1;
            }
        }
        Num1[playerid] = 0;
        Num2[playerid] = 0;
        return 1;
I hope you kinda get how it works with this.

Kevin
Reply
#4

Thank you both.
Reply
#5

But how would you make a "Previous Page" button in the dialog box at the end of the second page?
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)