SA-MP Forums Archive
[HELP] Saving Messages - 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: [HELP] Saving Messages (/showthread.php?tid=351845)



[HELP] Saving Messages - Saw® - 17.06.2012

Hi , i want to save all Player's messages, Like whene a player register/login.
& say his first text in (T)
i wanna that the server create a file called PlayerName.txt
then , every message will be saved in that file .
So is that Possible ? i mean , can we save any player's messages . thank you

Sorry for my bad english.


Re: [HELP] Saving Messages - Kindred - 17.06.2012

pawn Код:
public OnPlayerText(playerid, text[])
{
    new PlayerLog[60], Name[MAX_PLAYER_NAME];
    format(PlayerLog, sizeof(PlayerLog), "logs/%s.txt", GetPlayerName(playerid, Name, sizeof(Name));
    new File:playerslog = fopen(PlayerLog, io_append), string[256];
    format(string, sizeof(string), "%s says: %s", GetPlayerName(playerid, Name, sizeof(Name), text);
    fwrite(playerslog, string);
    fclose(playerslog);
    return 1;
}
Very basic, simply creates a file if it doesn't exist, and when the person uses regular chat (not commands) he creates a log with the text he has in it. The name of the file is his name. I'm not even sure if this will work, I simply took this from another script and changed it to my liking.

If you want to make it so when someone uses a command, it adds that to the file, simply tell me and I can create a function that will do the above but also show what command was done.


Re: [HELP] Saving Messages - Saw® - 18.06.2012

THank u a lot ! +++Rep (i will test it )


Re: [HELP] Saving Messages - Saw® - 18.06.2012

Tested but not working i get 1 error for the first "format" & 1error + 1 warning for the second "format"
Код:
C:\DOCUME~1\ADMINI~1\Bureau\FCDA\GAMEMO~1\FCDA.pwn(294) : error 001: expected token: ",", but found ";"
C:\DOCUME~1\ADMINI~1\Bureau\FCDA\GAMEMO~1\FCDA.pwn(296) : warning 202: number of arguments does not match definition
C:\DOCUME~1\ADMINI~1\Bureau\FCDA\GAMEMO~1\FCDA.pwn(296) : error 001: expected token: ",", but found ";"



Re: [HELP] Saving Messages - MadeMan - 18.06.2012

pawn Код:
public OnPlayerText(playerid, text[])
{
    new PlayerLog[60], Name[MAX_PLAYER_NAME], string[256];
    GetPlayerName(playerid, Name, sizeof(Name));
    format(PlayerLog, sizeof(PlayerLog), "logs/%s.txt", Name);
    new File:playerslog = fopen(PlayerLog, io_append);
    format(string, sizeof(string), "%s says: %s\r\n", Name, text);
    fwrite(playerslog, string);
    fclose(playerslog);
    return 1;
}



Re: [HELP] Saving Messages - MarinacMrcina - 18.06.2012

How to make it when a player writs something in it get saved in a new row not all in 1 row?


Re: [HELP] Saving Messages - MadeMan - 18.06.2012

Quote:
Originally Posted by MarinacMrcina
Посмотреть сообщение
How to make it when a player writs something in it get saved in a new row not all in 1 row?
I edited my post.


Re: [HELP] Saving Messages - MarinacMrcina - 18.06.2012

And how can you put a date and time in front of the string that the player said?


Re: [HELP] Saving Messages - MadeMan - 18.06.2012

You can use this Log function

pawn Код:
stock Log(const filename[], const string[])
{
    new hour, minute, second;
    gettime(hour, minute, second);
    new year, month, day;
    getdate(year, month, day);
    new timestamp[32];
    format(timestamp, sizeof(timestamp), "[%02d/%02d/%02d | %02d:%02d:%02d] ", day, month, year, hour, minute, second);
    new File:logfile = fopen(filename, io_append);
    fwrite(logfile, timestamp);
    fwrite(logfile, string);
    fwrite(logfile, "\r\n");
    fclose(logfile);
}
pawn Код:
public OnPlayerText(playerid, text[])
{
    new PlayerLog[60], Name[MAX_PLAYER_NAME], string[256];
    GetPlayerName(playerid, Name, sizeof(Name));
    format(PlayerLog, sizeof(PlayerLog), "logs/%s.txt", Name);
    format(string, sizeof(string), "%s says: %s", Name, text);
    Log(PlayerLog, string);
    return 1;
}



Re: [HELP] Saving Messages - Saw® - 19.06.2012

Quote:
Originally Posted by MadeMan
Посмотреть сообщение
You can use this Log function

pawn Код:
stock Log(const filename[], const string[])
{
    new hour, minute, second;
    gettime(hour, minute, second);
    new year, month, day;
    getdate(year, month, day);
    new timestamp[32];
    format(timestamp, sizeof(timestamp), "[%02d/%02d/%02d | %02d:%02d:%02d] ", day, month, year, hour, minute, second);
    new File:logfile = fopen(filename, io_append);
    fwrite(logfile, timestamp);
    fwrite(logfile, string);
    fwrite(logfile, "\r\n");
    fclose(logfile);
}
pawn Код:
public OnPlayerText(playerid, text[])
{
    new PlayerLog[60], Name[MAX_PLAYER_NAME], string[256];
    GetPlayerName(playerid, Name, sizeof(Name));
    format(PlayerLog, sizeof(PlayerLog), "logs/%s.txt", Name);
    format(string, sizeof(string), "%s says: %s", Name, text);
    Log(PlayerLog, string);
    return 1;
}
thank u a lot!
but 1 question, whene i write a message , it doesn't shown in the screen before 2 or 3 seconds , is it due the code ? but anyway u gave to me a HUGE help thanks.