Y_ini to Dini
#10

I would just create it...Here's an example

pawn Код:
#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
}
Here's the dini functions I used
pawn Код:
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
It's actually pretty simple to do (re-creating the entire thing).
Reply


Messages In This Thread
Y_ini to Dini - by Dziugsas - 25.03.2012, 15:17
Re: Y_ini to Dini - by Cinnt - 25.03.2012, 15:18
Re: Y_ini to Dini - by Dziugsas - 25.03.2012, 15:19
Re: Y_ini to Dini - by Shabi RoxX - 25.03.2012, 15:23
Re: Y_ini to Dini - by Dziugsas - 25.03.2012, 15:24
Re: Y_ini to Dini - by Dziugsas - 25.03.2012, 15:36
Re: Y_ini to Dini - by Shabi RoxX - 25.03.2012, 16:54
Re: Y_ini to Dini - by NeTuddMeg - 25.03.2012, 17:28
Re: Y_ini to Dini - by Cinnt - 25.03.2012, 18:12
Re: Y_ini to Dini - by [ABK]Antonio - 26.03.2012, 06:29

Forum Jump:


Users browsing this thread: 1 Guest(s)