INI_String.
#1

Hey.

Call me dumb or lazy I searched the web, couldn't understand anything.

I have this:
pawn Код:
GetPlayerName(playerid, kname[playerid], sizeof(kname));
format(kfile[playerid], sizeof(kfile), "Users/%s.ini", kname[playerid]);
new INI:File = INI_Open(kfile[playerid]);
And I want to add a line to "read" the line "Password" in the file.
I have no idea how to. I know that in dini you use string = dini_Get(filename, linename);

But I can't understand INI_String at all.
Please someone explain..?
Reply
#2

INI_String is a function of 'y_INI' which gets a string from a file. For example, if you want to get your password; you gotta do this:
pawn Код:
INI_String(Path, "Password", User[playerid][Password]);
A bit more elaborated:
pawn Код:
#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;
}
Reply
#3

Now I understand, but not completely.

I mean - I've read this and I have no idea where to put any line. ( First time using Y-INI, I dunno why I can't understand this. )

Let's say I got this:

pawn Код:
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)
I am either very dumb or this is very complicated. I'll choose the very dumb.
Thank you for the help.
Reply
#4

pawn Код:
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*/);
My INI file:
Код:
Password = ...........................
PersonalText = hello world!
The above code code will get the 'hello world!' from the entry 'PersonalText'.

EDIT: I've done a mistake in 'INI_String' function, you need to add the array's size too at the last parameter of INI_String.
Reply
#5

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?
Reply
#6

Quote:
Originally Posted by Denying
Посмотреть сообщение
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?
1) Yes, it will be imported to the array.
2) INI_ParseFile is a function which executes a INI function which we manually create to load the data. You can view some of the user tutorials using y_INI to clarify it well.

EDIT: I've done a mistake in the above posts, you've to mention the size also in the INI_String function.

pawn Код:
/*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;
}
And my file:
Код:
[PlayerData]
Cash = 100
Score = 10
Kills = 467
Deaths = 100
PersonalTxt = Hi, I'm Lordz.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)