How to Make Logs -
RichyB - 17.07.2010
Hey, the name is RichyB and this is the Tutorial on how to make Logs for your server.
This is my First Tutorial
I will be using the Grand Larceny Script for Example.
Alright, lets say we wanted to create a Log of everyone who dies.
We put this at the top of our script:
pawn Код:
forward KillLog(killstring[]); //
Like This:
Now Look for
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
Underneath that we are in need of a String, this string will be written to the Log File.
pawn Код:
new killstring[256]; // Creates the Kill String
Alright, so we need to get the Name of the Killer and the Player.
So Under the KillString put this.
pawn Код:
new Victimname[MAX_PLAYER_NAME]; // Victims Name.
new Killername[MAX_PLAYER_NAME]; // Killers Name
This will be where we store the full name of the Victim, and the Killer.
Ok, we gotta get the names.
So under the above do this:
pawn Код:
GetPlayerName(playerid,Victimname,sizeof(Victimname));
GetPlayerName(killerid,Killername,sizeof(Killername));
This will get the Full Name for both Victim and Killer
Now we need to Format the string to say Victimname was killed by Killername.
So what we do is put this under the above code:
pawn Код:
format(killstring, sizeof(killstring), "%s was killed by %s.", Victimname, Killername); //Formats the String
Alright, so we have done all that, but what we need to do now, is tell the server what it does with that.
So now we need to do this under the above code:
pawn Код:
KillLog(killstring); //This calls Function KillLog and sends the killstring.
Now thats all for OnPlayerDeath:
The Above should look like this:
Alright, if we compiled this, we would probably get an error which says this:
function "KillLog" is not implemented
The reason is, we haven't setup the KillLog Function.
How we do this, is scroll to the bottom of your script.
Out of any Functions put this code in:
pawn Код:
public KillLog(killstring[])
{
}
This should Compile Perfect.
But if someone kills you, nothing will happen, since we haven't told it to do anything.
Now for the below, but it in the
when I mean in the { } i mean
Now we need to create a new string.
This is the string that gets the last string and puts it into the Log.
pawn Код:
new entry[256]; //This will add an Entry to the Kill Logs.
Now we need to Format this String and put in the last String.
pawn Код:
format(entry, sizeof(entry), "%s\n",killstring); // \n means a new line. killstring is the string which says Victimname was killed by Killername
Now Since we have Formatted that, its time for the File Creation.
A String is similar to a Variable.
This is a String
And this is a Variable
Creating a new file is easy.
Copy this below the above.
And now we need to open the file.
pawn Код:
hFile = fopen("kill.log", io_append);
io_append will open the file into the kill.log file.
And if there file isn't there, it will create it when someone dies.
Next we need to write to the file thats there.
pawn Код:
fwrite(hFile, entry); //Writes the string into the file.
Now since we have written into the file, we need to close it safely.
Put the following code underneath the above.
And thats it for the File.
The Above should look like this.
Now your ready to compile and kill your friends and see the logs appear in your scriptfiles folder.
Thanks, and hope you enjoyed the Tutorial.
Re: How to Make Logs -
Grim_ - 17.07.2010
Good tutorial, however I'm going to point out a couple of things :P
That is a big waste of cells, the max number the string can be is 63.
Also, there's no need to forward that KickLog functions, since it's not being used in a timer or such.
But nice
Re: How to Make Logs -
HeLiOn_PrImE - 06.02.2014
How can I create the file inside a folder?
Re: How to Make Logs -
Flake. - 07.02.2014
Quote:
Originally Posted by HeLiOn_PrImE
How can I create the file inside a folder?
|
You just bumped a 4 year old thread..
It will automatically make the file once a player is killed.
Re: How to Make Logs -
Lordzy - 07.02.2014
Quote:
Originally Posted by HeLiOn_PrImE
How can I create the file inside a folder?
|
pawn Код:
fopen("existingfoldername/filename.txt", io_append);
The server may crash in case if the folder don't exist.
Re: How to Make Logs -
Konstantinos - 07.02.2014
Quote:
Originally Posted by Lordz™
pawn Код:
fopen("existingfoldername/filename.txt", io_append);
The server may crash in case if the folder don't exist.
|
The server can also crash from natives fwrite, fclose because it never checks whether the file handle is valid.
Re: How to Make Logs -
HeLiOn_PrImE - 07.02.2014
Код:
error 027: invalid character constant