07.09.2012, 15:50
(
Последний раз редактировалось Glint; 10.09.2012 в 16:53.
)
EDIT: Sorry the script is not compiled and will bump into bugs i will be fixing them ASAP when i have time and again i apologize.
Do you want to use y_ini but don't want to download the whole library just for one include ?
Or maybe you want to use dini because it is easy to use, but you can't because it is slow ?
Or do you want to use MySQL or SQLite but don't know how, or maybe don't want to ?
Then if your answer to all of these questions is yes then this system is for you.
It was released in 2011/06/19 By [HLF]Southclaw, and as some of the current INI systems it is based on cache, however i don't have much to say let's start working.
You can apply this on any script you like, in this tutorial we are going to use the blank script (generated when you click on 'new' in PAWNO) and off course we will need the include itself, you can get it from It's Original Topic (Click!) and we will need the Whirlpool plugin to hash password, you can get it from Here that's all we need for now open PAWNO and follow the steps
By including it the functions will be available for you to use and you can see the function in PAWN's function list on your right hand side of the screen.
When a new user registers his INI file will get written to a folder called Accounts in your scriptfiles directory, please create the folder Accounts in your scriptfiles otherwise it won't work.
The enum you see above will save each player's :
By using MAX_PLAYERS the enum will be available to each player so later on we can use PlayerInfo[playerid][Admin] for example.
the above function will let us use the hashing function provided by the Whirlpool plugin.
And we need to make a stock for user's path you so add this anywhere in your script (because when the script needs a stock it will look for it through top to bottom)
this is pretty self explanatory, but again, what are we doing is declaring two variables a pName to get player's name and store it inside pName, and Path to form user's path, the MAX_PLAYER_NAME is 24, this stock will return User's path.
TBH, i actually don't know what that is and why we added it, but when i didn't it just can't save player's data (I hope Soutclaw will come and tell me).
If the player's file exists then show the login dialog to him, else if it doesn't exist the show the register dialog so he can register, and make a new account on the server.
i explained everything in a comment near the code so i won't explain it here.
Now what we are doing above is checking if the player's file exists, if it does the get the location where the player was when he disconnected, and save them to his enum then afterwords save each enum into a line in his file, simple as that.
I explained what you need to know in the comments.
Now we need the player to see his motto when he logs in so under OnPlayerSpawn add
In the code above we used the direct reading functions, to be specific the string reading one, please note that the direct reading is very fast for ONLY ONE LINES not multiple.
Register / Login System Using Southclaw's INI System
Introduction
Do you want to use y_ini but don't want to download the whole library just for one include ?
Or maybe you want to use dini because it is easy to use, but you can't because it is slow ?
Or do you want to use MySQL or SQLite but don't know how, or maybe don't want to ?
Then if your answer to all of these questions is yes then this system is for you.
It was released in 2011/06/19 By [HLF]Southclaw, and as some of the current INI systems it is based on cache, however i don't have much to say let's start working.
What Do We Need
You can apply this on any script you like, in this tutorial we are going to use the blank script (generated when you click on 'new' in PAWNO) and off course we will need the include itself, you can get it from It's Original Topic (Click!) and we will need the Whirlpool plugin to hash password, you can get it from Here that's all we need for now open PAWNO and follow the steps
Steps!
Step 1
First of all we need to include the system on top of your script so it will look like this pawn Код:
#include <a_samp>
#include <INI>
Step 2
Now we need to define the user's path for ease of use so under your includes add this pawn Код:
#define USER_PATH "Accounts/%s.ini"
Step 3
Now as usual we need an enum to store our variables inside, so under your defines addpawn Код:
enum Info
{
IP[16],
Password[129],
Admin,
Score,
Money,
Deaths,
Kills,
Float:PosX,
Float:PosY,
Float:PosZ,
Float:PosA,
IsRegistered,
MyMotto[128]
}
- IP Address
- Password
- Admin Level
- Score
- Money
- Number Of Kills He Made
- Number Of Times He Died
- His Position So We Can Load It When He Re-Connects
- If He Is Registered Or Not
- His Motto
pawn Код:
new PlayerInfo[MAX_PLAYERS][Info];
Step 4
Now we need to add the Whirlpool native so under the declaration we made on the last step addpawn Код:
native WP_Hash(buffer[], len, const str[]);
And we need to make a stock for user's path you so add this anywhere in your script (because when the script needs a stock it will look for it through top to bottom)
pawn Код:
stock UserPath(playerid)
{
new pName[MAX_PLAYER_NAME], Path[60];
GetPlayerName(playerid, pName, sizeof(pName));
format(Path, sizeof(Path), USER_PATH, pName);
return Path;
}
Step 5
Now under your OnGameModeInit callback we need to addpawn Код:
file_OS();
Step 5
Now when a player joins when need to check if he has a account (registered), or it is the first time he is joining (not registered), so we can show the dialog to him, please note that the upcoming code can be added under OnPlayerConnect, OnPlayerRequestClass, OnPlayerSpawn, and OnPlayerRequestSpawn, however in this tutorial i am going to stick with OnPlayerConnect.pawn Код:
public OnPlayerConnect(playerid)
{
if(fexist(UserPath(playerid)))
{
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "Login", "Please Login By Writing Your Password Below", "Login", "Leave");
}
else
{
ShowPlayerDialog(playerid, 0, DIALOG_STYLE_PASSWORD, "Create An Account", "Please Create An Account On Our Server Before You Continue", "Register", "Leave");
}
return 1;
}
Step 6
Now under your OnDialogResponse add the following pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == 0) // If it is the register dialog
{
if(response) // if the player pressed the first button in our case Register.
{
if(!strlen(inputtext) || strlen(inputtext) > 100) // if the text ISN'T between 1 - 100 characters.
{
ShowPlayerDialog(playerid, 0, DIALOG_STYLE_PASSWORD, "Create An Account", "Please Create An Account On Our Server Before You Continue", "Register", "Leave");
SendClientMessage(playerid, -1, "Your password must be between (1 - 100) characters");
}
else // if the text IS between 1 - 100 characters.
{
new pName[MAX_PLAYER_NAME], pIP[16], HashPass[129]; // Creating 3 variables for player's name, IP, and a variable for hasing user's password.
GetPlayerName(playerid, pName, sizeof(pName)); // getting player's name and storing it inside the pName variable we created above ^.
GetPlayerIp(playerid, pIP, sizeof(pIP)); // getting player's IP and saving it inside the pIP variable we created before.
WP_Hash(HashPass, sizeof(HashPass), inputtext); // we are hashing inputtext (meaning the text the player wrote under the register dialog).
file_Create(UserPath(playerid)); // Creating the file in (Accounts/%s.ini)
file_Open(UserPath(playerid)); // opening the file
file_SetStr("Password", HashPass); // setting the player's password to the hashed number.
file_SetStr("IP", pIP); // setting player's IP to his IP
file_SetVal("Admin", 0); // setting his admin level to 0
file_SetVal("Score", 0); // setting his score to 0
file_SetVal("Money", 500); // setting his money to 500 (NOTE: you also need to use GivePlayerMoney under OnPlayerSpawn).
file_SetVal("Deaths", 0); // setting his kills to 0
file_SetVal("Kills", 0); // setting his deaths to 0
file_SetFloat("PosX", 0.0); // setting his X position to 0.0
file_SetFloat("PosY", 0.0); // setting his Y position to 0.0
file_SetFloat("PosZ", 0.0); // setting his Z position to 0.0
file_SetFloat("PosA", 0.0); // setting his Angle to 0.0
file_SetVal("IsRegistered", 1);
file_SetStr("MyMotto", "You Don't Have A Motto Set One Using /setmotto");
file_Save(UserPath(playerid)); // saving the file.
file_Close(); // closing the file (NOTE: ALWAYS AND I DO MEAN ALWAYS close a file don't keep it open)
SendClientMessage(playerid, -1, "you have been reged successfully"); // Sending a message to the player telling him he have been successfully registered the color -1 is white.
}
}
}
else if(dialogid == 1) // if he is registered then show him the login dialog
{
if(response) // if he clicked the first button in our case LOGIN
{
new HashPass[129]; // creating a variable to store get the hashed password from his file
WP_Hash(HashPass, sizeof(HashPass), inputtext); // hashing the text he entered under the login dialog
if(!strcmp(HashPass, PlayerInfo[playerid][Password])) // comparing it to the text in his file if it is true
{
file_Open(UserPath(playerid)); // open his file
PlayerInfo[playerid][Admin] = file_GetVal("Admin"); // set each variable in his enum to the one in his file
PlayerInfo[playerid][Score] = file_GetVal("Score");
PlayerInfo[playerid][Money] = file_GetVal("Money");
PlayerInfo[playerid][Deaths] = file_GetVal("Deaths");
PlayerInfo[playerid][Kills] = file_GetVal("Kills");
PlayerInfo[playerid][PosX] = file_GetFloat("PosX");
PlayerInfo[playerid][PosY] = file_GetFloat("PosY");
PlayerInfo[playerid][PosZ] = file_GetFloat("PosZ");
PlayerInfo[playerid][PosA] = file_GetFloat("PosA");
PlayerInfo[playerid][IsRegistered] = file_GetVal("IsRegistered");
file_Close(); // Closing the file.
}
else
{
SendClientMessage(playerid, -1, "wrong password entered try again"); // if the password doesn't match the one in his file then tell him that it is incorrect
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "Login", "Please Login By Writing Your Password Below", "Login", "Leave"); // and re-show the login dialog
}
}
}
return 1;
}
Step 7
We are almost finished, the last thing we need to do is get the player's information when he leaves and save them to his file to do that add the following lines to your OnPlayerDisconnect.pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
if(fexist(UserPath(playerid)))
{
GetPlayerPos(playerid, PlayerInfo[playerid][PosX], PlayerInfo[playerid][PosY], PlayerInfo[playerid][PosZ]);
GetPlayerFacingAngle(playerid, PlayerInfo[playerid][PosA]);
file_Open(UserPath(playerid));
file_SetVal("Admin", PlayerInfo[playerid][Admin]);
file_SetVal("Score", PlayerInfo[playerid][Score]);
file_SetVal("Money", PlayerInfo[playerid][Money]);
file_SetVal("Deaths", PlayerInfo[playerid][Deaths]);
file_SetVal("Kills", PlayerInfo[playerid][Kills]);
file_SetFloat("PosX", PlayerInfo[playerid][PosX]);
file_SetFloat("PosY", PlayerInfo[playerid][PosY]);
file_SetFloat("PosZ", PlayerInfo[playerid][PosZ]);
file_SetFloat("PosA", PlayerInfo[playerid][PosA]);
file_SetVal("IsRegistered", PlayerInfo[playerid][IsRegistered]);
file_SetStr("MyMotto", PlayerInfo[playerid][MyMotto]);
file_Close();
}
return 1;
}
Extra Stuff (Additions)
Now we are going to make a motto system (meaning each player can set a motto for himself, so make a command using zcmd, like this.pawn Код:
CMD:setmotto(playerid, params[])
{
if(PlayerInfo[playerid][IsRegistered] == 1) // if he is registered
{
if(IsNull(params)) return SendClientMessage(playerid, -1, "USAGE: /setmotto [your motto]"); // if he didn't write any parameters
PlayerInfo[playerid][MyMotto] = params; // set his motto to the parameter he wrote
SendClientMessage(playerid, -1, "SUCCESS: you have been successfully changed your motto into %s", params); // send him a success message
}
else SendClientMessage(playerid, -1, "You are not registered so you can't use this command"); // if he isn't registered
return 1; // the command is successfully done
}
Now we need the player to see his motto when he logs in so under OnPlayerSpawn add
pawn Код:
public OnPlayerSpawn(playerid)
{
PlayerInfo[playerid][MyMotto] = file_dGetStr(UserPath(playerid), "MyMotto"); // setting the MyMotto variable inside our enum to the MyMotto line in the player's user file
new Str[128];
format(Str, sizeof(Str), "Welcome Back Your Motto Is : %s", PlayerInfo[playerid][MyMotto]); // formatting the message that we are going to send him.
SendClientMessage(playerid, -1, Str);
return 1;
}
Footnotes
- If you face any problems please inform me
- If you can't understand a part tell me
- If there are any grammer mistakes again tell me.
- I know the player won't spawn where he was when he left, that is because i didn't add how to load it, it is easy to add just use SetPlayerPos under your OnPlayerSpawn and that's it, if i have time i will add it later, sorry.
Credits
[HLF]Southclaw - For The INI System
****** - For Whirlpool
****** - For Whirlpool