SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 03/06/2013, 02:26 PM   #1
GiamPy.
Huge Clucker
 
GiamPy.'s Avatar
 
Join Date: Apr 2011
Location: Ravenna, Italy
Posts: 220
Reputation: 16
Default Dynamic Dialog Pages

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.
GiamPy. is offline   Reply With Quote
Old 03/06/2013, 02:35 PM   #2
GiamPy.
Huge Clucker
 
GiamPy.'s Avatar
 
Join Date: Apr 2011
Location: Ravenna, Italy
Posts: 220
Reputation: 16
Default Re: Dynamic Dialog Pages

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;
}
GiamPy. is offline   Reply With Quote
Old 03/06/2013, 02:39 PM   #3
SomebodyAndMe
Huge Clucker
 
SomebodyAndMe's Avatar
 
Join Date: Feb 2010
Location: 52.511938,6.092434 find it.
Posts: 471
Reputation: 21
Default Re: Dynamic Dialog Pages

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
SomebodyAndMe is offline   Reply With Quote
Old 03/06/2013, 03:02 PM   #4
GiamPy.
Huge Clucker
 
GiamPy.'s Avatar
 
Join Date: Apr 2011
Location: Ravenna, Italy
Posts: 220
Reputation: 16
Default Re: Dynamic Dialog Pages

Thank you both.
GiamPy. is offline   Reply With Quote
Old 20/06/2013, 07:05 AM   #5
Coz
Little Clucker
 
Join Date: May 2013
Location: Orlando
Posts: 29
Reputation: 5
Default Re: Dynamic Dialog Pages

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

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Help]Dynamic Dialog por12802 Scripting Help 9 29/03/2013 02:55 PM
[FilterScript] Dynamic Dialog Maker arvifilter Filterscripts 12 20/09/2012 04:58 PM
Dynamic dialog problem Devix Scripting Help 4 19/09/2012 11:57 AM
Dynamic Dialog Items help Norn Help Archive 10 25/01/2010 09:52 PM
Pawno, C++, web pages... AiVAMAN Everything and Nothing 4 18/01/2009 03:25 PM


All times are GMT. The time now is 09:39 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.