05.04.2009, 20:00
3PLAY - Player Inventory Library Include
Description:This library allows you to add, remove or edit items in the player inventory, that is shown to the user using the Menu System.
Each item has a quantity that is displayed in the menu aswell.
Library Functions Overview:
VerifyInventoryMenuRowSelected(playerid, rowid):
You need to place this call inside the 'public OnPlayerSelectedMenuRow(playerid, row)' right before 'return 1;', so the system can identify if that row belongs to it or not. If it doesn't belong, this will return 0 (or false), otherwise it returns 1 (or true) and fires 'OnPlayerInventoryItemSelected(playerid, itemid)'
InitializeInventories():
This must be placed in 'OnGameModeInit' or 'OnFilterScriptInit'. It basicly initializes all variables. If you don't do it some unknown bugs might happen!
RemoveItemFromPlayerInventory(playerid, itemid, quantity):
This can be called in any function in your script. It removes the «quantity» from the player inventory where the item is «itemid». If the «quantity» is bigger then the existing quantity, the entire item will be removed from the inventory.
ResetPlayerInventory(playerid):
Can be inserted into OnPlayerConnect or Disconnect. It resets the entire player inventory for that player. It can also be called from anywhere else to remove all items from that player inventory
AddItemToPlayerInventory(playerid, itemid, quantity, itemdescription[] = ""):
Adds the item to the player inventory. If the item already exists (if theres another item with the same id) the quantity will be added and the description ignored. Otherwise, it creates a new item with that quantity and description
ShowInventoryToPlayer(playerid):
Shows the inventory to the specified player.
DestroyPlayerInventoryMenu(playerid):
Destroys the player menu. Not much usefull, except 'OnPlayerDisconnect'.
GetItemQuantity(playerid, itemid):
Returns the existing amount of that item, or -1 if the item doesn't exist.
PlayerHasItemInInventory(playerid, itemid):
Returns 1 (or true) if the player as the item in the inventory, or 0 (false).
(Version 0.2b) SetPlayerItemQuantity(playerid, itemid, quantity):
Sets the «quantity» of the specified «itemid». It will return 0 (false) if the item doesn't exist in the player inventory. Otherwise, it returns 1;
(Version 0.2b) SavePlayerInventoryToFile(playerid):
Saves the player inventory data into a file that is located inside «Player Inventories» folder. This folder must be created inside
«scriptfiles», that is located in your server root. If you don't create it, the script will not save the data.
(Version 0.2b) LoadPlayerInventoryFromFile(playerid):
Loads the player inventory data from the file located inside «Player Inventories» folder. This folder must be created inside
«scriptfiles», that is located in your server root. If you don't create it, the script will think there is no saved data and will return 0.
Library Callbacks:
public OnPlayerInventoryItemSelected(playerid, itemid):
When you have called the 'VerifyInventoryMenuRowSelected' function, it checks which row of the inventory menu has been selected
and calls this function. The playerid is the playerid of the player who selected an item from the menu, and the 'itemid' is the id
of the selected item. This ID is specified by you when you add it to the players inventory.
File Download: Player Inventory - Version 0.2b Current Version

Change Log:
PlayerInventory.inc - Version 0.1.1b
- Fixed a bug that made the player uncontrollable after choosing an item from the inventory
- Fixed function «PlayerHasItemInInventory»
- Fixed function «GetItemQuantity»
PlayerInventory.inc - Version 0.2b
- Added «SetPlayerItemQuantity(playerid, itemid, quantity)»
- Added «SavePlayerInventoryToFile(playerid)»
- Added «LoadPlayerInventoryFromFile(playerid)»
Simple Demonstration Gamemode:

For those who downloaded 3PLAY | Team Deathmatch, may recognize the game mode.
I just added the Player Inventory System to it. When you connect, choose your favorite character and spawn.
You will be given 3 Health packs the first time you join the server. If you leave the server and come back latter,
you will notice that you now have the same healthpacks that you had before you leave the server.
Important Note:
[size=8pt]Since version 0.2b, the PlayerInventory.inc pawn library uses DracoBlue INI Engine (DINI) to save and load the data from *.ini files.
Dini.inc file is contained in PlayerInventory.rar file, but it was not created or modified in anyway by me or any other 3Play member.
Dini is copyright © DracoBlue (2006 / 200

Feel free to report any bugs or submit suggestions, by replying to this topic or contacting me over MSN: jplopes@live.com.pt