Detect listitem
#1

I am converting my report system to SQLite.
My question is, how do i detect which report the admin has selected?
can it be done with inputtext? what output will inputtext have?

code:
PHP код:
CMD:pendingreports(playerid,params[])
{
    new 
str[1024], string2[1024], string[1024], szQuery[128], status[25];
    new 
DBResult:REPORTS_RESULT;
    
format(szQuerysizeof(szQuery), "select * from `REPORTS`");
    
REPORTS_RESULT db_query(LARP_DATABASEszQuery);
    if(
AdminLevel[playerid] >=2)
    {
        for(new 
1MAX_REPORTSi++)
        {
            new 
DBResult:REPORTS_RESULT_FINAL;
            new 
reportstatus[5], szQuery2[128];
            
format(szQuery2sizeof(szQuery2), "select * from `REPORTS` where `ID` = '%d'"i);
                
REPORTS_RESULT_FINAL db_query(LARP_DATABASEszQuery2);
            
db_get_field_assoc(REPORTS_RESULT_FINAL"ID"ReportInfo[i][ReportID], 5);
            
db_get_field_assoc(REPORTS_RESULT_FINAL"Status"reportstatussizeof(reportstatus));
            
db_get_field_assoc(REPORTS_RESULT_FINAL"PlayerName"ReportInfo[i][ReportedName], 124);
            
db_get_field_assoc(REPORTS_RESULT_FINAL"Reported"ReportInfo[i][ReportedBy], 124);
            
db_get_field_assoc(REPORTS_RESULT_FINAL"Report"ReportInfo[i][ReportedReason], 124);
            
db_get_field_assoc(REPORTS_RESULT_FINAL"Date"ReportInfo[i][ReportedDate], 124);
               
ReportInfo[i][ReportStatus] = strval(reportstatus);
            
printf(ReportInfo[i][ReportID]);
            
printf(ReportInfo[i][ReportStatus]);
            if(
ReportInfo[i][ReportStatus] == 0) {status="{FF8000}Pending";}
            if(
ReportInfo[i][ReportStatus] == 1) {status="{00CC00}Open";}
            
format(str,sizeof(str),"[%s] #%d\t%s\t%s\t%s\n",ReportInfo[i][ReportedDate], strval(ReportInfo[i][ReportID]), ReportInfo[i][ReportedName], ReportInfo[i][ReportedReason],status);
            
strcat(string2,str);
        }
        
format(str,sizeof(str),"Report ID\tReported Name\tReason\tStatus\n%s"string2);
           
strcat(string,str);
        
ShowPlayerDialog(playeridDIALOG_PENDINGREPORTS+1DIALOG_STYLE_TABLIST_HEADERS"Pending Reports"string"Select""Back");
        
db_free_result(REPORTS_RESULT);
    }
    return 
1;

Reply
#2

When clicking an item in a list, inputtext will be called with the string of the listitem.

I personally use DIALOG_TYPE_TAB_LIST(_HEADERS) for such things, like this:

Код:
ID\tName\tReason\t...
When using Tab List only the first tab will be called, so inputtext will have the ID as text.

For example

Код:
5\tNaS\tHacks
and inputtext will contain "5" as string.

ID in your case would be the ReportInfo index, not the playerid.

edit: Just saw you already did that, so you basically just have to use strval on the inputtext to retrieve the ID.
Reply
#3

* Just noticed that it was already was answered with a better solution than mine.


Create an array with relationship between the listitem and the output ID, and when under OnPlayerDialogResponse you can then get by the listitem the ID
Код:
new relationship[MAX_REPORTS];
cmd:pendingreports()
    for(i)
        db_get_field_assoc(REPORTS_RESULT_FINAL, "ID", relationship[i], 5); 

onDialogResponse(listitem)
    new reportid=relationship[listitem];
Reply
#4

I have a problem with retrieving the id from inputtext.
inputtext returns the number 49.
CharacterMonth[playerid] returns the number 52.

What am i doing wrong?

PHP код:
ShowPlayerDialog(playeridDIALOG_ACCOUNT_REGISTRATION+8DIALOG_STYLE_TABLIST_HEADERS"Character Creation - Select a Month""#\tMonth\n1\tJanuary\n2\tFebruary\n3\tMarch\n4\tApril\n5\tMay\n6\tJune\n7\tJuly\n8\tAugust\n9\tSeptember\n10\tOctober\n11\tNovember\n1\tDecember""Confirm""Close");
         
if(
dialogid==DIALOG_ACCOUNT_REGISTRATION+8)
    {
        if(
response)
        {
            new 
MonthStr[10],MonthStrPrep[10];
            
format(MonthStrPrepsizeof(MonthStrPrep), "%d"inputtext);
            
CharacterMonth[playerid] = strval(MonthStrPrep);
            if(
CharacterMonth[playerid] >= && CharacterMonth[playerid] <= 9)
            {
                
format(MonthStrsizeof(MonthStr), "0%d"CharacterMonth[playerid]);
            } else {
                
format(MonthStrsizeof(MonthStr), "%d"CharacterMonth[playerid]);
            }
            
PlayerTextDrawSetString(playerid,CharacterCreationTD30[playerid],MonthStr);
        }
        return 
1;
    } 
Edit: This fixed it

PHP код:
format(MonthStrPrepsizeof(MonthStrPrep), "%s"inputtext); 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)