Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <sscanf2>
- #include <zcmd>
- #define MAX_REPORTES 50
- #define MAX_REPORT_STRING 128
- new playerReport[MAX_PLAYERS];
- enum Reportes{
- reporteExiste,
- reportePara[MAX_PLAYER_NAME],
- reporteDe,
- reporteRazon[MAX_REPORT_STRING]
- }
- new ReportData[MAX_REPORTES][Reportes];
- main()
- {
- }
- #define ReportExist(%1) (ReportData[%1][reporteExiste])
- #define CompareString(%1:%2) ((!isnull(%1) || !isnull(%2)) && !strcmp(%1, %2, true))
- #define IsValidReport(%1) ((0 <= %1 < MAX_REPORTES) && ReportExist(%1))
- #define getReportValue(%1->%2) (ReportData[%1][%2])
- stock deleteReportsBy(playerid)
- {
- new
- count = 0
- ;
- if(!IsPlayerConnected(playerid))
- return count;
- new nombre_1[MAX_PLAYER_NAME];
- format(nombre_1, sizeof(nombre_1), GetPlayerNameEx(playerid));
- new nombre_temp[MAX_PLAYER_NAME];
- for(new i; i < sizeof(ReportData); i++) if(ReportExist(i))
- {
- if(!(0 <= ReportData[i][reporteDe] < MAX_PLAYERS))
- continue;
- format(nombre_temp, sizeof(nombre_temp), GetPlayerNameEx(ReportData[i][reporteDe]));
- if(!CompareString(nombre_1:nombre_temp))
- continue;
- DeleteReport(i);
- count ++;
- }
- return count;
- }
- stock DeleteReport(id)
- {
- if(IsValidReport(id))
- return 0;
- ReportData[id][reporteExiste] = false;
- ReportData[id][reportePara][0] = '\0';
- ReportData[id][reporteDe] = INVALID_PLAYER_ID;
- ReportData[id][reporteRazon][0] = '\0';
- return 1;
- }
- stock CreateReport(playerid, reportado, razon[])
- {
- for(new i; i < sizeof(ReportData); i++)
- {
- if(ReportExist(i))
- continue;
- ReportData[i][reporteExiste] = true;
- format(ReportData[i][reportePara], MAX_PLAYER_NAME, GetPlayerNameEx(reportado));
- ReportData[i][reporteDe] = playerid;
- format(ReportData[i][reporteRazon], MAX_REPORT_STRING, razon);
- return i;
- }
- return -1;
- }
- CMD:reportar(playerid, params[])
- {
- new
- reportado,
- razon[MAX_REPORT_STRING];
- if(sscanf(params, "ds[MAX_REPORT_STRING]", reportado, razon))
- return SendClientMessage(playerid, 0xFFFFFFFF, "Utilice /reportar [playerid] [razon]");
- new reportID = CreateReport(playerid, reportado, razon);
- if(reportID == -1)
- return SendClientMessage(playerid, 0xFFFFFFFF, "Ahora mismo hay muchos reportes, por favor espere a que sean contestados.");
- SendClientMessage(playerid, 0xFFFFFFFF, "Tu reporte se ha enviado con exito!, espera a que sea respondido.");
- return 1;
- }
- CMD:reportes(playerid, params[])
- {
- return ShowPlayerReports(playerid);
- }
- stock cutMessage(str[])
- {
- new _str[128];
- if(strlen(str) > 20)
- {
- format(_str, sizeof(_str), "%.20s ...", str);
- }
- else
- {
- format(_str, sizeof(_str), "%s", str);
- }
- return _str;
- }
- stock ShowPlayerReports(playerid)
- {
- new
- string[1024],
- count = 0,
- index[64]
- ;
- format(string, sizeof(string), "Reporte #\tUsuario\tReportado\tRazon");
- for(new i; i < sizeof(ReportData); i++)
- {
- if(!ReportExist(i))
- continue;
- format(string, sizeof(string), "%s\n#%i\t%s\t%s\t%s",
- string,
- i,
- GetPlayerNameEx(getReportValue(i->reporteDe)),
- getReportValue(i->reportePara),
- cutMessage(getReportValue(i->reporteRazon))
- );
- format(index, sizeof(index), "_report_%i", count);
- SetPVarInt(playerid, index, i);
- count++;
- }
- if(!count)
- return SendClientMessage(playerid, 0xFFFFFFFF, "No hay reportes activos!");
- ShowPlayerDialog(playerid, 5, DIALOG_STYLE_TABLIST_HEADERS, "Reportes", string, "Detalles", "Cancelar");
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(dialogid == 5)
- {
- new index[64];
- format(index, sizeof(index), "_report_%i", listitem);
- new reportid = GetPVarInt(playerid, index);
- if(!IsValidReport(reportid))
- return SendClientMessage(playerid, 0xFFFFFFFF, " El reporte ya habra sido contestado, o el jugador que reporta desconectado.");
- new String[128];
- format(String, sizeof(String), "Reporte ID: #%i\n\nReportado %s\nPor: %s\nRazon: %s",
- reportid,
- GetPlayerNameEx(getReportValue(reportid->reporteDe)),
- getReportValue(reportid->reportePara),
- getReportValue(reportid->reporteRazon)
- );
- ShowPlayerDialog(playerid, 10, DIALOG_STYLE_MSGBOX, "Reporte", String, "Aceptar", "Rechazar");
- }
- return 1;
- }
- stock GetPlayerNameEx(playerid)
- {
- new name[MAX_PLAYER_NAME];
- GetPlayerName(playerid, name, sizeof(name));
- return name;
- }
- public OnPlayerConnect(playerid)
- {
- playerReport[playerid] = -1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- new res = deleteReportsBy(playerid);
- if(res > 0)
- {
- playerReport[playerid] = -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement