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.
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 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 uponINVENTORY
- The name of the inventory the item was inITEMVERB
- 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 <pre>String protection=ITEMNAME;</pre> 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.
In this example we will create a simple working inventory and items set up covering the following goals
work as discussed and are not particularly interesting to configure.
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!");