25.03.2012, 15:17
Hello Friends.I want to ask you how can i convert Y_ini system to Dini?
#define strcpy(%0,%1,%2) \
strcat((%0[0] = '\0', %0), %1, %2)
//Above is just a way of copying our string from the file into our string (I didn't make above (I believe ****** did))
#define PlayerPath "Mydirectory/%s.ini" //Our file path where we store our player data
//You'll see more how it's used in the Save and Load functions
enum InfoExample //Our info for our players enum
{
Int, //We have 2 ints
String[30], //1 string
Float:OurFloat, //and a float to store
AnotherInt
}
new PlayerArray[MAX_PLAYERS][InfoExample]; //We create our array so we can use the enum above in it
//The array is the size of max_players. the second dimension is the size of our enum (with things in it)
stock Save(playerid) //A simple save function
{
new file[50], Name[MAX_PLAYER_NAME]; //We need 2 strings here, one to store the name of the player. The other to store the file path
GetPlayerName(playerid, Name, sizeof(Name)); //Here we store the players name in our Name string
format(file, sizeof(file), PlayerPath, Name); //Here we format the %s in the file path to the Name variable
dini_IntSet(file, "Int", PlayerArray[playerid][Int]); //How we save an int
dini_Set(file, "String", PlayerArray[playerid][String]); //How we save a string
dini_FloatSet(file, "OurFloat", PlayerArray[playerid][OurFloat]); //How we save a float
dini_IntSet(file, "AnotherInt", PlayerArray[playerid][AnotherInt]); //How we save an int again
}
stock Load(playerid) //A simple load function
{
new file[50], Name[MAX_PLAYER_NAME]; //Same as the Save function
GetPlayerName(playerid, Name, sizeof(Name)); //Same as the Save function
format(file, sizeof(file), PlayerPath, Name); //Same as the Save function
PlayerArray[playerid][Int] = dini_Int(file, "Int"); //Get our int from the file and store it where it belongs
strcpy(PlayerArray[playerid][String], dini_Get(file, "String"), sizeof(PlayerArray[playerid][String])); //Get our string
PlayerArray[playerid][OurFloat] = dini_Float(file, "OurFloat"); //Store our Float we just got from the file into PlayerArray[playerid][OurFloat]
PlayerArray[playerid][AnotherInt] = dini_Int(file, "AnotherInt"); //We get the variable we stored earlier
}
OnPlayerDisconnect(playerid, reason)
{
Save(playerid); //Calls the function we created to save their data when they leave
}
OnPlayerConnect(playerid)
{
Load(playerid); //This would actually go on your login stuff - just an example
}
dini_Int(filepath[], "line_to_get_from_file"); //Get's an int from the file
dini_IntSet(filepath[], "name_to_store_it_as", AnInteger); //Sets an int to the file
dini_Get(filepath[], "line_to_get_from_file"); //Get's a string from the file
dini_Set(filepath[], "name_to_store_it_as", our_string_to_store[]); //Sets a string to the file
dini_Float(filepath[], "line_to_get_from_file"); //Get's a float from the file
dini_FloatSet(filepath[], "name_to_store_it_as", Float:afloat); //Sets a float to the file