Inv System help
#1

Hello,

Can anyone give me an simple example like how can i save/load metals.
Here's my cmd : /metals - to open inv

pawn Код:
CMD:metals(playerid, params[])
{
   ShowPlayerDialog(playerid, metals, DIALOG_STYLE_MSGBOX,"Metals","Metal Ore : %d\nGold : %d\nDiamond : %d\nSilver : %d\nTin : %d\nLead : %d\nIron : %d\nCobalt : %d\nTitanium : %d\nPlatinum : %d\nCopper : %d\nManganese : %d\nMercury : %d");
   return 1;
}
I need that it should create a file for every player in Scriptfiles, and how can i give metal to someone like, if he got A gold metal, how can do like : GivePlayer.... ?

Thanks.
Reply
#2

try using Y_ini

https://sampforum.blast.hk/showthread.php?tid=175565

and for the metals and stuff, possibly sscanf2 might be useful
Reply
#3

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;
}
Reply
#4

Thanks, It worked, Repped and will Add your name with Bold on Credits
I wanna Ask that if Player Gets Any metal like Gold, how can i set it 1?
Reply
#5

pawn Код:
Inventory[playerid][Gold] = 1; //It will set to one.
Inventory[playerid][Gold]++; //Will increase with the current value, +1.
Inventory[playerid][Gold]--; //Same as above, but reduces -1.
Inventory[playerid][Gold] += 5; //Adds +5 to the current value.
Inventory[playerid][Gold] -= 5; //Reduces -5 to the current value.
Reply
#6

Thanks Very Much.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)