[Tutorial] How to make a report command.
#1

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.

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.
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;
}
Now, for the explanations:
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.
            }
        }
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.
Reply


Messages In This Thread
How to make a report command. - by Leon_Rahil! - 28.01.2011, 00:55
Re: How to make a report command. - by playbox12 - 28.01.2011, 11:27
Re: How to make a report command. - by Leon_Rahil! - 28.01.2011, 19:42
Re: How to make a report command. - by Mean - 28.01.2011, 21:19
Re: How to make a report command. - by Fool - 29.01.2011, 12:34
Re: How to make a report command. - by Mean - 29.01.2011, 15:24
Re: How to make a report command. - by Max_Coldheart - 30.01.2011, 12:54
Re: How to make a report command. - by Not available - 30.01.2011, 13:13
Re: How to make a report command. - by Zh3r0 - 31.01.2011, 18:33

Forum Jump:


Users browsing this thread: 1 Guest(s)