28.01.2011, 00:55
(
Last edited by Leon_Rahil!; 28/01/2011 at 02:12 AM.
)
This tutorial is to show you how to make a report command. You shouldn't wonder why, "Well, why must I need a report command?" But, I'm positive that there are many people around there who will ask this question, so I'll answer it in the shortest way possible: Hackers travel all over SA:MP, looking for servers to hack in. Now, most servers don't allow the use of 'hacks'. So, they'd like to ban all the hackers they meet. Or maybe there's a rule-breaker and it's beginning to irritate players... therefore they'd like to get into contact with the administrators without the rule-breaker or hacker seeing so.
Now, for the explanations:
Thank you for reading this tutorial, it's my first tutorial and I made it because of the fact that nobody's ever made one on a report command. I know it's an easy command to create, I thought I might make one for all the pawn n00bs, though.
Please note: This tutorial uses dini, dudb, dutils, zcmd, and sscanf2.
For ZCMD, go here.
For sscanf2, go here.
For dini, go here.
For dutils, go here.
For dudb, go here.
For ZCMD, go here.
For sscanf2, go here.
For dini, go here.
For dutils, go here.
For dudb, go here.
pawn Code:
CMD:report(playerid, params[])
{
new pName[MAX_PLAYER_NAME], aName[MAX_PLAYER_NAME], str[128], reason, iD;
if (sscanf(params, "dz", iD, reason)) return SendClientMessage(playerid, 0xAA3333AA, "Usage: /report [id] [reason]");
if (iD == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xAA3333AA, "Invalid ID.");
if (playerid == iD) return SendClientMessage(playerid, 0xAA3333AA, "You can't report yourself.");
GetPlayerName(playerid, pName, sizeof(pName));
GetPlayerName(iD, aName, sizeof(aName));
for (new i = 0; i < MAX_PLAYERS; i++)
{
if (IsPlayerConnected(i))
{
new zName[MAX_PLAYER_NAME], pFile[256];
GetPlayerName(i, zName, sizeof(zName));
format(pFile, sizeof(pFile), "Users\%s.ini", zName);
if (IsPlayerAdmin(i) || dini_Int(pFile, "AdminLevel") >= 1)
{
format(str, sizeof(str), "%s(%d) has reported %s(%d) for: %s", pName, playerid, aName, iD, reason);
SendClientMessage(i, 0xFFFFFFFF, str);
}
}
}
return 1;
}
pawn Code:
CMD:report(playerid, params[]) // States that the command is /report and it 'may' have extra parameters (which it will.)
{
return 1; // Returns 1 and shows that the command is real and must always work.
}
pawn Code:
new pName[MAX_PLAYER_NAME], aName[MAX_PLAYER_NAME], str[128], reason, iD; // Declares the local variables: pName, aName, str, reason, and iD.
if (sscanf(params, "dz", iD, reason)) return SendClientMessage(playerid, 0xAA3333AA, "Usage: /report [id] [reason]"); // States that sscanf is declares that there ARE going to be parameters, and if there aren't any, it'll return a message saying the 'syntax' of the command. The operators "dz" declare that d = integer, and z is a string that states an optional message.
if (iD == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xAA3333AA, "Invalid ID."); // Checks if the ID is invalid, and if so, it'll return a message telling the player who used the command so.
if (playerid == iD) return SendClientMessage(playerid, 0xAA3333AA, "You can't report yourself."); // Checks if the player is trying to report himself, and if so, tell him that he can't report himself.
GetPlayerName(playerid, pName, sizeof(pName)); // Gets the player's name.
GetPlayerName(iD, aName, sizeof(aName)); // Gets the ID's name. (The ID of the player who is being reported).
pawn Code:
for (new i = 0; i < MAX_PLAYERS; i++) // Calls the 'for' function, this function states that it will check all player slots and assigns each slot to a variable, in this case, it's going to assign the variable i.
{
if (IsPlayerConnected(i)) // Checks if the slot is being used.
{
new zName[MAX_PLAYER_NAME], pFile[256]; // Declares new definitions.
GetPlayerName(i, zName, sizeof(zName)); // Gets the name of the slots' user.
format(pFile, sizeof(pFile), "Users\%s.ini", zName); // Formats the player file, change what's in the quotes to the correct destination. (This is only needed if you're using DINI);
if (IsPlayerAdmin(i) || dini_Int(pFile, "AdminLevel") >= 1) // Checks if the player is an RCON admin or if the player is an admin on the player's file, (dini_Int is only required if you're using DINI).
{
format(str, sizeof(str), "%s(%d) has reported %s(%d) for: %s", pName, playerid, aName, iD, reason); // formats the variable 'str,' into a string.
SendClientMessage(i, 0xFFFFFFFF, str); // Sends the string to all online admins.
}
}