[Tutorial] Log - 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)
+---- Forum: Tutorials (
https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] Log (
/showthread.php?tid=297522)
Log -
Elka_Blazer - 16.11.2011
Log Tutorial
This is an easy Tutorial for you , teachs you how to create a log file !
I will now post the code then explane
pawn Код:
forward Log(logtype[],string[]);
public Log(logtype[],string[])
{
new File: LogFile = fopen(logtype,io_append);
new stringformat[256];
format(stringformat,sizeof(stringformat),"%s\r\n",string);
fwrite(LogFile,stringformat);
fclose(LogFile);
return 1;
}
So , on the public , the logtype[] is a string ( parameter ) that will contain the name of the log .
What do I mean ? If I want to input the string into a log ( .txt ) file , that named "samp.txt",I will put "samp.txt"
new File: LogFile = fopen(logtype,io_append);
it means , that we create a new file variable named LogFile.
That variable will open the 'logtype' we entered , in append mode .
Append mode means it will add a string to the .txt file without deleteing the other strings.
new stringformat[256];
format(stringformat,sizeof(stringformat),"%s\r\n", string);
Creating a string named stringformat, that will hold the variable "string[]" that you created with the public .
format .......... we gonna input the "string[]" into the variable "stringformat" .... the "%s\r\n" means :
%s = string ,
\r\n = we gotta make a new line .
if we wont add this %s\r\n
it will just be in 1 line , example :
"tonny was kicked by andrey " and right after it "sasa was kicked by sarasr" so it will be
"tonny was kicked by andreysasa was kicked by sarasr"
fwrite(LogFile,stringformat);
Here we are the "stringformat" text to the file that the variable "LogFile" is holding .
fclose(LogFile);
Just like a door , when you open a file you need to close it right ?
return 1;
return a valid value ?
Now how do I use this ****?
Lets say you got the "kick" command
After I kicked the player and all thats , and used sendclientmessagetoall or whatever ..
I want to put the line into the log
so
lets say on the CMD kick I got the variable string[256];
now we gonna format the string
pawn Код:
new year, month,day;
getdate(year, month, day);//get the date
new kName[MAX_PLAYER_NAME],pName[MAX_PLAYER_NAME];
GetPlayerName(playerid,pName,sizeof(pName));//Get the player's name ( the kicker )
GetPlayername(playerid,kName,sizeof(kName));//Get the player's name ( the kickeD )
//Now that we got all the info
format(string,sizeof(string),"%d-%d-%d : %s was kicked by %s ",year,month,day,kName,pName);
Log("kick.txt",string); // we gotta input the string into the kick.txt file
Thats it with the tutroial ... now for the tip :
If you want to create the log file in another folder ( not in scriptfiles ) then do the next steps :
goto your scriptfiles folder
create any folder there and name it as you wish
create the kick file ( optional )
now when u use the log function it should be like that
Log("logsfolder/kick.txt",string);
so lets say you named your folder logsfolder and after it comes the /kick.txt
KK I hope I helped you ! ( BTW Im sorry for my bad english )
Re: Log - Astralis - 16.11.2011
fix the word tutorial at this post :P
Nice tutorial man. How long you spent on making it ?
Re: Log -
Elka_Blazer - 16.11.2011
Quote:
Originally Posted by Neonman
fix the word tutorial at this post :P
Nice tutorial man. How long you spent on making it ?
|
TY
and about 20 minutes .
Re: Log -
kevinhbk1 - 24.12.2011
Lol....anyway nice .... Can u plz tell how to make it as a filterscript
.....so dat i can use it for ma server
Hope u will help...... Tnx
Re: Log -
kevinhbk1 - 24.12.2011
Lol....anyway nice .... Can u plz tell how to make it as a filterscript
.....so dat i can use it for ma server
Hope u will help...... Tnx
Re: Log -
System64 - 26.12.2011
https://sampforum.blast.hk/showthread.php?tid=264770
what's that?
Re: Log -
d0nTtoucH - 14.04.2014
not working -_-
creates the kick.txt and nothing is empty
when i kick someone it actually makes empty lines ;d
will you fix this ? or should i report your topic ..
Re: Log -
Konstantinos - 14.04.2014
Just a note: Check if the file handle is valid before
writing to/closing the file because if it's not, the server will crash.
pawn Код:
new File: LogFile = fopen(logtype,io_append);
...
if (LogFile)
{
fwrite(LogFile,stringformat);
fclose(LogFile);
}
Re: Log -
Lordzy - 15.04.2014
A boolean being added as parameter whether to store date/time before writing the log text would make things much more easier.
(Yes, this is an old topic)