Difference between revisions of "Script:Backpack"
From Roll20 Wiki
(→Item Definitions) |
(→enigmas) |
||
Line 217: | Line 217: | ||
{{syntaxbox end}} | {{syntaxbox end}} | ||
− | When an item with an enigma is added into a backpack compatible journal, its enigma name is considered a first class citizen for all purposes of any inventory actions (moving, giving, taking, dropping) save for specific actions such as 'use' which require identification. Therefore when one adds an item with an enigma option, they need to place special care as to the chosen enigma name so it does not conflict with other enigma names, as well as existing items. | + | When an item with an enigma is added into a backpack compatible journal, its enigma name is considered a <u>first class citizen</u> for all purposes of any inventory actions (moving, giving, taking, dropping) save for specific actions such as 'use' which require identification. Therefore when one adds an item with an enigma option, they need to place special care as to the chosen enigma name so it does not conflict with other enigma names, as well as existing items. |
<code>Longsword;weapon:sword 4lbs 15gp</code><br><br> | <code>Longsword;weapon:sword 4lbs 15gp</code><br><br> |
Revision as of 22:31, 27 June 2015
API Script
Author: Ken L.
Version: 1.25
Last Modified: 2015-6-24
Code: NA
Dependencies: None
Conflicts: Unknown
Contents |
Backpack is a journal based inventory system that updates the 'bio' section of a journal to represent a graphic inventory interface. This allows GMs whom implement this script to allow players to manage a graphic representation of their inventory. Once setup, you can move, give, drop, and pickup items through the use of the API button interface as well as buy and sell from shops and stores should they be prepared.
To use this script requires quite a bit of setup on the part of the GM preparing the asset and item databases. The asset database is simply a list of available item types/subtypes and their associated images. The item database is a list of parsable item definitions which can be short hand written to loot drops or any backpack compatible journal entry.
Getting Started
Once you load the backpack.js and backpack_tmp.js scripts into your campaign, you'll need to at least create an asset database.
After creating an asset database, you're ready to populate backpack compatible journal entries as inventories, stores, or loot cache drops.
General Use
TODO
Player Inventory
Store
Loot drop
Commands
Many Backpack commands are automated, but there are a handful that still need to be manually invoked.
GM commands
create
load
close
show_active
show_loot
show
single
place
identify
reload_db
Player commands
move
give
give_exact
buy
sell
sell_exact
pay
take
drop
use
charge
Internal commands
charge_exact
bpRelay
Item Definitions
Item definitions are the format in which entries of items are parsed into the script. They consist of several parts.
[quantity] <name>;<type> [weight] [value] [description] [use] [maxcharge] [enigma]
Formally:[quantity]
name
type
[optionals]
[quantity]
name
type
subtype
[optionals]
name
→ Name of the item, see name
type
→ Existing type in backpack_tmp.js, see type
sybtype
→ Existing subtype defined in the asset database, see subtype
quantity
→ Optional quantity of the item, see quantity
weight
→ Optional weight of the item in lbs, see weight
value
→ Optional value of the item, see value
description
→ Optional description of the item, see description
use
→ Optional use argument to be executed, see use
maxcharge
→ Optional max charges of the item, see charges
enigma
→ Optional enigma arguments, see enigmas
An Item definition at the bare minimum requires a name, and a type with the remaining optional parameters in any order (excluding subtype which branches from type) separated by at least one white space character.
Examples:
String of Beads;misc 1cp
498 Diamond Dust; misc:cyandust 1gp
7 Silver Chalice; treasure:trophy 10pp 5gp 8cp
1 +2 Trident; weapon:trident 40pp 8gp 3lbs
2 Bolt; weapon:bolt 1gp 0.1lb
1 Magic Spoon; weapon 500pp 0.1lb desc:(this magic spoon was once used by a Thulgar the great, a halfling of great renown)
7 Greatsword; weapon:greatsword 1pp 5gp 6lbs
1 Potion of Invisibility; potion:white 30pp 0.1lb use:( )
4 Potion of Cure Moderate Wounds; potion:blue 30pp 0.1lb use:(Heal [[2d8+3]])
1 Wand of Cure Light Wounds[41]; wand 75pp use:((Heal [[1d8+1]]))
1 Staff of Life[8];staff 109400gp 5lbs use:(Heal for 1 charge, Raise dead for 5 charges)
name
The name parameter is essential to the item definition and must be unique for this item. Names of items are case insensitive and considered first class citizens along with enigma names. Names can contain any character including numbers but cannot start with a number else that number will be considered a quantity.
Names have a special suffix case where if it has a suffix of [<number>]
it can denote charges. In this case the name of the item is everything preceding this suffix. For the example of 'Wand of Bless[50]'
, 'Wand of Bless'
is the base item name, and '[50]'
is parsed out as the number of charges this item has. This is such that items of the same charge amount can stack and separate in quantity as they're used. Clearly an item named 'Staff of bolts'
and 'Staff of bolts[10]'
would be seen as the same item; but one definition denotes that the item has charges, and the other does not, 'Staff of bolts'
is not the same as 'Staff of bolts[0]'
despite having the same name identifier. For the purposes of charging this item, 'Staff of bolts[0]'
could be charged and 'Staff of bolts'
could not.
If there are multiple items with the same name identifier the combined result of the receiving location will have its quantity increased even if the donating location's item definition is different in other areas from the receiving location's definition.
An example would be moving a 'flute' from A → B where say A has 5 flutes and B has 2 flutes. The difference between A and B's flutes despite having the same name is that they have different descriptions or weights despite having the same primary identifier as 'flute'. If you move 1 flute A → B then B would have 3 flutes and A 4 as expected, but B will simply have it's quantity altered, as opposed to another 'flute' item being generated matching A's flute definition.
A simple resolution to this to have the name be more descriptive such as 'Alfreds Flute' and 'Bernard's Flute'. Special care must be taken such that these names do not conflict with introduced enigma names
type
The type parameter is essential to the item definition as it connects the item definition to a display template that exists in backpack_tmp.js as well as an image for the type. A legal type is defined within the script, therefore only a fixed number of types exist. This can be extended upon by editing backpack_tmp.js, see customizing for details. All types are case sensitive and can only include characters [A-Za-z] plus '-' and '_'.
Type name | Description |
---|---|
potion | template for potions |
weapon | template for weapons |
armor | template for armor |
wand | template for potions |
staff | template for staves |
ring | template for rings |
scroll | template for scrolls |
misc | template for miscellaneous |
food | template for food |
treasure | template for treasure |
gem | template for gems |
No item definition can exist without a valid type, compared to subtypes which are optional, and enumerable within the asset database.
Some types are associated with one or more categories which can add special behaviors to all items of this type, implicitly including all of its subtypes. Categories are assigned to types within the asset database.
subtype
The subtype is not essential to to the item definition so long as the type it branches off exists. Subtypes exist primarily for the purpose of image enumeration categorized by type. For example from scroll:scroll_ancient
we can extract scroll
as the type and scroll_ancient
as the subtype. scroll:scroll_ancient
could refer to a withered image of parchment where as scroll:scroll_empowered
could refer to an image of a glowing scroll. There are no naming conventions other than what is a legal type name so weapon:greataxe
is valid as well.
Types (type and subtype) as presented by this script are used to
A.) Provide a template for the item
B.) Allow propagation for item images related to the base type
quantity
The quantity of an item is optional to the item definition but is never left undefined. If not provided it represents an infinite pool of the item for backpack journals configured as stores, but otherwise defaults to 1 for all other purposes (loot caches, inventories). If defined, the quantity is defined before the item name, typically a white space separating the two.
weight
The weight of an item is optional and considered 0, or weightless if not provided. Weight is parsed as a number immediately followed by lb
or lbs
. Valid examples are:
45lbs
0.5lb
100lb
Correct plurality for lb
isn't a factor.
value
The value of an item is represented as the combination of numbers followed by short-hand names of the currency denominations defined in the script's design section. By default these denominations are platinum, gold, silver and copper. Their respective short names are thus 'pp', 'gp', 'sp', and 'cp'. Therefore the value of an item can be represented by the examples:
10gp 2sp 1cp
35pp 353gp
42098gp 2004sp 350000cp
Internally, when the script processes the item definition, it unifies the value into a single total and upon display, will divide this unified value into the minimum of each denomination required. Upon saving this item definition this minimum coinage value is recorded as opposed to the original representation.
The denomination values are defined internally in the script's design section. This and currency names can be altered as explained in customizing.
description
The description argument is optional, typically containing some textual information regarding the item. It follows the syntax desc:(<text>)
where <text>
is anything except parenthesis. Valid examples include:
desc:(This old hat was once worn by haggard the great)
desc:(This artifact was one of the 4 shards spread across the continent. It radiates a dim red light around its edges..)
use
The use argument is optional, but if defined will configure the item as 'usable'. Then the item is 'used' it will output the use content that was stored in the use argument. Valid examples are:
use:(Healing [[1d8+1]])
use:( )
use:(DC 15 Reflex save or blinded!)
By default, if a usable item is used without a set quantity, it will execute the use argument once; else it will execute the use argument as many times as the quantity requested unless this behavior is altered by a category on the item's type.
charges
Charges, if an item has them, are defined as a suffix of the item name (non-inclusive of the name) ending in [<number>]
where <number>
is the amount of charges an item has. An item that 'has' charges, in that it contains this suffix, can be used if the use argument is present to decrease the number of charges. By default, the script will use a single charge if no exact number is given. The auto-generated macro for the use button specifically asks the number of charges to use.
Depending on the category associated with the type as defined in the asset database, when the item is used, it can output its use argument in several ways.
enigmas
Enigmas are a special optional item argument that essentially masks the true item's identity; and is itself a mini item definition comprising of an enigma name and an enigma description.
enigma:(<enigma name>;<enigma description>)
Formally:enigma:(
enigma name
enigma description
)
enigma name
→ A name that masks the item definition's true name
enigma description
→ The description of the enigma'd item
When an item with an enigma is added into a backpack compatible journal, its enigma name is considered a first class citizen for all purposes of any inventory actions (moving, giving, taking, dropping) save for specific actions such as 'use' which require identification. Therefore when one adds an item with an enigma option, they need to place special care as to the chosen enigma name so it does not conflict with other enigma names, as well as existing items.
Longsword;weapon:sword 4lbs 15gp
is considered to have the same name identifier as
+1 Longsword;weapon:sword 4lbs 2015gp enigma:(Longsword;This sword appears naturally light and cuts through the air with ease)
Assuming an inventory had a longsword, and this enigma masked +1 Longsword was added to it, the longsword quantity would simply increase as opposed to adding a new masked enigma item of a +1 longsword. This however works well for the case of say identifying yet another potion which an inventory already has many of.
Potion of Cure Light Wounds;potion 0.1lb 50gp use:(Heal [[1d8+1]])
Potion of Cure Light Wounds;potion 0.1lb 50gp use:(Heal [[1d8+1]]) enigma:(Murky Vial;This blue vial's liquid swirls with several hues of blue)
These two item definitions despite having the same name identifier can co-exist in the same inventory due to the property of enigma names. If the enigma is lifted from the Potion, then it would add itself cleanly to the quantity of the known potions.
Enigma items use the enigma template which makes the enigma image a link to a command that identifies the item within the inventory it's in. So if an unidentified ring is on the floor, one could add it to their inventory and identify it there, or identify it on the floor. Extending further, you could give this unknown item to someone else and identify it in their inventory.
One restriction to identifying enigma items is that the linked command will only work for the GM therefore it's assumed that after some RP or skill check, the GM can identify the item. It also adds an air of mystery for items not identified floating around in player inventories, as well as the unveiling when the mask is lifted, all with the click of a button.
Know that after an item has its enigma removed, the item definition will have its enigma argument stripped from it. If one wants to preserve this argument, you can save a copy of the original definition elsewhere.
Asset Database
The asset database is a journal entry that contains within its gmnotes section the library of images to be used for item definitions through their type and subtype
The asset database has a simple format where each line is a single asset entry (blank lines between groups of entries are fine).
Each asset entry is in either of the following formats:
<type>:<link>
<type>:<subtype>:<link>
Formally:
type
subtype
link
type
link
type
→ Existing type in backpack_tmp.js
sybtype
→ Any valid subtype name except ε
link
→ HTML link to the image source, must start with 'http' case insensitive
category
A category is an additional layer of logical classification for an item type outside of defining a template and enumerating subtypes. They are assigned within the asset database as a prefix to a listed type of the form:
{category}<type>:<link>
or
{category}<type>:<subtype>:<link>
It should be noted that despite the two formats, categories are always applied to the base type, they are never applied to the subtype. In the case {CONSUMABLE}wand:http://i.imgur.com/LGF3DHG.png
and {CHARGEABLE}wand:pearl:http://i.imgur.com/LGF8DGJF.png
on separate lines would first associate the CONSUMABLE
category with wand, then add the CHARGEABLE
category as a side effect of adding the wand:pearl
subtype.
Categories are currently built into the script to have certain meanings and the only flexibility granted by assigning them in the asset database is that you're attaching the behavior associated with this category to the type. All categories grant a certain behavior to items that are defined as follows:
Category name | Description |
---|---|
VARIABLECHARGE | Declares that the type is variable charge in that when multiple charges are used, it does not mean that the it was used that number of times. Using 5 charges does not indicate that the use argument is replicated 5 times as perhaps 5 charges were used to activate a secondary effect. The use argument is only displayed once and the number of charges decremented from the total charge. |
CONSUMABLE | Declares that the type when used will remove itself from inventory after use if usable. If there is a certain quantity of this item, this quantity will be reduced. If this item has charges, there is no effect, even at 0 charges. |
CHARGEABLE | Declares that the type is chargeable, where charges can be added back to the item if it has charges. This will add the 'charge' button to the item. If the item has a defined 'maxcharge' then it cannot exceed this maximum and will set itself to maximum if charged over this limit. |
All currently defined categories can overlap in the behaviors they grant without conflict.
Item Database
TODO
Customizing
Templates
Design
Fields
Changelog
TODO