SA-MP Forums Archive
report command - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: report command (/showthread.php?tid=200131)



report command - Face9000 - 17.12.2010

Hi all,i maked this report cmd:

Code:
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;
}
But when i compile,my Pawno crashes.

Why?

I've defined the cmd.


Re: report command - Scenario - 17.12.2010

When PAWNO crashes like that it means you have too many errors in your code. It could be here, it could be elsewhere. I don't feel like decoding that code, then putting it back together. I'm only letting you know why PAWNO would crash.


Re: report command - JaTochNietDan - 17.12.2010

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?


Re: report command - Scenario - 17.12.2010

Quote:
Originally Posted by JaTochNietDan
View Post
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?
Oh and you would be better off using sscanf with DCMD/ZCMD. It's so much easier and definitely makes the code look better.


Re: report command - Face9000 - 17.12.2010

Umh so,what i need to do?


Re: report command - Scenario - 17.12.2010

You may wish to study this code further. This does all you wanted it to do, even though it looks completely different.

pawn Code:
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;
}



Re: report command - WillyP - 17.12.2010

Quote:
Originally Posted by RealCop228
View Post
Oh and you would be better off using sscanf with DCMD/ZCMD. It's so much easier and definitely makes the code look better.
Quote:
Originally Posted by Logitech90
View Post
Umh so,what i need to do?
lrn2read?