[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


Messages In This Thread
Cyanide's Inventory System (Saving, and Loading Support | Great for Roleplay | Descriptions) - by Cyanide - 04.09.2011, 12:34
Re: Cyanide's Inventory System (Saving, and Loading Support | Great for Roleplay | Descriptions) - by Phanto90 - 04.09.2011, 12:42
Re: Cyanide's Inventory System (Saving, and Loading Support | Great for Roleplay | Descriptions) - by WooTFTW - 04.09.2011, 12:45
Re: Cyanide's Inventory System (Saving, and Loading Support | Great for Roleplay | Descriptions) - by FireCat - 04.09.2011, 12:45
Re: Cyanide's Inventory System (Saving, and Loading Support | Great for Roleplay | Descriptions) - by Cyanide - 04.09.2011, 12:53
AW: Cyanide's Inventory System (Saving, and Loading Support | Great for Roleplay | Descriptions) - by 'Pawno. - 20.09.2012, 10:48
Re: Cyanide's Inventory System (Saving, and Loading Support | Great for Roleplay | Descriptions) - by Devix - 09.10.2012, 10:50
Re : Cyanide's Inventory System (Saving, and Loading Support | Great for Roleplay | Descriptions) - by DexX39 - 24.01.2014, 16:47
Re: Cyanide's Inventory System (Saving, and Loading Support | Great for Roleplay | Descriptions) - by Toxik - 17.02.2014, 11:41
Re: Cyanide's Inventory System (Saving, and Loading Support | Great for Roleplay | Descriptions) - by MasonSFW - 04.07.2015, 15:46
Re: Cyanide's Inventory System (Saving, and Loading Support | Great for Roleplay | Descriptions) - by IchNar - 24.08.2017, 17:33
Re: Cyanide's Inventory System (Saving, and Loading Support | Great for Roleplay | Descriptions) - by FuNkYTheGreat - 24.08.2017, 17:41

Forum Jump:


Users browsing this thread: 1 Guest(s)