[Include] Player Inventory System 0.2b (Menu + Save / Load)
#1

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 : http://dracoblue.com


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

WoW! Nice!
Reply
#3

Looks like a fascinating system, I am going to try it out myself.

EDIT: If I make another test script, would you be interested?

EDIT 2: It would be good if you documented OnPlayerInventoryItemSelected(playerid, itemid)
Reply
#4

Quote:
Originally Posted by Weirdosport
Looks like a fascinating system, I am going to try it out myself.

EDIT: If I make another test script, would you be interested?

EDIT 2: It would be good if you documented OnPlayerInventoryItemSelected(playerid, itemid)
Sure, I would be interested in another test script.
I didn't had much time to fully test this thing, and I would really appreciate that
About EDIT2: Sure, I'm going to do it right now
Reply
#5

I found a bug/typo, depending on how you see it.

Line 166 of the include has this:

pawn Code:
for(new j, j < 10; j++)
It should be a ; not a ,

This flags up problems when compiling the PlayerHasItemInInventory(playerid, _itemid) function.
Reply
#6

cool i might try it
Reply
#7

Came across another bug, where I ended up with the following setup:

Code:
Package 1 x3
Package 3 x1
Package 2 x1
Package 2 x1 <-- Did not increase package 2 quantity, added separate item
Also when I selected an item from the menu, it executed the command I wanted, but it left the player uncontrollable. Do I have to add a return 1; to this callback?
Reply
#8

Quote:
Originally Posted by Weirdosport
Came across another bug, where I ended up with the following setup:

Code:
Package 1 x3
Package 3 x1
Package 2 x1
Package 2 x1 <-- Did not increase package 2 quantity, added separate item
Also when I selected an item from the menu, it executed the command I wanted, but it left the player uncontrollable. Do I have to add a return 1; to this callback?
EDIT:
Wirdosport. Since this is a library, I don't think theres a way of knowing when the player left the menu without you calling a function.
Please call the 'DestroyPlayerInventoryMenu()' in 'OnPlayerExitedMenu'. This removes the menu from the memory and sets the player controllable.

Is the Item ID the same?
Because, it is supposed to only add the quantity if the itemid is the same.
Reply
#9

Quote:
Originally Posted by -zriptarusk
EDIT:
Wirdosport. Since this is a library, I don't think theres a way of knowing when the player left the menu without you calling a function.
Please call the 'DestroyPlayerInventoryMenu()' in 'OnPlayerExitedMenu'. This removes the menu from the memory and sets the player controllable.

Is the Item ID the same?
Because, it is supposed to only add the quantity if the itemid is the same.
I did end up using DestroyPlayerInventoryMenu, and it does the job.

As for the Item ID, I am fairly sure it was the same, as I only used the AddItemToPlayerInventory(); in 1 place for each individual package, and only used item id's 0 1 and 2. Is it ok to use id 0?
Reply
#10

Quote:
Originally Posted by Weirdosport
Quote:
Originally Posted by -zriptarusk
EDIT:
Wirdosport. Since this is a library, I don't think theres a way of knowing when the player left the menu without you calling a function.
Please call the 'DestroyPlayerInventoryMenu()' in 'OnPlayerExitedMenu'. This removes the menu from the memory and sets the player controllable.

Is the Item ID the same?
Because, it is supposed to only add the quantity if the itemid is the same.
I did end up using DestroyPlayerInventoryMenu, and it does the job.

As for the Item ID, I am fairly sure it was the same, as I only used the AddItemToPlayerInventory(); in 1 place for each individual package, and only used item id's 0 1 and 2. Is it ok to use id 0?
Do you mind posting the portion of the code where you add the items?
Because, I just made another gamemode and everything is working as it should.

:S I have no idea what is causing that.

Please post it so I can take a better look.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)