Detect listitem -
jasperschellekens - 21.02.2018
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(szQuery, sizeof(szQuery), "select * from `REPORTS`");
REPORTS_RESULT = db_query(LARP_DATABASE, szQuery);
if(AdminLevel[playerid] >=2)
{
for(new i = 1; i < MAX_REPORTS; i++)
{
new DBResult:REPORTS_RESULT_FINAL;
new reportstatus[5], szQuery2[128];
format(szQuery2, sizeof(szQuery2), "select * from `REPORTS` where `ID` = '%d'", i);
REPORTS_RESULT_FINAL = db_query(LARP_DATABASE, szQuery2);
db_get_field_assoc(REPORTS_RESULT_FINAL, "ID", ReportInfo[i][ReportID], 5);
db_get_field_assoc(REPORTS_RESULT_FINAL, "Status", reportstatus, sizeof(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(playerid, DIALOG_PENDINGREPORTS+1, DIALOG_STYLE_TABLIST_HEADERS, "Pending Reports", string, "Select", "Back");
db_free_result(REPORTS_RESULT);
}
return 1;
}
Re: Detect listitem -
NaS - 21.02.2018
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
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.
Re: Detect listitem -
Kaperstone - 21.02.2018
* 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];
Re: Detect listitem -
jasperschellekens - 01.05.2018
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(playerid, DIALOG_ACCOUNT_REGISTRATION+8, DIALOG_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(MonthStrPrep, sizeof(MonthStrPrep), "%d", inputtext);
CharacterMonth[playerid] = strval(MonthStrPrep);
if(CharacterMonth[playerid] >= 1 && CharacterMonth[playerid] <= 9)
{
format(MonthStr, sizeof(MonthStr), "0%d", CharacterMonth[playerid]);
} else {
format(MonthStr, sizeof(MonthStr), "%d", CharacterMonth[playerid]);
}
PlayerTextDrawSetString(playerid,CharacterCreationTD30[playerid],MonthStr);
}
return 1;
}
Edit: This fixed it
PHP код:
format(MonthStrPrep, sizeof(MonthStrPrep), "%s", inputtext);