====== Inventories ====== Characters inventories are implemented as a specialisation of [[Sets]] (review this first) and extend [[Sets]] by defining Items, actions on those items (called Verbs internally), limits on inventories and so on. :!: NOTE: The Second Life dialog menu system can be quite limited in the number of characters it can display to a user, as such things like "Potion of Greater Healing" versus "Potion of Greater Fire Protection" or whatever may be indistinguishable through the Dialog menu. There is a component of the HUD called "UIXMenus" which uses prims and floating text to create a replacement for dialog boxes that has a broader display of characters. You can go to Configuration, GPHUDClient and edit ''GPHUDClient.UIXMenus'' and set this to true at the instance level, or if you wish to preview the change, set it to true for your particular character. While here you may also wish to check out the ''GPHUDClient.UIXBalance'' setting which I feel providers a more aesthetic layout, however you may make your own choices. The UIX code has been heavily tuned for performance even at the most overloaded of sims (should take a single frame of execution to set up the UIX menus) but you can test this and simply leave it disabled if it does not suit your setup. ====Inventories==== An Inventory is created by using Configuration -> Characters and creating a new Attribute of type INVENTORY. Give it an appropriate name like Backpack or Vault or similar. Once an Inventory is created, some dynamic KVs come into being ; under Configuration, Inventory you'll find 5 new attributes for controlling this inventory (replace Attributename with the name of the inventory): * ''Inventory.AttributenameAccessible'' - can the player access this inventory ; can be set to false and then overridden in zones or groups, otherwise if true the inventory is always accessible. * ''Inventory.AttributenameDefaultAllow'' - Can items be stored in this inventory by default (this can be set on a per item basis and just provides a default value) * ''Inventory.AttributenameMaxItems'' - Maximum number of items (regardless of quantity) storable in inventory. * ''Inventory.AttributenameMaxQuantity'' - Maximum total number of items (sum of quantities) storable in inventory. * ''Inventory.AttributenameMaxWeight'' - Maximum total weight that can be placed in this inventory (weight defined by items). ====Items==== Items can be configured under Configuration, Items. A new item can be created here, its name and description should be populated, and the weight, optionally, can be set (leave as zero if undesired). Please note that weight values must be Integers (whole numbers) so you should use a suitably small unit that you won't want "fractions" of, e.g. grams rather than kilograms. You can also tick two options for items defining if players may give the item to other players (a proper trade system may come in a future version, but for now players can simply give away items), or if the player can Destroy the item from their inventory. Once created, you may select the Item from the list under Configuration, Items. Here in you will be able to edit the basic settings for the item created above, and also toggle the "permitted" status for the item in various inventories. At the bottom of this page you can create "Actions" such as "Eat" "Throw" "Drink" etc and assign behaviours such as a script or a command, and optionally have the system automatically consume the item. NOTE: Regarding "Consumes Item" - if your script is likely to ask for user input (e.g. "throw at who") then you should not use the "Consumes Item" tickbox as this will immediately consume the item when invoked ; if the user then cancels or ignores the targeting dialog box the potion will simply have been lost. Instead you can call the appropriate gsFunction to remove the item once you actually enact the effect. Scripts called from Item actions have 3 variables introduced: * ''ITEMNAME'' - The name of the item being acted upon * ''INVENTORY'' - The name of the inventory the item was in * ''ITEMVERB'' - The name of the action ("Drink" "Eat" etc) Even if you do not use the above variables, adding a line at the start of your script such as
String protection=ITEMNAME;
will do nothing in a proper item invocation, however, if a user calls the script directly (say via /1scripting.scriptname) then the script will error due to ITEMNAME being an undefined variable name. ====Example Configuration==== In this example we will create a simple working inventory and items set up covering the following goals * Creation of two inventories, a Backpack and a Vault. * The Backpack should be always accessible. * The Vault should only be accessible when standing inside the Bank building (a Zone) * We will not bother to configure inventory item/quantity/weight limits as these are rather arbitrary balance/realism numbers that will make sense (or not be worth the effort) to your actual sim ; the limits work as discussed and are not particularly interesting to configure. * We will add some options to our HUD menu to interact or view inventories. ===Set up the inventories=== * Go to Configuration, Characters, create New Attribute called Backpack of type INVENTORY * Go to Configuration, Characters, create New Attribute called Vault of type INVENTORY * Go to Configuration, Zoning, create a zone called Vault and click on it, inside, add an area (appropriate to your instance) * Go to Configuration, Inventory, and change Inventory.VaultAccessible, set the instance value to false, and the Zone Vault value to True - this will make the vault only accessible when inside the bank zone. ===Create an Item Script=== * Go to Configuration, Scripting, create a script called healingPotion and edit it as follows: String itemCheck=ITEMNAME; Response response=gsAPIX(CALLER,"Health.healRoll",[CALLER,4,1,0,"Drank a potion of healing!"]); Integer discard=gsSayAsChar(CALLER,"/me consumes a potion of healing!"); ===Create an Items=== * Go to Configuration, Items and Create New Item, call it Healing Potion. * Click on the healing potion in the list and add an Available Action called "Drink" * Click on the newly created Drink action and bind it to "Invoke Script" "healingPotion", and tick "consumes item". Submit the changes. ===Add a way to interact with the inventory=== * To add to a menu, go to Menus, open your menu, and bind Inventory.Interact to a menu button * OR, perhaps, go to GPHUDClient and bind Inventory.Interact to a quick button