Command Log
#1

Hello how can i make a Log file from all Commands from the players ?

how can I create a log file from the server command which a player enters?
Reply
#2

Use Y_ini.
Reply
#3

OnPlayerCommandText
printf("Player (id=%d) typed the command=%s", playerid, cmdtext);

And it will save it to your server log file
Reply
#4

What the person above me said, OR if you want commands in specific files:
pawn Код:
stock LogCommand(event[])
{
  new File:log = fopen("command_log.txt", io_append);
  fwrite(log, event);
  fwrite(log, "\n");
  fclose(log);
}
Should work by 'LogCommand();', however I did not test the code.

Example usage:

pawn Код:
COMMAND:heal(playerid, params[])
{
  new target;
  if(sscanf(params, "u", target)) return SendClientMessage(playerid, 0x00ff0f00, "Usage: /heal [playerid/name]");
  else if(target == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0x00ff0f00, "Invalid player!");
  SetPlayerHealth(target, 100);
  new gName[MAX_PLAYER_NAME], string[128];
  GetPlayerName(target, gName, MAX_PLAYER_NAME);
  GetPlayerName(playerid, string, MAX_PLAYER_NAME);
  format(string, sizeof string, "[HEAL] %s has healed %s", string, gName); //Important: Formats the string to log
  CommandLog(string); //Log the string
  return 1;
}
Hope that kind of explained it to you.
Reply
#5

thanks,

I would like when a player join the server it in the log file so:

Player (ID:5) joined the server

i want the ID in the Log so can i see in the log how many Players played today on tzhe server
Reply
#6

You don't need to create necessary files in your folder, that means more disk-space, however, you may try printing to server_log.txt in your server directory.

On top:

pawn Код:
new PlayerCount = 0;
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    new playername[24];
    GetPlayerName(playerid, playername, 24);
    printf("[cmd] %s(%d): %s", playername, playerid, cmdtext);
    return 0;
}
And for connecting:

pawn Код:
public OnPlayerConnect(playerid)
{
    new ip[16], playername[24];
    GetPlayerIp(playerid, ip, 16);
    GetPlayerName(playerid, playername, 24);
    printf("%s (ID: %i) (IP: %s) has joined the server!", playername, playerid, ip);
    PlayerCount++;
    printf("Total players connected since server startup: %i",PlayerCount);
    return 1;
}
Reply
#7

thx woks!

now i want when my server starts print the Date/Year in the Server Log,

(Server successfully starts 26.02.2011)

can everyone help
Reply
#8

https://sampwiki.blast.hk/wiki/Getdate
https://sampwiki.blast.hk/wiki/Gettime
https://sampwiki.blast.hk/wiki/printf
Reply
#9

print("Server startet: %02d/%02d/%d", Day, Month, Year);

have 3 Warnings :

Код:
E:\pwn(518) : warning 202: number of arguments does not match definition
E:\pwn(518) : warning 202: number of arguments does not match definition
E:\pwn(518) : warning 202: number of arguments does not match definition
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


3 Warnings.
Reply
#10

printf
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)