SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 10/09/2012, 04:17 PM   #1
vIBIENNYx
Huge Clucker
 
vIBIENNYx's Avatar
 
Join Date: Apr 2011
Posts: 218
Reputation: 9
Default [Dialog] Listing MySQL data inside a List Dialog

Basically, I want to retrieve all the members from the MySQL database of a certain faction and display it inside the dialog, here's what I have so far:

pawn Code:
command(members, playerid, params[])
{
    if(PVar[playerid][factionID] < 1)
    {
        SendClientMessage(playerid, 0x66666666, "You are not currently in a faction");
        return 1;
    }
    else
    {
        new Query[128], members, memberrankdisp[24];
        new resultline[200], membername[24], memberrank;
        new membersonline = 0, membersstring[128];
        new memberlist1[128];
        format(Query, sizeof(Query), "SELECT `username` & `factionRank` FROM `playerinfo` WHERE `factionID` = '%d'", PVar[playerid][factionID]);
        mysql_query(Query);
        if(mysql_fetch_row_format(resultline))
        {
            //you can now use sscanf, explode, split or strtok to split result
            sscanf(resultline,"p<|>s[24]d",membername, memberrank);
        }

        members = mysql_num_rows();
        for(new i=0; i < members; i++)
        {
            if(IsPlayerConnected(i))
            {
                membersonline++;
            }
        }
        format(membersstring, sizeof(membersstring), "%s - Members online: (%d/%d)", FVar[PVar[playerid][factionID]][factionname], membersonline, members);
        ShowPlayerDialog(playerid, MEMBERS, DIALOG_STYLE_LIST, membersstring, " ", "Close", "");
       
        for(new i; i < members; i++)
        {
            //
        }
        return 1;
    }
}

I want to add a line for each member too, any help would be appreciated.
vIBIENNYx is offline   Reply With Quote
Old 10/09/2012, 05:05 PM   #3
vIBIENNYx
Huge Clucker
 
vIBIENNYx's Avatar
 
Join Date: Apr 2011
Posts: 218
Reputation: 9
Default Re: [Dialog] Listing MySQL data inside a List Dialog

Basically, have a member on each line inside the dialog.
vIBIENNYx is offline   Reply With Quote
Old 10/09/2012, 05:41 PM   #4
HuSs3n
Guest
 
Posts: n/a
Default Re: [Dialog] Listing MySQL data inside a List Dialog

untested
pawn Code:
command(members, playerid, params[])
{
    if(PVar[playerid][factionID] < 1)
    {
        SendClientMessage(playerid, 0x66666666, "You are not currently in a faction");
        return 1;
    }
    else
    {
        new Query[128], members, memberrankdisp[24];
        new resultline[200], membername[24], memberrank;
        new membersonline = 0, membersstring[128];
        new memberlist1[128];
        format(Query, sizeof(Query), "SELECT `username` & `factionRank` FROM `playerinfo` WHERE `factionID` = '%d'", PVar[playerid][factionID]);
        mysql_query(Query);
        new dialog[1024];
        if(mysql_fetch_row_format(resultline))
        {
            //you can now use sscanf, explode, split or strtok to split result
            sscanf(resultline,"p<|>s[24]d",membername, memberrank);
            format(dialog,sizeof(dialog),"%s\n%s   %d",dialog,membername,memberrank);
        }

        members = mysql_num_rows();
        for(new i=0; i < members; i++)
        {
            if(IsPlayerConnected(i))
            {
                membersonline++;
            }
        }
        format(membersstring, sizeof(membersstring), "%s - Members online: (%d/%d)", FVar[PVar[playerid][factionID]][factionname], membersonline, members);
        ShowPlayerDialog(playerid, MEMBERS, DIALOG_STYLE_LIST, membersstring, dialog, "Close", "");

        for(new i; i < members; i++)
        {
            //
        }
        return 1;
    }
}
  Reply With Quote
Old 10/09/2012, 06:03 PM   #5
vIBIENNYx
Huge Clucker
 
vIBIENNYx's Avatar
 
Join Date: Apr 2011
Posts: 218
Reputation: 9
Default Re: [Dialog] Listing MySQL data inside a List Dialog

There is an issue with this:

pawn Code:
format(Query, sizeof(Query), "SELECT `username` & `factionRank` FROM `playerinfo` WHERE `factionID` = '%d'", PVar[playerid][factionID]);
        mysql_query(Query);

It's not selecting the information correctly, any idea how I can work this?
vIBIENNYx is offline   Reply With Quote
Old 10/09/2012, 06:06 PM   #6
TheArcher
High-roller
 
TheArcher's Avatar
 
Join Date: Dec 2009
Location: Home
Posts: 2,334
Reputation: 251
Default Re: [Dialog] Listing MySQL data inside a List Dialog

pawn Code:
SELECT `username` & `factionRank`....
i think it's
pawn Code:
SELECT `username` AND `factionRank`
__________________
TheArcher is offline   Reply With Quote
Old 10/09/2012, 06:12 PM   #7
vIBIENNYx
Huge Clucker
 
vIBIENNYx's Avatar
 
Join Date: Apr 2011
Posts: 218
Reputation: 9
Default Re: [Dialog] Listing MySQL data inside a List Dialog

Quote:
Originally Posted by TheArcher View Post
pawn Code:
SELECT `username` & `factionRank`....
i think it's
pawn Code:
SELECT `username` AND `factionRank`
Nope.. "/
vIBIENNYx is offline   Reply With Quote
Old 10/09/2012, 06:21 PM   #8
vIBIENNYx
Huge Clucker
 
vIBIENNYx's Avatar
 
Join Date: Apr 2011
Posts: 218
Reputation: 9
Default Re: [Dialog] Listing MySQL data inside a List Dialog

Fixed it's now:

pawn Code:
format(Query, sizeof(Query), "SELECT `username`,`factionRank` FROM `playerinfo` WHERE `factionID` = '%d'", PVar[playerid][factionID]);
        mysql_query(Query);
vIBIENNYx is offline   Reply With Quote
Old 10/09/2012, 06:24 PM   #9
TheArcher
High-roller
 
TheArcher's Avatar
 
Join Date: Dec 2009
Location: Home
Posts: 2,334
Reputation: 251
Default Re: [Dialog] Listing MySQL data inside a List Dialog

Ah that's it, I didn't remember MySQL syntax however there were the problem glad you fixed it
__________________
TheArcher is offline   Reply With Quote
Old 10/09/2012, 07:48 PM   #10
vIBIENNYx
Huge Clucker
 
vIBIENNYx's Avatar
 
Join Date: Apr 2011
Posts: 218
Reputation: 9
Default Re: [Dialog] Listing MySQL data inside a List Dialog

I changed the command to the following:

pawn Code:
command(members, playerid, params[])
{
    if(PVar[playerid][factionID] < 1)
    {
        SendClientMessage(playerid, 0x66666666, "You are not currently in a faction");
        return 1;
    }
    else
    {
        new Query[128], members, memberrankdisp[24];
        new resultline[200], membername[24], memberrank;
        new membersonline = 0, membersstring[128];
        new memberlist1[128];
        new dialog[1024];
        format(Query, sizeof(Query), "SELECT `username`, `factionRank` FROM `playerinfo` WHERE `factionID` = '%d'", PVar[playerid][factionID]);
        mysql_query(Query);
        mysql_store_result();
       
        memberrank = PVar[playerid][factionRank];
        for(new i=0; i < mysql_num_rows(); i++)
        {
            if(mysql_fetch_row_format(resultline))
            {
                //you can now use sscanf, explode, split or strtok to split result
                sscanf(resultline,"p<|>s[24]d", membername, memberrank);
                if(IsPlayerConnected(i))
                {
                    format(dialog,sizeof(dialog),"%s\n{004000}• {FFFFFF}%s, (%s | Rank: %d)",dialog, membername, FactionRankToName(PVar[playerid][factionID], memberrank), memberrank);
                }
                else
                {
                    format(dialog,sizeof(dialog),"%s\n{BF0000}• {FFFFFF}%s, (%s | Rank: %d)",dialog, membername, FactionRankToName(PVar[playerid][factionID], memberrank), memberrank);
                }
            }
        }
        members = mysql_num_rows();
        for(new i=0; i < members; i++)
        {
            if(IsPlayerConnected(i))
            {
                membersonline++;
            }
        }
        format(membersstring, sizeof(membersstring), "%s - Members online: {FFFFFF}(%d/%d)", FVar[PVar[playerid][factionID]][factionname], membersonline, members);
        ShowPlayerDialog(playerid, MEMBERS, DIALOG_STYLE_LIST, membersstring, dialog, "Close", "");
        return 1;
    }
}

BUT, As you can see here:

pawn Code:
if(IsPlayerConnected(i))
                {
                    format(dialog,sizeof(dialog),"%s\n{004000}• {FFFFFF}%s, (%s | Rank: %d)",dialog, membername, FactionRankToName(PVar[playerid][factionID], memberrank), memberrank);
                }
                else
                {
                    format(dialog,sizeof(dialog),"%s\n{BF0000}• {FFFFFF}%s, (%s | Rank: %d)",dialog, membername, FactionRankToName(PVar[playerid][factionID], memberrank), memberrank);
                }

It checks to see if the id of the player is online, rather than the name in the list, meaning if there are two members online, the top two will go green. Any ideas how to work around this?
vIBIENNYx 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
MySQL Rows in Dialog List quagga Scripting Help 2 05/08/2012 06:27 PM
MySQL rows into a Dialog List? GamingTurf Scripting Help 4 13/12/2011 05:58 AM
Listing mySQL data MP2 Help Archive 5 03/04/2011 06:13 PM
Listing all the players in a dialog? DeltaAirlines12 Help Archive 4 09/02/2011 11:58 PM
Dialog LIST question. (MySQL) oliverrud Help Archive 4 19/06/2010 08:35 PM


All times are GMT. The time now is 10:40 PM.


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