[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
#2

Maybe some people may find it usefull, but I rather think they will just copy it without thinking also you should use foreach instead of regular player loops; its way more effecient and faster!
Reply
#3

Quote:
Originally Posted by playbox12
View Post
Maybe some people may find it usefull, but I rather think they will just copy it without thinking also you should use foreach instead of regular player loops; its way more effecient and faster!
I understand what you mean, but I've never really tried out foreach by ******. Yes, it seems like a good idea but I'd rather use for();.
Reply
#4

You could make it simpler, but it's explaining what it does.
Reply
#5

Why Didn't You make it With Y_Ini?
Reply
#6

Nah, he could just use deufaults: fwrite, fclose... I got a stock for SaveToFile(filename, string), It uses deufaults, fwrite, fclose...
Reply
#7

Copied it, Errors:

pawn Code:
C:\Users\Max\Desktop\GTA San Andreas\samp03csvr_win32\gamemodes\TDM.pwn(113) : error 029: invalid expression, assumed zero
C:\Users\Max\Desktop\GTA San Andreas\samp03csvr_win32\gamemodes\TDM.pwn(113) : error 017: undefined symbol "cmd_report"
C:\Users\Max\Desktop\GTA San Andreas\samp03csvr_win32\gamemodes\TDM.pwn(113) : error 029: invalid expression, assumed zero
C:\Users\Max\Desktop\GTA San Andreas\samp03csvr_win32\gamemodes\TDM.pwn(113) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


4 Errors.
Reply
#8

Why do you even call this a tutorial?
Reply
#9

This is rather simplier.

pawn Code:
CMD:report(playerid, params[])
{
    if ( sscanf( params, "us", params[ 0 ], params[ 1 ] ) )
        return SendUsage( playerid, "/report <Player's Name/ID> [report message]");
    FormMessage( playerid, COLOR_PINK, "You reported %s to the Administrators, the report has been saved into a file!",PlayerName2( params[ 0 ] ) );

    new S,M,H,D,Mo,Y,STTRR[512],File:file;
    file = fopen("Administration/Extras/Reports.txt", io_append);
    getdate(Y,Mo,D),gettime(H,M,S);
    format(STTRR, sizeof( STTRR ), "[DATE: %d/%d/%d] [TIME: %d/%d/%d]: Player %s reported %s(ID:%i) for:\r\n%s\r\n---------------------------------------------------------------------------------------------------------------------\r\n",D,Mo,Y,H,M,S,PlayerName2( playerid ), PlayerName2( params[ 0 ] ), params[ 0 ], params[ 1 ] );
    if (file)
    {
        fwrite(file, STTRR);
        fclose(file);
    }
    return 1;
}
Everybody has PlayerName2.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)