SA-MP Forums Archive
Best way to log commands - 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)
+--- Thread: Best way to log commands (/showthread.php?tid=548955)



Best way to log commands - LeXuZ - 03.12.2014

Hello, I've been thinking about making a logging command system for my server, I wanted it to log every command that is used, but I've looked thought some of the logging and I wanted something different, I wanted it so it will auto log, lets say, I banned someone it would do, '[03/12/2014][18:57] Administrator LeXuZ banned Player for hacks'.
If so can you help me out here.

So lets say another admin mutes someone it will say

'[03/12/2014][19:00] Administrator LeXuZ muted Player for 5 minutes: spam'
But i wouldn't have to write another logging code to get what has been done, if you get what i mean.
If you are able to help, that would be great! thank you


Re: Best way to log commands - Schneider - 03.12.2014

In case you use ZCMD.

Just replace the admintitle and name variables with the ones you are using:
pawn Код:
public OnPlayerCommandPerformed(playerid, cmdtext[], success)
{
    new Year, Month, Day, Hour, Minute, Second;
    getdate(Year, Month, Day);
    gettime(Hour, Minute, Second);
    printf("[%02d/%02d/%d][%02d:%02d:%02d] - %s %s performed command: %s", Day, Month, Year, Hour, Minute, Second, AdminTitle[playerid], PlayerName[playerid], cmdtext);
    return 1;
}
..or you can put that code under OnPlayerCommandText if you're using that.


Re: Best way to log commands - LeXuZ - 03.12.2014

But is there a way to log it like
[03/12/2014][18:57] Administrator LeXuZ banned Player for hacks
for would i have to go and log that myself ?


Re: Best way to log commands - Misiur - 03.12.2014

For each command you want specific log, yup, you'd have to do it for every one of them.


Re: Best way to log commands - LeXuZ - 03.12.2014

Ok, thanks for the help!


Re: Best way to log commands - Schneider - 03.12.2014

pawn Код:
#define CMD_BAN 0
#define CMD_KICK 1
#define CMD_MUTE 2
#define CMD_FREEZE 3

stock LogCommand(playerid, giveplayerid, command, params[]= " ")
{
    new Year, Month, Day, Hour, Minute, Second, pname[24], gname[24], str[128], date[32];
    getdate(Year, Month, Day);
    gettime(Hour, Minute, Second);
    GetPlayerName(playerid, pname, 24);
    GetPlayerName(giveplayerid, gname, 24);
    format(date, sizeof(date), "[%02d/%02d/%d][%02d:%02d:%02d]", Day, Month, Year, Hour, Minute, Second);
    switch (command)
    {
        case 0:  format(str, 128, "%s - %s %s banned %s. Reason: %s", date, AdminNames[PlayerInfo[playerid][P_AdminLevel]], pname, gname, params);
        case 1:  format(str, 128, "%s - %s %s kicked %s. Reason: %s", date, AdminNames[PlayerInfo[playerid][P_AdminLevel]], pname, gname, params);
        case 2:  format(str, 128, "%s - %s %s muted %s. Reason: %s", date, AdminNames[PlayerInfo[playerid][P_AdminLevel]], pname, gname, params);
        case 3:  format(str, 128, "%s - %s %s froze %s. Reason: %s", date, AdminNames[PlayerInfo[playerid][P_AdminLevel]], pname, gname, params);
    }
    print(str);
}
So, like Misiur said, you have to add a 'case' and a define for each command.

Then in each command you want to log you add the LogCommand-function. Example:

pawn Код:
COMMAND:kick(playerid, params[])
{
    if(!HasPermission(playerid, CMD_kick)) return SCM(playerid, COLOR_ERROR, ERROR_NO_PERMISSION);
    new targetID, reason[32], str[128];
    if(sscanf(params, "ds[32]", targetID, reason)) return SCM(playerid, COLOR_ERROR, "[Error] - Use: /kick [id] [reason]");
    if(!IsPlayerConnected(targetID)) return SCM(playerid, COLOR_ERROR, ERROR_PLAYER_NOT_CONNECTED);
    format(str, sizeof(str), "You have been kicked by %s %s. Reason: %s", AdminNames[PlayerInfo[playerid][P_AdminLevel]], PlayerInfo[playerid][P_Name], reason);
    SCM(targetID, COLOR_PENALTY, str);
    SetTimerEx("KickBanPlayer", 2000, 0, "ii", targetID, KICK);
    LogCommand(playerid, targetID, CMD_KICK, reason);  
    return 1;
}