[Include] Cyanide's Inventory System (Saving, and Loading Support | Great for Roleplay | Descriptions)
#1

→ About

Cyanide's Inventory System's name explains itself. This project was launched about three weeks ago.

→ Advantages
  • Loading and Saving Support.
  • Great for Roleplay Servers.
  • User Friendly.
  • Useful Callbacks.
  • Useful Functions.
→ Optional Callbacks
pawn Код:
public onPlayerReceiveItem( playerid, itemName[ ], description[ ], amount )
{
      printf(" Player %i got a %s", playerid, itemName );
}

public onPlayerRemoveItem( playerid, itemName[ ], amount )
{
      printf(" Player %i lost %i of %s", playerid, amount, itemName );
}

public onPlayerInventorySaved( playerid, directory[ ] )
{
      printf( "Player %i's inventory was just saved to %s", playerid, directory );
}

public onPlayerInventoryLoaded( playerid, directory[ ] )
{
      printf( "Player %i's inventory was just loaded from %s", playerid, directory );
}
→ Functions ( inventorySystem.inc required )
Код:
countInventoryItems( clientid ) - Counts the amount of inventory items a player has.
listInventoryItems( clientid, inv_name[ ], inv_description[ ], &inv_int, &index ) - Lists all inventory items, view forum topic for information.
saveInventory( clientid, directory[ ] = INVENTORY_DIRECTORY ) - Saves a inventory.
loadInventory( clientid, directory[ ] = INVENTORY_DIRECTORY ) - Laods a inventory.
getInventoryItemDesc( clientid, itemName[ ] ) - Gets a item's description.
checkInventoryItemQuanity( clientid, itemName[ ] ) - Checks the amount of a item a player has.
checkInventoryItem( clientid, itemName[ ] ) - Checks if a player has a inventory item.
addInventoryItem( clientid, itemName[ ], description[ ], amount ) - Adds a inventory item.
removeInventoryItem( clientid, itemName[ ], amount = 0 ) - Removes a inventory item.
resetInventory( clientid ) - Resets a player's inventory.
        
onPlayerReceiveItem( playerid, itemName[ ], description[ ], amount ) - Called when a player gets item.
onPlayerRemoveItem( playerid, itemName[ ], amount ) - Called when a player loses a item.
onPlayerInventorySaved( playerid, directory[ ] ) - Called when a inventory is saved.
onPlayerInventoryLoaded( playerid, directory[ ] ) - Called when a inventory is loaded.
→ Functions Examples ( inventorySystem.inc required )

pawn Код:
new
    bool:p_logged[ MAX_PLAYERS ]
;

public OnPlayerConnect( playerid )
{
     addInventoryItem( playerid, "cow", "this animal echos moo.", 2 ); // The player has two cows!
     addInventoryItem( playerid, "Pencil", "You can write with this object", 1 ); // The player has one pencil.
}

public OnPlayerDisconnect( playerid, reason )
{
     if( p_logged[ playerid ] == true )
         saveInventory( playerid );

     return true;
}

public OnPlayerCommandText( playerid, cmdtext[ ] )
{
     if( !strcmp( cmdtext, "/login", true ) )
     {
          ...
          OnPlayerLogin( playerid, password );
     }
     if( !strcmp( cmdtext, "/moo", true ) )
     {
           if( !checkInventoryItem( playerid, "cow" ) )
              return SendClientMessage( playerid, 0x0, "{FFFFFF}Since you don't have a cow, you cannot use this command" );
 
           ...
     }
     if( !strcmp( cmdtext, "/myinventory", true ) )
     {
          new
              string[ 150 ],
              itemName[ 30 ],
              itemDesc[ 100 ],
              itemAmm
              idx
          ;
          SendClientMessage( playerid, 0x0, "{FFFFFF}You have the following items in your inventory:" );
          while( listInventoryItems( playerid, itemName, itemDesc, itemAmm, idx ) )
          {
               format( string, sizeof string, "{FFFFFF}%s - %s (Amount: %i)", itemName, itemDesc, itemAmm );
               SendClientMessage( playerid, 0x0, string );
               idx ++;
          }
          /*
              From the items given in OnPlayerConnect, this would print:
              cow - this animal echos moo (Amount: 2)
              Pencil - You can write with this object (Amount: 1)
          */

     }
}

public onPlayerReceiveItem( playerid, itemName[ ], description[ ], amount )
{
     if( !strcmp( itemName, "cow", true ) )
        return printf("Player %i is now cow-friendly", playerid );
}

public OnPlayerLogin( playerid, password )
{
     loadInventory( playerid );
     p_logged[ playerid ] = true;
}
→ Download

.inc download.

→ Credits

Код:
Cyanide - Project Launcher & Developer
SA-MP Team - San Andreas Multiplayer Modification.
→ Other Notes

The default saving and loading directory is playerInventories/%s.ini, you can configurate that setting by opening inventorySystem.inc and changing line 36 ( INVENTORY_DIRECTORY ). You will need to create the folder for the files to actually save and load.
Reply
#2

I think it's better to create item and then add them to players.
String comparison is not so good as checking system and the saving system probabily won't be useful for all end-users.
For example in my rp server, you enter with a nickname that can be or not RP, and then manage your account (a system that provides multiaccount linked to a main account)
Therefore, would be better let users implement a saving system theirselfs.
Anyway, nice work.
Reply
#3

Phanto90, you're right. For example, i have an item system in my roleplay gamemode and i use item IDs instead of comparing item names and it's easier for yourself.

I might release my version of inventory system soon.
Reply
#4

Nice
Reply
#5

Quote:
Originally Posted by Phanto90
Посмотреть сообщение
I think it's better to create item and then add them to players.
String comparison is not so good as checking system and the saving system probabily won't be useful for all end-users.
For example in my rp server, you enter with a nickname that can be or not RP, and then manage your account (a system that provides multiaccount linked to a main account)
Therefore, would be better let users implement a saving system theirselfs.
Anyway, nice work.
Well, there's a advantage from using string comparison to script-wise codes. A example of the advantage would be a administrator giving a player a custom object for RP purposes. Also, a saving, and loading system can be added from the user-end by using listInventoryItems.
Reply
#6

Hey.
I had a little problem.
I want to make a inventory-system and i use your include.
i want to list all items in the inventory, and it works. (in dialog)
but i want to "choose" items in the dialog (list-dialog) and i dont know what to do now ... :/

If i press "Z" (KEY_YES) it opens the dialog, and all items are in the list.
pawn Код:
if(newkeys & KEY_YES)
    {
        new
            itemName[30],
            itemDescription[100],
            itemAmount,
            index;
        strdel(DialogString, 0, sizeof(DialogString));
        strcat(DialogString, COLOR_HEX_RED"Item\t\t\t\t\tAnzahl\n");
        while(listInventoryItems(playerid, itemName, itemDescription, itemAmount, index))
        {
            format(DialogString, sizeof(DialogString), COLOR_HEX_WHITE"%s%s\t\t\t%d\n", DialogString, itemName, itemAmount);
            index++;
        }
        ShowPlayerDialog(playerid, DIALOG_INVENTORY, DIALOG_STYLE_LIST, "Inventar", DialogString, "Auswдhlen", "Abbrechen");
    }
But my brain says to me, that i cant script more ( ... ) xD
pawn Код:
case DIALOG_INVENTORY:
{
    if(response)
    {
       
    }
}
can u help me?? ^^
Reply
#7

Cyanide, this include has some issues for me.

1. Sometimes the file saves when I log out, but sometimes it erases all of the items in the inventory-user-file.
2. I have this command:

Код:
COMMAND:i(playerid, params[])
{
	new ilist[780];
 	new
   	itemName[ 30 ],
   	itemDesc[ 100 ],
   	itemAmm,
   	idx;
   
   while( listInventoryItems( playerid, itemName, itemDesc, itemAmm, idx ) )
   {
   		format( ilist, sizeof ilist, "{FFFFFF}%s - %s (Amount: %i)\n%s", itemName, itemDesc, itemAmm , ilist);
      	idx ++;
   }
    ShowPlayerDialog(playerid, 789, DIALOG_STYLE_LIST, "Inventory", ilist, "Close", "Close");
    return 1;
}
Which shows me two items while only having one sometimes (same items, same descriptions, same amount).
Reply
#8

I would like to draw inspiration from this system to save in the database! Thank you!
Reply
#9

why dont use keys for open inv Like ...... KEY_YES (Y) For open inv and close ..
Reply
#10

Why items name often are capital letter ?

How to change them?
Reply
#11

I cant download it...Has someone this include ?? Please send me a download link.
Reply
#12

https://pastebin.com/mHHRk0NA
Here it is !
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)