Here's an example, it's not tested though.
pawn Код:
//=====================Just an example==========================================
#include <a_samp>
#include <YSI\y_ini> //For saving
#include <zcmd> //I generally use zcmd for cmd processing, you can use yours here.
enum inv
{
Gold, //Gold's var
Diamond, //Diamond's
Silver //And silver's
}
new Inventory[MAX_PLAYERS][inv]; //Creating it in an enum so that it looks pretty clean.
#define DIALOG_INVENTORY 8521 //Dialog id of Inventory.
#define pInvPath "Inventory_Users/%s.ini" //Path where the users save, default defined : "Scriptfiles/Inventory_Users/"
stock pPath(playerid) //To execute the player's name with the INI files.
{
new Lname[MAX_PLAYER_NAME], string[128];
GetPlayerName(playerid, Lname, sizeof(Lname));
format(string, sizeof(string), pInvPath, Lname);
return string;
}
forward LoadPlayer_Inventory(playerid, name[], value[]); //A forward function which loads player's inventory.
public LoadPlayer_Inventory(playerid, name[], value[])
{
//Function: INI_Int - Which loads the 'int' value (integer). In case of string, it's INI_String, in case of float it's INI_Float.
INI_Int("Gold", Inventory[playerid][Gold]);
INI_Int("Diamond", Inventory[playerid][Diamond]);
INI_Int("Silver", Inventory[playerid][Silver]);
//Gets the value
return 1;
}
public OnPlayerConnect(playerid)
{
if(fexist(pPath(playerid))) //If there's a file for this player: then it loads
{
//We must use 'INI_ParseFile' function and execute the 'LoadPlayer_Inventory' with it. It loads the saved stats, via the user path defined in the function.
INI_ParseFile(pPath(playerid), "LoadPlayer_Inventory", .bExtra = true, .extra = playerid);
//Loads the data from the path defined and detects the player's file using getting player's name which is done in 'pPath' function.
//Now the data is loaded.
}
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
//Now the saving part, we must open, create a tag for the file and then write the values. And then, close the file. (INI_Open, INI_SetTag, INI_WriteInt <As it's an integer>, INI_Close )
new INI:iFile = INI_Open(pPath(playerid)); //Opens the player's path.
INI_SetTag(iFile, "Inventory"); //Sets a tag called "Inventory"
INI_WriteInt(iFile, "Gold", Inventory[playerid][Gold]);
INI_WriteInt(iFile, "Silver", Inventory[playerid][Silver]);
INI_WriteInt(iFile, "Diamond", Inventory[playerid][Diamond]);
//It writes the values of the var(s) of the player.
INI_Close(iFile);
Inventory[playerid][Gold] = 0;
Inventory[playerid][Silver] = 0;
Inventory[playerid][Diamond] = 0;
//Resetting the values after disconnect would be good to avoid bugs happening later.
return 1;
}
CMD:metals(playerid, params[])
{
new string[256];
format(string, sizeof(string), "Gold:%d\nSilver:%d\nDiamonds:%d\n"); //Formatting the string to show the var's value in dialog. Normally the dialog function won't support "{Float_...}"
ShowPlayerDialog(playerid, 8512, DIALOG_STYLE_MSGBOX, "Metals", string, "Close", "");
return 1;
}