SA-MP Forums Archive
Loading a help list - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Loading a help list (/showthread.php?tid=610725)



Loading a help list - justjamie - 27.06.2016

Hello.
i have a command where someone can use /help to ask a question, it stores it in the database, and i want a list with unanswered questions.
I made a code, but it doesn't load anything.
Can someone tell me what i did wrong?
Thanks.

PHP код:
COMMAND:helplist(playeridparams[])
{
    new 
query[420];
    if(!
Player[playerid][Admin] && !Player[playerid][Helper]) return SendClientError(playerid,"You are not authorized to use this command");
    for(new 
i=1i<100i++)
    {
    
format(query,sizeof(query),"SELECT * FROM helplist WHERE ID='%s' AND active='1'",i);
    
mysql_tquery(connection,query,"helpList","ud",playerid,i);
    }
    return 
1;
}
forward helpList(playerid,helpid);
public 
helpList(playerid,helpid)
{
    new 
string[420],temp_sentby[35],temp_wat[420];
    
cache_get_field_content(helpid"sentby"temp_sentby);
    
cache_get_field_content(helpid"wat"temp_wat);
    
    
format(string,sizeof(string),"{FFFFFF}[{6f757d}Help ID%d{FFFFFF}] {6f757d}%s{FFFFFF}: '{6f757d}%s{FFFFFF}'",helpid,temp_sentby,temp_wat);
    
SendClientMessage(playerid,-1,string);
    return 
1;




Re: Loading a help list - Stinged - 27.06.2016

"u" isn't an actual thing for callbacks, it only works in sscanf.
It should be i or d (integer)

You shouldn't use a loop for that.
Just use something like this:
Код:
mysql_tquery(connection, "SELECT * FROM helplist WHERE active = 1", "helplist", "i", playerid);

forward helplist(playerid);
public helplist(playerid)
{
    new rows = cache_num_rows();
    if (!rows) 
        return SendClientMessage(playerid, -1, "No active questions.");

    new id, temp_sentby[35], tmp_wat[144];
    for (new i = 0; i < rows; i++)
    {
        id = cache_get_field_content_int(i, "ID");
        cache_get_field_content(i, "sentby", temp_sentby); 
        cache_get_field_content(i, "wat", temp_wat);

        format(temp_wat, sizeof (temp_wat), "{FFFFFF}[{6f757d}Help ID%d{FFFFFF}] {6f757d}%s{FFFFFF}:'{6f757d}%s{FFFFFF}'",id,temp_sentby,temp_wat);
        SendClientMessage(playerid, color, temp_wat);
    }
    return 1;
}



Re: Loading a help list - justjamie - 27.06.2016

Quote:
Originally Posted by Stinged
Посмотреть сообщение
"u" isn't an actual thing for callbacks, it only works in sscanf.
It should be i or d (integer)

You shouldn't use a loop for that.
Just use something like this:
Код:
mysql_tquery(connection, "SELECT * FROM helplist WHERE active = 1", "helplist", "i", playerid);

forward helplist(playerid);
public helplist(playerid)
{
    new rows = cache_num_rows();
    if (!rows) 
        return SendClientMessage(playerid, -1, "No active questions.");

    new id, temp_sentby[35], tmp_wat[144];
    for (new i = 0; i < rows; i++)
    {
        id = cache_get_field_content_int(i, "ID");
        cache_get_field_content(i, "sentby", temp_sentby); 
        cache_get_field_content(i, "wat", temp_wat);

        format(temp_wat, sizeof (temp_wat), "{FFFFFF}[{6f757d}Help ID%d{FFFFFF}] {6f757d}%s{FFFFFF}:'{6f757d}%s{FFFFFF}'",id,temp_sentby,temp_wat);
        SendClientMessage(playerid, color, temp_wat);
    }
    return 1;
}
Thanks, but i now get absolutely spammed, even tho i have 1 active question open xd.


Re: Loading a help list - Stinged - 27.06.2016

Do you get spammed with the same message? If not, post some of them.
Also, please post a picture or something of your table.


Re: Loading a help list - justjamie - 27.06.2016

Quote:
Originally Posted by Stinged
Посмотреть сообщение
Do you get spammed with the same message? If not, post some of them.
Also, please post a picture or something of your table.
https://gyazo.com/632f598a54486ae50f1eb562340cee3f

i get spammed by both messages


Re: Loading a help list - Stinged - 27.06.2016

Are you actually getting spammed? Or are you getting sent 2 messages?
Because in the post above you said this:
Quote:
Originally Posted by justjamie
Посмотреть сообщение
even tho i have 1 active question open xd.
When you actually have 2 questions 'active'


Re: Loading a help list - justjamie - 27.06.2016

Quote:
Originally Posted by Stinged
Посмотреть сообщение
Are you actually getting spammed? Or are you getting sent 2 messages?
Because in the post above you said this:

When you actually have 2 questions 'active'
yes i noticed that i had 2 open, my bad.

this is what i get:

Код:
[21:13:14] {FFFFFF}[{6f757d}Help ID: 1{FFFFFF}] {6f757d}xd{FFFFFF}:'{6f757d}{FFFFFF}'

[21:13:14] {FFFFFF}[{6f757d}Help ID: 1{FFFFFF}] {6f757d}xd{FFFFFF}:'{6f757d}{FFFFFF}'

[21:13:14] {FFFFFF}[{6f757d}Help ID: 1{FFFFFF}] {6f757d}xd{FFFFFF}:'{6f757d}{FFFFFF}'

[21:13:14] {FFFFFF}[{6f757d}Help ID: 1{FFFFFF}] {6f757d}xd{FFFFFF}:'{6f757d}{FFFFFF}'

[21:13:14] {FFFFFF}[{6f757d}Help ID: 1{FFFFFF}] {6f757d}xd{FFFFFF}:'{6f757d}{FFFFFF}'

[21:13:14] {FFFFFF}[{6f757d}Help ID: 1{FFFFFF}] {6f757d}xd{FFFFFF}:'{6f757d}{FFFFFF}'

[21:13:14] {FFFFFF}[{6f757d}Help ID: 1{FFFFFF}] {6f757d}xd{FFFFFF}:'{6f757d}{FFFFFF}'

[21:13:14] {FFFFFF}[{6f757d}Help ID: 1{FFFFFF}] {6f757d}xd{FFFFFF}:'{6f757d}{FFFFFF}'

[21:13:14] {FFFFFF}[{6f757d}Help ID: 1{FFFFFF}] {6f757d}xd{FFFFFF}:'{6f757d}{FFFFFF}'

[21:13:14] {FFFFFF}[{6f757d}Help ID: 1{FFFFFF}] {6f757d}xd{FFFFFF}:'{6f757d}{FFFFFF}'

[21:13:15] {FFFFFF}[{6f757d}Help ID: 1{FFFFFF}] {6f757d}xd{FFFFFF}:'{6f757d}{FFFFFF}'



Re: Loading a help list - Logic_ - 27.06.2016

Try something like this, I don't have much experience with MySQL. Make sure you test it with multiple active help msg.

Quote:

format(temp_wat, sizeof (temp_wat), "%s{FFFFFF}[{6f757d}Help ID%d{FFFFFF}] {6f757d}%s{FFFFFF}:'{6f757d}%s{FFFFFF}'",temp_wat, id,temp_sentby,temp_wat);
return SCM