[Tutorial] /report command.
#1

WELCOME :]
So, today i will try to teach you, how to make an /report command!
First of all, you will need sscanf and zCMD
Links:
ZCMD: https://sampforum.blast.hk/showthread.php?tid=91354
SSCANF: https://sampforum.blast.hk/showthread.php?tid=120356
Getting started
Now, you need to set the zcmd's .ini file in pawno -> include
The sscanf file will have folders, just drag them in your folder, where you have the pawno etc.
You will also need to add sscanf in your server.cfg file (plugins sscanf)
Now, do #include <sscanf2> and #include <zcmd> under the <a_samp> include.
COLOR DEFINES
You will need these color defines.
Add them under your includes.
#define COLOR_ORANGE 0xFF9900AA
#define COLOR_LIME 0x10F441AA
define / include check
This is how it looks for me
pawn Code:
#include <a_samp>
#include <zcmd>
#include <sscanf2>
#define COLOR_ORANGE 0xFF9900AA
#define COLOR_LIME 0x10F441AA
STARTING SCRIPTING
pawn Code:
CMD:report(playerid, params[]) {
The base of the command.
It will trigger when a player types 'report'

pawn Code:
new id;
    new reason[128];
    if(sscanf(params, "us[128]", id, reason)) return SendClientMessage(playerid, COLOR_ORANGE, "[SERVER] - USAGE: /report [ID] [REASON]");
But if the player won't know how to type the command fully, this will show up.
new id; 'defines' the targets id, and new reason[128]; is a string for the reason.
pawn Code:
new string[150], sender[MAX_PLAYER_NAME], receiver[MAX_PLAYER_NAME];
    GetPlayerName(playerid, sender, sizeof(sender));
    GetPlayerName(id, receiver, sizeof(receiver));
These strings will 'get' the senders(playerids) name/id, and the receivers(id/target) name/id.
GetPlayerName playerid sender etc etc will get the players name / id.
GetPlayerName id receiver etc etc will get the targets name / id.
pawn Code:
format(string, sizeof(string), "[ADMIN] - %s(%d) has reported %s(%d)", sender, playerid, receiver, id);
    SendMessageToAdmins(string);
    format(string, sizeof(string), "[ADMIN] - Reason: %s", reason);
    SendMessageToAdmins(string);
This will send the report message, to the admins.
It will look like ->
[ADMIN] - PlayerName(playerid) has reported TargetName(TargetID)
[ADMIN] - Reason: reason here.
pawn Code:
SendClientMessage(playerid, COLOR_ORANGE, "Your report has been sent.");
    return 1;
}
And then the server will send a message to the player, saying that the report was sent.
SendMessageToAdmins
We need to make it, so the RCON Admins are actually able to see the report.
By that we will need to add this stock:

pawn Code:
stock SendMessageToAdmins(text[])
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerAdmin(i))
        {
            SendClientMessage(i, COLOR_LIME, text);
        }
    }
}
This will loop trough the players/rcon admins, and will send the report message"SendMessageToAdmins"
NOTE: The SendMessageToAdmins can be also used for admin chats.
Well, i hope that i some-what helped you.
PREVIEW.
[ame]www.youtube.com/watch?v=MlRjzEoFBaI[/ame]
FULL CODE
pawn Code:
CMD:report(playerid, params[]) {
    new id;
    new reason[128];
    if(sscanf(params, "us[128]", id, reason)) return SendClientMessage(playerid, COLOR_ORANGE, "[SERVER] - USAGE: /report [ID] [REASON]");
    new string[150], sender[MAX_PLAYER_NAME], receiver[MAX_PLAYER_NAME];
    GetPlayerName(playerid, sender, sizeof(sender));
    GetPlayerName(id, receiver, sizeof(receiver));
    format(string, sizeof(string), "[ADMIN] - %s(%d) has reported %s(%d)", sender, playerid, receiver, id);
    SendMessageToAdmins(string);
    format(string, sizeof(string), "[ADMIN] - Reason: %s", reason);
    SendMessageToAdmins(string);
    SendClientMessage(playerid, COLOR_ORANGE, "Your report has been sent.");
    return 1;
}
Reply
#2

Not a bad tutorial


Off topic now. Why don't people stock the GetPlayerName function instead of having to get the player name each time.

pawn Code:
stock Name(playerid)
{
    new n[MAX_PLAYER_NAME];
    GetPlayerName(playerid,n,sizeof(n));
    return n;
}
Reply
#3

Nice tutorial
will be usefull for newbies
Reply
#4

Quote:
Originally Posted by DobbysGamertag
View Post
Not a bad tutorial


Off topic now. Why don't people stock the GetPlayerName function instead of having to get the player name each time.

pawn Code:
stock Name(playerid)
{
    new n[MAX_PLAYER_NAME];
    GetPlayerName(playerid,n,sizeof(n));
    return n;
}
Then it'll become:
pawn Code:
CMD:report(playerid,params[])
{
    new pid,reason[60],string[124];
    if(sscanf(params,"us[60]",pid,reason))return SendClientMessage(playerid,COLOR_ORANGE,"[SERVER] - USAGE /report [id][reason]");
    format(string,124,"[ADMIN] %s (%d) has reported %s (%d)",Name(playerid),playerid,Name(pid),pid);
    SendMessageToAdmins(string);
    format(string,124,"[ADMIN]  - Reason: %s",reason);
    SendMessageToAdmin(string);
    SendClientMessage(playerid,COLOR_ORANGE,"Your report has been sent");
    return 1;
}
Wrote it quick so im not sure if it'll compile without errors. But you get the idea?
Honestly, your method is worse. Do you want to know why?

Let's say in a command you need to show 4 messages with the playerid's name. By using his method, he would call GetPlayerName only 1 time and your stock would call GetPlayerName 4 times. I hope you get what I mean.

The best way is to get the name ONLY 1 time on connect and use it later on.

pawn Code:
new
    Name[ MAX_PLAYERS ][ MAX_PLAYER_NAME ]
;

// OnPlayerConnect:
GetPlayerName( playerid, Name[ playerid ], MAX_PLAYER_NAME );

// Everywhere else:
format(string,124,"[ADMIN] %s (%d) has reported %s (%d)",Name[playerid],playerid,Name[pid],pid);
Reply
#5

WOW!!!
Kyance very nice tutorial

mate add me on skype i want to talk with you i just want to talk with you like old days
Skype:efrim142
Reply
#6

Quote:
Originally Posted by efrim123
View Post
WOW!!!
Kyance very nice tutorial

mate add me on skype i want to talk with you i just want to talk with you like old days
Skype:efrim142
Friend request sent, also, thanks everyone.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)