17.07.2010, 09:26
Hey, the name is RichyB and this is the Tutorial on how to make Logs for your server.
This is my First Tutorial
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[]); //
Now Look for
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
pawn Код:
new killstring[256]; // Creates the Kill String
So Under the KillString put this.
pawn Код:
new Victimname[MAX_PLAYER_NAME]; // Victims Name.
new Killername[MAX_PLAYER_NAME]; // Killers Name
Ok, we gotta get the names.
So under the above do this:
pawn Код:
GetPlayerName(playerid,Victimname,sizeof(Victimname));
GetPlayerName(killerid,Killername,sizeof(Killername));
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
So now we need to do this under the above code:
pawn Код:
KillLog(killstring); //This calls Function KillLog and sends the killstring.
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[])
{
}
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
pawn Код:
{
}
pawn Код:
{
//here
}
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.
pawn Код:
format(entry, sizeof(entry), "%s\n",killstring); // \n means a new line. killstring is the string which says Victimname was killed by Killername
A String is similar to a Variable.
This is a String
pawn Код:
new Name[256];
pawn Код:
new Name;
Copy this below the above.
pawn Код:
new File:hFile;
pawn Код:
hFile = fopen("kill.log", io_append);
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.
Put the following code underneath the above.
pawn Код:
fclose(hFile);
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.