Face9000
08/02/2011, 06:59 PM
Hai all,this is my first tutorial so don't get mad if i will do something wrong.
And excuse my poor english,i'm Italian ^^.
Let's start:
What is this tutorial?
This tutorial is the simplest way to learn how to make logs in the fastest and simplest way.
For this tutorial,i will use the BanLog,to log all the admin bans in a file placed in /scriptfiles folder.
As first step,we need to create the forward statement:
forward BanLog(string[]);
Copy it in the first lines of your game mode.
Now we got the forward,we need to add the public() too.
So,let's add this:
public BanLog(string[])
{
new entry[128];
format(entry, sizeof(entry), "%s\n",string);
new File:hFile;
hFile = fopen("/LOGS/bans.log", io_append);
fwrite(hFile, entry);
fclose(hFile);
}
All public functions must be forwarded. That is a rule of pawno. If you do not forward a public function, you will receive warnings from the compiler. It's best to forward a function at the top of the script (but below the #include directives, though).
Let me describe what i write above:
new entry[128];
format(entry, sizeof(entry), "%s\n",string);
I used it for create a new string to write in the file.
the %s stays for the string to write in the file. (In this case,the ban).
\n is for create a new line.
And string,is for write ALL in the text file.
new File:hFile;
hFile = fopen("/LOGS/bans.log", io_append);
fwrite(hFile, entry);
fclose(hFile);
Here,we create the file place in /scriptfiles/LOGS/ called bans.log
WARNING: ALL FILES MUST BE IN /SCRIPTFILES FOLDER,PAWNO DOESNT HAVE ACCESS TO THE ROOT OF YOUR SERVER,SO YOU CANT CREATE FILES IN THE ROOT AND READING IT.
You can change the name/folder as you decided.
Ex: U can use only bans.log to access it in the only /scriptfiles folder,but i suggest to leave as is writed: /scriptfiles/LOGS.
NO NEED EVERYTIME TO WRITE /scriptfiles.
After the file is opened,the server will write it with:
fwrite(hFile, entry);
And after writing,it will be closed with:
fclose(hFile);
Well,we got now the forward and the public!
Now we need to add at your ban command,here is an example:
dcmd_b(playerid, params[])
{
new toplayerid, reason[ 128 ];
if (sscanf(params, "us[128]", toplayerid, reason))
{
SendClientMessage(playerid, 0xAA3333AA, "Syntax Error: /ban < Playerid > < Reason >");
return 1;
}
if (toplayerid == INVALID_PLAYER_ID)
{
SendClientMessage(playerid, 0xAA3333AA, "Input Error: Player is not connected or it is yourself.");
return 1;
}
new banString[128], adminName[24], bannedName[24];
GetPlayerName(playerid, adminName, 24);
GetPlayerName(toplayerid, bannedName, 24);
format(banString, 128, "%s was banned by Admin %s. Reason: %s.", bannedName, adminName, reason);
SendClientMessageToAll(0xAA3333AA, banString);
BanLog(banString);
Ban(toplayerid);
}
return 1;
}
As you can see,i've added the BanLog(banString) under:
format(banString, 128, "%s was banned by Admin %s. Reason: %s.", bannedName, adminName, reason);
SendClientMessageToAll(0xAA3333AA, banString);
And we done.Simply uh?
WARNING: You need,when add BanLog to write the string used in the command.
Ex: In this case we used banString,if u use the normal string,u need to do:
BanLog(string);
That's all,you can create all logs you want by using the forward and public writed above.
Sorry if tutorial is long but i've to describe the functions used ^^.
And excuse my poor english,i'm Italian ^^.
Let's start:
What is this tutorial?
This tutorial is the simplest way to learn how to make logs in the fastest and simplest way.
For this tutorial,i will use the BanLog,to log all the admin bans in a file placed in /scriptfiles folder.
As first step,we need to create the forward statement:
forward BanLog(string[]);
Copy it in the first lines of your game mode.
Now we got the forward,we need to add the public() too.
So,let's add this:
public BanLog(string[])
{
new entry[128];
format(entry, sizeof(entry), "%s\n",string);
new File:hFile;
hFile = fopen("/LOGS/bans.log", io_append);
fwrite(hFile, entry);
fclose(hFile);
}
All public functions must be forwarded. That is a rule of pawno. If you do not forward a public function, you will receive warnings from the compiler. It's best to forward a function at the top of the script (but below the #include directives, though).
Let me describe what i write above:
new entry[128];
format(entry, sizeof(entry), "%s\n",string);
I used it for create a new string to write in the file.
the %s stays for the string to write in the file. (In this case,the ban).
\n is for create a new line.
And string,is for write ALL in the text file.
new File:hFile;
hFile = fopen("/LOGS/bans.log", io_append);
fwrite(hFile, entry);
fclose(hFile);
Here,we create the file place in /scriptfiles/LOGS/ called bans.log
WARNING: ALL FILES MUST BE IN /SCRIPTFILES FOLDER,PAWNO DOESNT HAVE ACCESS TO THE ROOT OF YOUR SERVER,SO YOU CANT CREATE FILES IN THE ROOT AND READING IT.
You can change the name/folder as you decided.
Ex: U can use only bans.log to access it in the only /scriptfiles folder,but i suggest to leave as is writed: /scriptfiles/LOGS.
NO NEED EVERYTIME TO WRITE /scriptfiles.
After the file is opened,the server will write it with:
fwrite(hFile, entry);
And after writing,it will be closed with:
fclose(hFile);
Well,we got now the forward and the public!
Now we need to add at your ban command,here is an example:
dcmd_b(playerid, params[])
{
new toplayerid, reason[ 128 ];
if (sscanf(params, "us[128]", toplayerid, reason))
{
SendClientMessage(playerid, 0xAA3333AA, "Syntax Error: /ban < Playerid > < Reason >");
return 1;
}
if (toplayerid == INVALID_PLAYER_ID)
{
SendClientMessage(playerid, 0xAA3333AA, "Input Error: Player is not connected or it is yourself.");
return 1;
}
new banString[128], adminName[24], bannedName[24];
GetPlayerName(playerid, adminName, 24);
GetPlayerName(toplayerid, bannedName, 24);
format(banString, 128, "%s was banned by Admin %s. Reason: %s.", bannedName, adminName, reason);
SendClientMessageToAll(0xAA3333AA, banString);
BanLog(banString);
Ban(toplayerid);
}
return 1;
}
As you can see,i've added the BanLog(banString) under:
format(banString, 128, "%s was banned by Admin %s. Reason: %s.", bannedName, adminName, reason);
SendClientMessageToAll(0xAA3333AA, banString);
And we done.Simply uh?
WARNING: You need,when add BanLog to write the string used in the command.
Ex: In this case we used banString,if u use the normal string,u need to do:
BanLog(string);
That's all,you can create all logs you want by using the forward and public writed above.
Sorry if tutorial is long but i've to describe the functions used ^^.