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.
I'm not familiar with how certain galaxy functions translate to GUI, so this library is incomplete. You're going to have to fix it up. I think I commented in every function that wouldn't work, I'm not sure. Its late, and I'm tired.
I also did a bit of second-guessing you on certain details, mainly choosing to use Unit Type for type instead of String.
I'm also not sure what 'fixed' is, so I think I always used an integer instead, I may have used a real or two.
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.
Just wanted to point out that the library seems to work alright, but the map is missing i = i-1 on the stack function, causing an infinite loop. Might confuse a few people trying to figure out what the map does.
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.
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.
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.
This is great job, ZyphreRZO. Using it for my map, it's real good.
BTW, I'm thought I'd ask you this. The way you used for items on target unit requires prestoring a target unit beforehand. Is there a way to use the item via the trigger, then player gets to select the target through cursor, only then the order is issued?
I cannot get the Ability Command for Inventory to show up in the trigger. It seems to only show Effect - Target type abilities. I have set a button to the Use Item (Instant) command for the Inventory Ability. Am I missing something?
I cannot get the Ability Command for Inventory to show up in the trigger. It seems to only show Effect - Target type abilities. I have set a button to the Use Item (Instant) command for the Inventory Ability. Am I missing something?
I'm having this same problem. It has to do with the inventory ability automatically assigning sub-abilities to manipulate items. You can't change "ItemInstant" to anything else, so changing it from "No Target" doesn't work. This is why any button assigned to ItemInstant doesn't show up in the Order Use Item Instant action - only abilities with targeting will show up (especially considering this function is a copy of "Issue Order Targeting Item.")
Could one of you two please try modifying the Use Item Instant trigger? Replace the line:
General - Return (cmd targeting item)
with
General - Return (Smart Command targeting item)
Tell me if that fixes anything.
Edit: It will still ask you to give a command in the trigger, because I didn't have you overhaul the entire function. It doesn't reference the command you give it anymore, so pick anything.
A glitch I ran into turned up something interesting.
I had a trigger that issued an order on every item in my inventory. I thought it would harmlessly ignore the instant use items, and I knew it wouldn't affect no-use items. But, to my surprise, when it came to the instant-use item, my unit walked over to the point I was targeting, and then used the item. Here was the trigger I was using:
Unit - Order (Triggering unit) to (Order Use Item Targeting Point( Use Item Targeted, (Item carried by (Triggering unit) in Seed Index), (Triggering ability target point))) (Replace Existing Orders)
What really baffles me, though, is that trigger was called every .5 seconds, and it should have replaced the order each time, but my unit happily walked over, taking several seconds, and avoiding using several items. I'm guessing it should be fairy safe to use Use Item Targeting Point to activate Instant use items, as long as you target the position of the unit that holds the item.
This might be a stupid question.. but how do I install the Library. I want to have the ability to issue order 'pickup item'. But I dont know where to paste that text.
Great work ZyphreRZO, just wondering how I could use the add/remove/set charges functions.
When ever I seem to be using them on last created item, the item charges is set and then once I use it, the charges become max charges then will never decrement on use.
Ive tried using these functions in your test map and it seems to not be working as well. Am I not using the functions correctly?
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
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.
I'm not familiar with how certain galaxy functions translate to GUI, so this library is incomplete. You're going to have to fix it up. I think I commented in every function that wouldn't work, I'm not sure. Its late, and I'm tired. I also did a bit of second-guessing you on certain details, mainly choosing to use Unit Type for type instead of String. I'm also not sure what 'fixed' is, so I think I always used an integer instead, I may have used a real or two.
@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.
Just wanted to point out that the library seems to work alright, but the map is missing i = i-1 on the stack function, causing an infinite loop. Might confuse a few people trying to figure out what the map does.
@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.
@ZyphreRZO: Go
I would like to pick up something from the inventory, like when right clicking an item that is inside the inventory. Is it possible to do with this ?
Could you give a list of what's inside the lib?
@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.
@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.
Really helpful. Props!
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.
This is great job, ZyphreRZO. Using it for my map, it's real good.
BTW, I'm thought I'd ask you this. The way you used for items on target unit requires prestoring a target unit beforehand. Is there a way to use the item via the trigger, then player gets to select the target through cursor, only then the order is issued?
Bump
I cannot get the Ability Command for Inventory to show up in the trigger. It seems to only show Effect - Target type abilities. I have set a button to the Use Item (Instant) command for the Inventory Ability. Am I missing something?
@Vortexx2010: Go
Check if your ability command type is set to No Target type.
I'm having this same problem. It has to do with the inventory ability automatically assigning sub-abilities to manipulate items. You can't change "ItemInstant" to anything else, so changing it from "No Target" doesn't work. This is why any button assigned to ItemInstant doesn't show up in the Order Use Item Instant action - only abilities with targeting will show up (especially considering this function is a copy of "Issue Order Targeting Item.")
@BasharTeg: Go
Could one of you two please try modifying the Use Item Instant trigger? Replace the line:
General - Return (cmd targeting item)
with
General - Return (Smart Command targeting item)
Tell me if that fixes anything.
Edit: It will still ask you to give a command in the trigger, because I didn't have you overhaul the entire function. It doesn't reference the command you give it anymore, so pick anything.
@BasharTeg: Go
A glitch I ran into turned up something interesting.
I had a trigger that issued an order on every item in my inventory. I thought it would harmlessly ignore the instant use items, and I knew it wouldn't affect no-use items. But, to my surprise, when it came to the instant-use item, my unit walked over to the point I was targeting, and then used the item. Here was the trigger I was using:
Unit - Order (Triggering unit) to (Order Use Item Targeting Point( Use Item Targeted, (Item carried by (Triggering unit) in Seed Index), (Triggering ability target point))) (Replace Existing Orders)
What really baffles me, though, is that trigger was called every .5 seconds, and it should have replaced the order each time, but my unit happily walked over, taking several seconds, and avoiding using several items. I'm guessing it should be fairy safe to use Use Item Targeting Point to activate Instant use items, as long as you target the position of the unit that holds the item.
This might be a stupid question.. but how do I install the Library. I want to have the ability to issue order 'pickup item'. But I dont know where to paste that text.
Thanks in advance
[EDIT] Figured it out. thanks.
Great work ZyphreRZO, just wondering how I could use the add/remove/set charges functions.
When ever I seem to be using them on last created item, the item charges is set and then once I use it, the charges become max charges then will never decrement on use.
Ive tried using these functions in your test map and it seems to not be working as well. Am I not using the functions correctly?