dcmd_report(playerid, params[]) ( new tmp3[128]; tmp3 = strtok(cmdtext, idx); if(!strlen(tmp3)) { SendClientMessage(playerid, COLOR_ORANGE, "USAGE: /report [name/id] [reason]"); return 1; } new targetid = ReturnUser(tmp3); if(targetid != INVALID_PLAYER_ID) { new msg[128],giveplayername[128]; GetPlayerName(targetid, giveplayername, sizeof(giveplayername)); GetPlayerName(playerid, sendername, sizeof(sendername)); new reason[128]; reason = bigstrtok(cmdtext, idx); if(!strlen(reason)) return SendClientMessage(playerid, COLOR_ORANGE, "USAGE: /report [playerid] [reason]"); new string[128]; format(string, sizeof(string), "%s reported %s [ID: %d] [ Reason: %s ]", sendername,giveplayername,targetid,reason); SendMessageToAdmins(COLOR_RED, string); print(string); format(string, sizeof(string), "Your report on '%s' has been sent to the current online admins. Thank you.", giveplayername); SendClientMessage(playerid, COLOR_GREEN, string); format(msg,sizeof(string),"%s reported %s [ID: %d] (%s)", sendername,giveplayername,targetid,reason); ReportLog(string); IRC_GroupSay(gGroupID, IRC_CHANNEL, msg); } else if(giveplayerid == INVALID_PLAYER_ID) { new string[128]; format(string, sizeof(string), "%d is not an active player.", giveplayerid); SendClientMessage(playerid, COLOR_RED, string); } return 1; }
Well for one thing why are you using strtok and creating a new variable to store the parameters from cmdtext, especially when cmdtext isn't in that scope? You have params[] in that scope, which is what you're trying to use strtok to extract from cmdtext (which doesn't exist in that scope) and then store in tmp3!
So instead of tmp3 or strtok, why not just use params directly? |
dcmd_report(playerid, params[]) // Credits to "RealCop228" //
{
new id, message[118], string[128];
if(sscanf(params, "us[118]", id, message)) // If the params don't match up, we'll tell them the correct syntax/usage.
return SendClientMessage(playerid, COLOR_ORANGE, "SYNTAX: /report [nick/id] [comment]");
if(id == INVALID_PLAYER_ID || !IsPlayerConnected(id)) // We'll check if the reported player is invalid, or not connected.
return SendClientMessage(playerid, COLOR_RED, "ERROR: That player is not connected!");
if(strlen(message) > 118) // We don't want to send a message which won't fit on the line being sent to the admins!
return SendClientMessage(playerid, COLOR_RED, "ERROR: Invalid Comment Length! Max Characters: 118");
new pName[MAX_PLAYER_NAME], iName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
GetPlayerName(id, iName, sizeof(iName));
// Let's send to the admins, IRC and the server console!
format(string, sizeof(string), "REPORT: %s(%d) has reported %s(%d).", pName, playerid, iName, id);
SendMessageToAdmins(COLOR_RED, string);
print(string); ReportLog(string); IRC_GroupSay(gGroupOD, IRC_CHANNEL, string); // You really don't need to format 2 more strings...
format(string, sizeof(string), "Comment: %s", comment);
SendMessageToAdmins(COLOR_RED, string);
print(string); ReportLog(string); IRC_GroupSay(gGroupOD, IRC_CHANNEL, string);
// Let's notify a successful report!
format(string, sizeof(string), "Your report on \"%s(%d)\" has been logged and sent to the online admins. Thank you!", iName, id);
SendClientMessage(playerid, COLOR_GREEN, string);
return 1;
}
Oh and you would be better off using sscanf with DCMD/ZCMD. It's so much easier and definitely makes the code look better.
|