Just found a major bug when an item's max charges are equal to its starting charges - this is why some items weren't stacking right / charges not being used. The problem has been fixed. If you are using an older version of the library, it is highly recommended that you upgrade to version 1.15 as soon as possible.
As promised a new version of the library and map have been posted along with a description of the library. Some bugs were fixed and some functions were added.
Yeah, I'll make a quick reference of all of the functions. It also appears that the map is broken again... I'm looking in to it (It was working a few weeks ago). I do know that the custom script functions still work though (I use them in my project). I'll post an updated version of things here in a bit.
Looks like a good start. Fixed in galaxy is the same as real in the GUI. Also, certain types that exist in GUI do not exist at all in galaxy and are represented by integers (for handle types) and strings(for id types). Also, I did not mean to go through and fully recreate each function in GUI, I meant copy and paste as custom blocks inside GUI functions (Although this is kind of bugged at the moment and you have to use a GUI - Custom Script Action instead of checking the custom script checkbox). Well anyways, I'll try to finish converting the library so people can see how it works in both GUI and Galaxy. Heck, I'm kind of bored, I think I'll make a demo map too.
Oh, I forgot to add, for some reason item charges aren't based on whole numbers (integers) but fixed-point (real) numbers instead - this makes figuring out the code somewhat non-intuitive.
The lack of useful inventory functions in the Galaxy Editor is staggering. Here is a small library to help. It contains inventory queries, item charge manipulation, item stacking, and item use orders. Thanks to A52BcE's help, the library is now available in both galaxy (custom script) and GUI flavors so feel free to compare the two if learning custom script. Please post any bugs you find and addition requests.
Notes on using the library
- Don't use the charge functions on items which don't have charges (it won't work).
- I recommend making a behavior called stackable and adding it to your stackable items' units for easier stacking identification. (The map has an example of this)
- In order to use the orders you must have buttons assigned to the appropriate inventory ability. (This is also in the map).
- Items with charges must have a max # of charges AND a charge cost AND an appropriate charge link.
- Items are treated as units in game - this means you can use unit functions on them (If you didn't already know).
- Item type refers to the catalog unit type of an item NOT the catalog item type - you can get this with script using UnitGetType on an item's unit.
Helper Functions/Actions
Units in group of type - Gets a unitgroup containing all the units in a unitgroup of the specified type.
Order Set Target Item - Allows any order to additionally target an item.
Item Type Charge Link - Tries to determine the charge link associated with an item type.
Item Order Functions/Actions
Order Use Item Instant - Same as Order Targeting Item (included for naming convention purposes).
Order Use Item Targeting Point - Creates an order to use an item targeting a point.
Order Use Item Targeting Relative Point - Creates an order to use an item on a relative point.
Order Use Item Targeting Unit - Creates an order to use an item on a unit.
Item Type Functions/Actions
Item Type Max Charges - Gets the max number of charges an item type can have.
Inventory Query Functions/Actions
Inventory Count Items of Type - Counts the number of items of the specified type in a units inventory.
Inventory Get Items of Type - Gets a unitgroup containing all items in an inventory of the specified type.
Inventory Has Item of Type - Returns true if a unit has an item of specified type.
Inventory Get Random Item of Type - Returns a single item of the specified type that a unit might be carrying.
Inventory Total Charges Of Item Type - Returns the total charges of the specified item type in a units inventory.
Item Charge Functions/Actions
Item Set Charges Remaining - Sets the number of charges remaining on an item.
Item Get Charges Used - Returns the number of charges used on an item.
Item Get Charges Remaining - Returns the number of charges remaining on an item.
Item Add Charges - Adds the specified number of charges to an item.
Item Remove Charges - Removes the specified number of charges from an item and removes the item if it becomes <= 0.
Inventory Management Functions/Actions
Inventory Remove Item Charges Of Type - Removes the specified number of charges from the item charge total of the specified item type in a units inventory.
Inventory Stack Items of Type - Stacks all items of the specified type in a players inventory.
Just found a major bug when an item's max charges are equal to its starting charges - this is why some items weren't stacking right / charges not being used. The problem has been fixed. If you are using an older version of the library, it is highly recommended that you upgrade to version 1.15 as soon as possible.
@ZyphreRZO:
As promised a new version of the library and map have been posted along with a description of the library. Some bugs were fixed and some functions were added.
@vjeux:
Yeah, I'll make a quick reference of all of the functions. It also appears that the map is broken again... I'm looking in to it (It was working a few weeks ago). I do know that the custom script functions still work though (I use them in my project). I'll post an updated version of things here in a bit.
@A52BcE: Go
Yeah, somehow I forgot to save the map after importing the working item library (it's more than just the i = i - 1) ... I've fixed it.
@A52BcE:
Looks like a good start. Fixed in galaxy is the same as real in the GUI. Also, certain types that exist in GUI do not exist at all in galaxy and are represented by integers (for handle types) and strings(for id types). Also, I did not mean to go through and fully recreate each function in GUI, I meant copy and paste as custom blocks inside GUI functions (Although this is kind of bugged at the moment and you have to use a GUI - Custom Script Action instead of checking the custom script checkbox). Well anyways, I'll try to finish converting the library so people can see how it works in both GUI and Galaxy. Heck, I'm kind of bored, I think I'll make a demo map too.
Oh, I forgot to add, for some reason item charges aren't based on whole numbers (integers) but fixed-point (real) numbers instead - this makes figuring out the code somewhat non-intuitive.
The lack of useful inventory functions in the Galaxy Editor is staggering. Here is a small library to help. It contains inventory queries, item charge manipulation, item stacking, and item use orders. Thanks to A52BcE's help, the library is now available in both galaxy (custom script) and GUI flavors so feel free to compare the two if learning custom script. Please post any bugs you find and addition requests.
Notes on using the library
- Don't use the charge functions on items which don't have charges (it won't work).
- I recommend making a behavior called stackable and adding it to your stackable items' units for easier stacking identification. (The map has an example of this)
- In order to use the orders you must have buttons assigned to the appropriate inventory ability. (This is also in the map).
- Items with charges must have a max # of charges AND a charge cost AND an appropriate charge link.
- Items are treated as units in game - this means you can use unit functions on them (If you didn't already know).
- Item type refers to the catalog unit type of an item NOT the catalog item type - you can get this with script using UnitGetType on an item's unit.
Helper Functions/Actions
Units in group of type - Gets a unitgroup containing all the units in a unitgroup of the specified type.
Order Set Target Item - Allows any order to additionally target an item.
Item Type Charge Link - Tries to determine the charge link associated with an item type.
Item Order Functions/Actions
Order Use Item Instant - Same as Order Targeting Item (included for naming convention purposes).
Order Use Item Targeting Point - Creates an order to use an item targeting a point.
Order Use Item Targeting Relative Point - Creates an order to use an item on a relative point.
Order Use Item Targeting Unit - Creates an order to use an item on a unit.
Item Type Functions/Actions
Item Type Max Charges - Gets the max number of charges an item type can have.
Inventory Query Functions/Actions
Inventory Count Items of Type - Counts the number of items of the specified type in a units inventory.
Inventory Get Items of Type - Gets a unitgroup containing all items in an inventory of the specified type.
Inventory Has Item of Type - Returns true if a unit has an item of specified type.
Inventory Get Random Item of Type - Returns a single item of the specified type that a unit might be carrying.
Inventory Total Charges Of Item Type - Returns the total charges of the specified item type in a units inventory.
Item Charge Functions/Actions
Item Set Charges Remaining - Sets the number of charges remaining on an item.
Item Get Charges Used - Returns the number of charges used on an item.
Item Get Charges Remaining - Returns the number of charges remaining on an item.
Item Add Charges - Adds the specified number of charges to an item.
Item Remove Charges - Removes the specified number of charges from an item and removes the item if it becomes <= 0.
Inventory Management Functions/Actions
Inventory Remove Item Charges Of Type - Removes the specified number of charges from the item charge total of the specified item type in a units inventory.
Inventory Stack Items of Type - Stacks all items of the specified type in a players inventory.