GetPlayerName(playerid, kname[playerid], sizeof(kname));
format(kfile[playerid], sizeof(kfile), "Users/%s.ini", kname[playerid]);
new INI:File = INI_Open(kfile[playerid]);
INI_String(Path, "Password", User[playerid][Password]);
#define pPath "Users/%s.ini" //User path.
stock Path(playerid)
{
new s[128], l[24];
GetPlayerName(playerid, l, sizeof(l));
format(s, sizeof(s), pPath, l);
return s;
} //This functions returns the path with the name of the playerid.
forward LoadPlayer_Password(playerid, name[], value[]); //Forwarding to load the player password. playerid is the player's id, name the line to get, and value is it's value.
public LoadPlayer_Password(playerid, name[], value)
{
INI_String(Path(playerid), "Password", User[playerid][Pass]); //Gets the password from player's path and stores in the 'user[playerid][pass]' array.
return 1;
}
//Execute this function in INI_Parse to perform.
public OnPlayerConnect(playerid)
{
INI_ParseFile(Path(playerid), "LoadPlayer_Password", .bExtra = true, .extra = playerid);
return 1;
}
if(1==1) // And now I want to go to get a string's value from a player's file. (String line name: "Password" for instance)
INI_String(/*the path of the file*/, /*the string line*/, /*it's value*/, /*the array's size here*/);
//Example:
INI_String("Users/Lordz.ini", "PersonalText", SAMP[playerid][Userid], /*the array's size here*/);
Password = ........................... PersonalText = hello world!
Let's see if I got this straight.
After using this line: INI_String("Users/Lordz.ini", "PersonalText", SAMP[playerid][Userid]); The value of PersonalText's line will be imported to SAMP[playerid][Userid]? If that's true; I have a few questions about your first post. Where do I put every part of code except the INI_ParseFile line? Should it global? |
/*Example of loading/saving user data with y_INI*/
#include <a_samp>
#include <YSI\y_INI>
#if !defined pPath
#define pPath "Users/%s.ini"
#endif
#if !defined Path
stock Path(playerid)
{
new l[24], s[128];
GetPlayerName(playerid, l, sizeof(l));
format(s, sizeof(s), pPath, l);
return s;
}
#endif
enum pinf
{
Money,
Score,
Kills,
Deaths,
PersonalText[128], //It's a string.
}
new User[MAX_PLAYERS][pinf];
forward LoadUser_Data(playerid, name[], value[]); //In the above posts, i've mentioned for the forwards.
public LoadUser_Data(playerid, name[], value[])
{
//For loading strings, we use 'INI_String(path, entryline, it'svalue);' and for integer or number, we use 'INI_Int(path, entryline, it'svalue, size);'
INI_Int(Path(playerid), "Cash", User[playerid][Money]); //Gets the value of the entry Cash and stores it in the array 'User[playerid][Money]'.
INI_Int(Path(playerid), "Score", User[playerid][Score]); //Just like above but here gets the 'score' entry.
INI_Int(Path(playerid), "Kills", User[playerid][Kills]); //^^
INI_Int(Path(playerid), "Deaths", User[playerid][Deaths]); //^^
//Next is getting personaltext, which is not an integer.
INI_String(Path(playerid), "PersonalTxt", User[playerid][PersonalText], 128); //Gets the personaltext's string value and stores it in the array.
return 1; //Returns the function.
}
//Now for this above function to get executed, you've got to parse the whole function in 'INI_ParseFile'.
//We generally use that under OnPlayerConnect to load the data while player gets connected.
public OnPlayerConnect(playerid)
{
INI_ParseFile(Path(playerid), /*thefunction*/"LoadUser_Data", /*parameters are needed?*/.bExtra = true/*yep*/, /*the parameter*/.extra = playerid);
return 1;
}
//Data is loaded now ^
//Now, to save it:
public OnPlayerDisconnect(playerid, reason)
{
//We'll save it when player gets disconnects, I'd rather choose a timer; but this is an example.
new INI:pfile = INI_Open(Path(playerid)); //Opens the player path.
INI_SetTag(pfile, "PlayerData"); //You must set a tag on the INI before writing the values.
//For writing integer, "INI_WriteInt(/*file*/,/*entry*/,/*value*/);" and "INI_WriteString" for string.
User[playerid][Money] = GetPlayerMoney(playerid);
User[playerid][Score] = GetPlayerScore(playerid);
INI_WriteInt(pfile, "Cash", User[playerid][Money]); //Now the value of the array is player's money.
INI_WriteInt(pfile, "Score", User[playerid][Score]);
INI_WriteInt(pfile, "Kills", User[playerid][Kills]);
INI_WriteInt(pfile, "Deaths", User[playerid][Deaths]);
INI_WriteString(pfile, "PersonalTxt", User[playerid][PersonalText]);
return 1;
}
[PlayerData] Cash = 100 Score = 10 Kills = 467 Deaths = 100 PersonalTxt = Hi, I'm Lordz.