INI_String.
#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


Messages In This Thread
INI_String. - by Denying - 12.05.2013, 10:41
Re: INI_String. - by Lordzy - 12.05.2013, 11:10
Re: INI_String. - by Denying - 12.05.2013, 11:28
Re: INI_String. - by Lordzy - 12.05.2013, 11:34
Re: INI_String. - by Denying - 12.05.2013, 12:21
Re: INI_String. - by Lordzy - 12.05.2013, 13:04

Forum Jump:


Users browsing this thread: 1 Guest(s)