!HELP! Inventory System
#1

How can I make an inventory system? What it would be like, is for players to carry items, could carry up to 5 of the same item within the 7 slot limit, and also so players could do a job that required them to carry many items with them to sell to other players (these players would be able to carry up to 100 of each item and have a 10 slot max). I will say that I have searched and found a plug-in for an inventory system, but unfortunately my server will be running on Linux and the plug-in is for windows. That being said, I feel you receive the most help when you take the time to go into detail of what you need help with and I will try to do that here:

Here I Will Say My Theory Of How To Make The System
Note That I Am Probably Way Wrong And Thus Is Why I Am Here
1) I would assume that we need to first create variables for the inventory system(How to I am Not Sure!)
2) I would think the next thing would be to define OnPlayerDisconnect and Connect that the player gets the same items they left the server with.
3) I would think that we next create some more but from here I would be totally lost..
4)In all honesty I have no clue what the hell I'm doing when it comes to this!

Any help is appreciated I am a visual learner and I am proud to say that all of the help I have received here has really helped me learn a lot easier since quite a few take the time to create the example and thus in turn I can pass the knowledge they gave to me on! I will be checking back hoping I can get some helpful examples! Thanks in advance!
Reply
#2

I really need help please guys I have been waiting 2 days to move on with my work and this is holding me up. If you can help me please don't hold back I have been very patient and really need help on this! Thanks in advance to those who help me. BTW I know DP is bad but I have been patient for 2 days and still 0 replies so sorry for that.
Reply
#3

Hey, i just completed like half a gm, which has a inventory system, have a look Here.
Reply
#4

Quote:
Originally Posted by JaYmE
Hey, i just completed like half a gm, which has a inventory system, have a look Here.
Cool I appreciate it I have been i need for the past 3 days now :/ I will have a look at it! Thanks again!
BTW if i get stuck do you mind if I ask you how I may implement it into my script?(I will try everything I know of before i ask tho :P) Thank you again!
Reply
#5

still dont understand ^^

i need an inventory system like this one just for linux ^^
Reply
#6

Quote:
Originally Posted by Plato
still dont understand ^^

i need an inventory system like this one just for linux ^^
I wish I could get one just like how I described I really feel that it would help out several players, I am not looking to just benefit myself I would like to see one just like how I described or very similar to it to help benefit the sa-mp community. Sharing is caring!
Reply
#7

I've made an inventory system for my gamemode which supports unlimited items which all have weights that limits the amount of items a player can carry depending on his Strength. This inventory system is completely GUI based and supports dropping items and trading them securely with other players.

I can tell you that such a system is not easy to make and is as big as many gamemodes released in here, so you're up for a BIG task there!

1) I would assume that we need to first create variables for the inventory system(How to I am Not Sure!)
For a proper inventory system you would need some kind of database to store all the player items in. Best bet would be to use sqlite which is natively supported in SA:MP.

2) I would think the next thing would be to define OnPlayerDisconnect and Connect that the player gets the same items they left the server with.
There is more to this than that; you would need a login system to identify users. Then you would need to give them all their items. You also have questions like: How do players get items? How do they use them or give them away? What if they die with items on them? Should they have a visual representation? How should a player sell/trade his items?

3) I would think that we next create some more but from here I would be totally lost..
Yes.. You would need to create a lot more How should a players inventory be presented to him? How should he navigate and sort his items?

4)In all honesty I have no clue what the hell I'm doing when it comes to this!
If you don't know where to start, maybe you should start with some other things for your gamemode and come back to this one when you feel more comfortable about it.
Reply
#8

1.Define an enum

pawn Код:
enum iinfo
{
  money,
  bank,
  mats,
  drugs
}
Inventory[MAX_PLAYERS][iinfo];
2.Now to create the file functions. First, you make a forward for them.

pawn Код:
forward CreateInventoryFile(playerid);
forward LoadInventoryFile(playerid);
forward SaveInventoryFile(playerid);
forward Split(const strscr[], strdest[][], delimiter);
3.Then make the functions.

pawn Код:
public CreateInventoryFile(playerid)
{
    new file[128];
    new filestr[128];

    new name[maxplayername];
    GetPlayerName(playerid, name, sizeof(name));
    format(file, sizeof(file), "%s.inv", name);
    new File: pfile = fopen(file, io_write);
    if(fexist(file))
    {
        Inventory[playerid][money]   = random(500) + 500;
        Inventory[playerid][bank]   = random(500);
        Inventory[playerid][mats]  = 500;
        Inventory[playerid][drugs]   = 0;

        format(filestr, sizeof(filestr),
            "%d/%d/%d/%d",
            Inventory[playerid][money],
            Inventory[playerid][bank],
            Inventory[playerid][mats],
            Inventory[playerid][drugs]
        );

        fwrite(pfile, filestr);
        fclose(pfile);
    }
    return 1;
}
public LoadInventoryFile(playerid)
{
    new file[128];
    new name[maxplayername];
    GetPlayerName(playerid, name, sizeof(name));

    format(file, sizeof(file), "/inventory/%s.inv", name);
    new File: pfile = fopen(file, io_read);
    if(fexist(file))
    {
        new filestr[128];
        new filearray[4][12]; // <- the first number is always one more than the lowest filearray[] below. The second is how long you want each variable in the array to be.
        fread(pfile, filestr);
        Split(filestr, filearray, '/'); // You can replace '/' with another symbol such as '|' if you want. but just make sure you update how the file is written to match that symbol.

        Inventory[playerid][money]  = strval(filearray[0]);
        Inventory[playerid][bank]   = strval(filearray[1]);
        Inventory[playerid][mats]   = strval(filearray[2]);
        Inventory[playerid][drugs]  = strval(filearray[3]);

    fclose(pfile);
    }
    return 1;
}
public SaveInventoryFile(playerid)
{
    new file[128];
    new name[maxplayername];
    GetPlayerName(playerid, name, sizeof(name));
    format(file, sizeof(file), "/inventory/%s.inv", name);
    if(fexist(file))
    {
        new filestr[128];
        new File: pfile = fopen(file, io_write);

        format(filestr, sizeof(filestr),
            "%d/%d/%d/%d",
            Inventory[playerid][money],
            Inventory[playerid][bank],
            Inventory[playerid][mats],
            Inventory[playerid][drugs]
        );

        fwrite(pfile, filestr);
        fclose(pfile);
    }
    return 1;
}
public Split(const strscr[], strdest[][], delimiter)
{
    new i, li;
    new aNum;
    new len;
    while(i <= strlen(strsrc))
    {
      if(strsrc[i]==delimiter || i==strlen(strsrc))
        {
        len = strmid(strdest[aNum], strsrc, li, i, 128);
        strdest[aNum][len] = 0;
        li = i+1;
        aNum++;
        }
        i++;
    }
    return 1;
}
4.Now just make sure you place the CreateInventoryFile(playerid); into your registration so that the file is made. You will now be able to set values to any of those variables you listed just like they are shown in the example below.

Ex.
pawn Код:
public examplegive100dollarsfunction(playerid)
{
  new amount = Inventory[playerid][money] += 100;
  GivePlayerMoney(playerid, amount);
  return 1;
}
Enjoy, you can modify this to make any type of file system. Sadly it is not very dynamic and if you change the way the file is, you have to either create the new one, or have a function to convert it to the new one, or do it manually.
Reply
#9

Hehe ^^ sry but i still dont understand ^^
Reply
#10

Kick ass I have 2 explanations to work off of and i really appreciate it. I understand this is a big task but I would eventually like to try to master this so I can eventually make a .INC like this for other players in our sa-mp community! I will try these things out and if I get stuck I will be specific in stating where I am stuck. BTW Plato once I figure out this if you still need help I will be willing to help you as well! Thanks again!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)