Character Vault
Any Concept / Any System
Compendium
Your System Come To Life
Roll20 for Android
Streamlined for your Tablet
Roll20 for iPad
Streamlined for your Tablet

Personal tools

Script:RPGMaster Library

From Roll20 Wiki

Jump to: navigation, search
Main Page: API:Script Index

API ScriptAuthor: Richard E
Version: 1.5.01
Last Modified: 2023-05-17
Code: RPGMlibrary AD+D2e
Dependencies: None
Conflicts: None

RPGMaster Scripts

The RPGMaster suite of APIs is a set of APIs created primarily for enhancing AD&D 2E gameplay, made by Richard E. The APIs are compatible with the Advanced 2nd Edition character sheet.

Some of the APIs can be used with other sheets.

Forum

RPGMaster APIs for AD&D 2E - main forum thread

Contents


RPGMaster Library

The RPGMaster series of APIs has been designed to work with multiple RPG systems and rulesets (although only AD&D2e is actually currently supported, as that is what the Author mostly plays!). In releases later than v1.3.00 (01/10/2022), all RPG version-specific data, rulesets and processing has been extracted from the APIs and moved into an RPGMaster Library API that must be loaded alongside the RPGMaster APIs you wish to use (except Script:RoundMaster which is RPG version independent). Which version of the RPGMaster Library is loaded will determine the RPG version and Roll20 Character Sheet version that is supported by the APIs: as of now, only the following versions exist:

  • RPGMaster Library AD+D2e - supports Advanced Dungeon & Dragons V2e and the Advanced AD&D2e Character Sheet by Peter B.

General RPGMaster Library information

The RPGMaster Library API provides the data and rule-set processing for a specific RPG version and Roll20 Character Sheet for the RPGMaster series of APIs. This particular Library supports the Advanced Dungeons and Dragons v2e RPG, and the Advanced D&D 2e Character Sheet by Peter B.

The functions and data in the Library cannot be accessed directly by the GM or Players (with the exception of the RPGMaster Roll Templates). It does not support any API commands directly, but supports the functioning of the API commands provided by other RPGMaster APIs: InitiativeMaster, AttackMaster, MagicMaster and CommandMaster, to the extent that these APIs will not function without the Library being loaded. Note: RoundMaster does not have any RPG-version specific aspects, is independent of the Library, and does not require a RPGMaster Library to be loaded to function.

The Library does Roll Template processing for RPGMaster-defined Roll Templates. These can be used by GMs to create their own Chat menus and displays. See the descriptions in Section 2 for how to access and use these templates.

The Library also provides a number of objects and functions that can be called from other APIs. These include an extensive Character Sheet table management suite described in Section 3 below, for table structures defined by The Aaron in various standard Roll20 Character Sheets, such as the Advanced D&D 2e character sheet by Peter B. There are a number of other useful functions, which are described in Section 3.

RPGMaster Roll Templates

Roll Templates are standard Roll20 functionality, often provided by various Character Sheet versions. The RPGMaster Library provides RPGMaster-specific versions of Roll Templates to support gameplay using the RPGMaster series of APIs. Of course, they can also be used for other purposes by the GM to support their design for gameplay, and by other APIs that might be loaded alongside the RPGMaster Library API. The list of those provided is:

TemplateBased onDescription
RPGMattackRPGMattackFormat the results of attacks, Melee or Ranged
RPGMpotionRPGMspellDisplay the details of a potion, oil or other consumable liquid
RPGMspellRPGMspellDisplay the specification of a spell or power
RPGMscollRPGMspellDisplay the details of a scroll or book
RPGMmessageRPGMmessageDisplay a formatted message
RPGMwarningRPGMdefaultDisplay a warning message in a bold format
RPGMweaponRPGMdefaultDisplay the specification of a weapon of any type
RPGMammoRPGMdefaultDisplay the specification of ammunition for a Ranged weapon
RPGMarmourRPGMdefaultDisplay the specifications of any form of armour
RPGMringRPGMdefaultDisplay the specifications of a ring
RPGMwandRPGMdefaultDosplay the specifications of a wand, stave or rod
RPGMitemRPGMdefaultDisplay the specifications of any magic item
RPGMclassRPGMdefaultDisplay the details of a character class
RPGMmenuRPGMdefaultDisplay a menu of actions that a Player or GM can perform
RPGMdefaultRPGMdefaultA default template that can display any form of information

The templates are built upon four base templates: RPGMattack, RPGMspell, RPGMmessage, and RPGMdefault. However, each individual template can have different colour swatches and background images. It is also possible for the GM to use special template field tags to change the colours and background images of various parts of the templates, as described below.

User-Selectable Template Display Options

In the API configuration menu, opened using !attk --config or !magic --config, the GM can choose whether the default display of RPGMaster Roll Templates for everyone is Fancy, meaning the system uses background textures and images to make the chat templates look interesting, or Plain, which means the default display is of coloured templates but without textures or images.

In addition, each Player can choose their own options: at the top right of every menu or message displayed in the chat using a RPGMaster Template is a cog wheel. Clicking this cog wheel will display an options dialog for the Player with three options - Menus with Images, Plain Menus, and Dark Mode Menus. The Player can select one of the options, and the current and all future menus and messages using RPGMaster Roll Templates will be displayed for that particular Player using this new option. The option persists for that Player between gameplay sessions.

Note: if use of a template includes any of the colour or image field tags (outer image, title image or body image) these images will always appear regardless of which option the Player chooses. The field tags always override the original template definition.

Colour, Padding and Image Override Field Tags

All RPGMaster templates can use the following field tags (with some exceptions as noted). The field tags are used in this way:

{{field tag=... whatever you want to be in this field ...}}

However, the fields in this table do not display data, but take the content of the field after the "=" as data for a CSS command to change the behavior of the template.

shadowdrop shadow specThe specification of the Template drop shadow for the outer box in any form of CSS units
outercolorThe colour of the outer box of the template
title boxcolorThe fill colour of the title box
title textcolorThe colour of the title text
body boxcolorThe fill colour of the body box
row boxcolorThe colour of the outline of each row box
row lightcolorThe fill colour of alternate row boxs (light / dark / light / dark ...)
row light textcolorThe colour of alternate row text (light / dark / light / dark ...)
row darkcolorThe fill colour of alternate row boxs (light / dark / light / dark ...)
row dark textcolorThe colour of alternate row text (light / dark / light / dark ...)
outer padpadding specThe padding of the outer box specified using any form of CSS measurements
title padpadding specThe padding of the title box specified using any form of CSS measurements
body padpadding specThe padding of the body box specified using any form of CSS measurements
row padpadding specThe padding of each row box specified using any form of CSS measurements
outer imageImage URLThe URL to an image in Roll20 which will be drawn behind the whole Template
title imageImage URLThe URL to an image in Roll20 which will be drawn behind the title box
body imageImage URLThe URL to an image in Roll20 which will be drawn behind the body of the Template

The data passed with these field tags is one of four types: color, padding spec, shadow spec or image URL. Note, the CSS keyword is not needed in each case, just the data specification that would follow the keyword.

Tip: In fact, you can sneak additional CSS keywords into the data - e.g. the title text colour could be 'Template:Title text=white; text-shadow: 1px 1px 1px gray' which would sneak a drop-shadow onto the title text of the Template. This will not always work, but is worth trying.

colorCan be any valid < color > specification that can be placed after a CSS < color > command: a named color, a RGB specification, a HSL specification, or any other valid syntax.
padding specCan be any valid padding < length > specification that can be placed after a CSS < padding > command: relative units such as 'em' or 'small' or percentages, or can be absolute units such as 'px' or 'cm'.
shadow specCan be any valid shadow < length > and < color > specification that can be placed after a CSS < box-shadow > command: relative units such as 'em' or 'small' or percentages, absolute units such as 'px' or 'cm'; and a named color, a RGB specification, an HSL specification, or any other valid <color> syntax.
Image URLMust be a valid URL of a thumbnail image already loaded to the Roll20 image library - either your own or one you are provided with.

Template Definitions

RPGMattack

As with any template, the text in any of the fields can be anything allowed by Roll20 in a macro or template, except where noted otherwise. If to be used with a RPGMaster API database, the Specs and Data fields must be configured in line with the relevant database documentation and placed between the template fields so as not to be seen by the Players when the Roll Template is displayed. This is a highly graphical template (even in Plain Mode) and the Field Tags are generally not displayed.

Title / NameMandatoryThe title text for the attack template. Either field tag can be used, and the tag is not displayed.
SubtitleOptionalThe subtitle text for the attack template. The tag is not displayed.
AC hitMandatoryThe value of the Armour Class that has been successfully hit by the attack. Can be a Roll20 calculation and/or dice roll specification. If the "Crit Roll" and "Fumble Roll" field tags are to function correctly, the AC hit tag must include one Roll20 calculation field tagged as the Dice Roll e.g. matches ##[Dice roll].
Attk typeOptionalThe type of damage done by the attack: S, P, B, or any combination of these.
Dmg S LabelOptionalThe label / title to display for the Dmg S field on the template. If not provided, it defaults to "S / M". Useful if using the template for attacks that result in some outcome other than damage to the opponent.
Dmg SMandatoryThe specification to display for damage to Small & Medium opponents. Can be numeric, a Roll20 calculation, dice roll specification, or even an API button specification.
Dmg L LabelOptionalThe label / title to display for the Dmg L field on the template. If not provided, it defaults to "L". Useful if using the template for attacks that result in some outcome other than damage to the opponent.
Dmg LMandatoryThe specification to display for damage to Large and larger opponents. Can be numeric, a Roll20 calculation, dice roll specification, or even an API button specification.
Target ACOptionalThe Armour Class value of the targeted opponent. Only used for targeted attacks. Can be a Roll20 "@{target..." command, numeric value, calculation etc.
Target SACOptionalThe Armour Class value of the targeted opponent vs. Slashing attacks. Only used for targeted attacks. Can be a Roll20 "@{target..." command, numeric value, calculation etc.
Target PACOptionalThe Armour Class value of the targeted opponent vs. Piercing attacks. Only used for targeted attacks. Can be a Roll20 "@{target..." command, numeric value, calculation etc.
Target BACOptionalThe Armour Class value of the targeted opponent vs. Bludgeoning attacks. Only used for targeted attacks. Can be a Roll20 "@{target..." command, numeric value, calculation etc.
Target HPOptionalThe current Hit Points of the targeted opponent. Must result in a numeric value.
Target MaxHPOptionalThe maximum Hit Points of the targeted opponent. Must result in a numeric value.
ResultOptionalA comparison function between any two other field tags, which are usually AC_Hit and Target_AC (note the underscores added). Can use any test from: = < > <= >= <> != e.g. AC_Hit<=Target_AC if true will give a green Success bar, if false will give a red Failure.
SuccessCmdOptionalThe text provided will not be displayed but will be sent to the chat window if the Result comparison indicates success. Normally used to send an API command on a successful attack result
FailCmdOptionalThe text provided will not be displayed but will be sent to the chat window if the Result comparison indicates failure. Normally used to send an API command on a failed attack result
Crit RollOptionalData must result in a numeric value which is compared to the Dice Roll value tagged in the AC Hit field. If Crit_roll<=Dice Roll, displays a green "Critical Hit!" bar.
Fumble RollOptionalData must result in a numeric value which is compared to the Dice Roll value tagged in the AC Hit field. If Fumble_roll>=Dice Roll, displays a red "Fumbled!" bar.
Desc / Desc(1-9)OptionalUp to 10 description fields can be added to the bottom of any RPGMaster attack template. The field tag is not displayed. These can, for example, hold reminders of special outcomes of the attack depending on the weapon or creature wielding it, or the roll achieved.

RPGMspell, RPGMpotion & RPGMscroll

As with any template, the text in any of the fields can be anything allowed by Roll20 in a macro or template, except where noted otherwise. For spell, potion and scroll descriptions especially it is quite often useful to include API Buttons in some of the fields to run certain RPGMaster API commands: this is especially the case if using the RoundMaster API and the commands !rounds --target to set status markers and timers and target spell effects, and/or !rounds --aoe to display ranges and areas of effect. If to be used with a RPGMaster API database, the Specs and Data fields must be configured in line with the relevant database documentation and placed between the template fields so as not to be seen by the Players when the Roll Template is displayed.

Title / NameMandatoryThe title text for the template. Either field tag can be used, and is not displayed.
SPlevelOptionalThe level of the spell being cast. No need to provide for potions or scrolls.
SchoolOptionalThe school of the spell or spell-like effect.
RangeMandatoryThe range of the spell or spell-like effect.
ComponentsMandatoryThe components of the spell or spell-like effect. Often represented by a combination of the letters VSM.
DurationMandatoryThe duration of the spell or spell-like effect.
RangeMandatoryThe range of the spell or spell-like effect.
TimeMandatoryThe casting time or time until effect occurs of the spell or spell-like effect.
AoEMandatoryThe Area of Effect of the spell or spell-like effect.
SaveMandatoryThe validity and outcome of any saving throw or other mitigating factors to the spell or spell-like effect.
HealingOptionalThe healing or other beneficial effect of the spell or spell-like effect.
DamageOptionalThe damage or other maleficent effect of the spell or spell-like effect.
ReferenceOptionalA reference to where more information can be found about the spell or spell-like effect.
MaterialsOptionalThe material components required to cast the spell or spell-like effect.
Looks LikeOptionalA description of what the item looks like (for potions & scrolls), especially useful for hidden items.
EffectsOptionalA description of the effects of the spell or spell-like effect.
UseOptionalInstructions for how to use the spell or spell-like effect. Especially useful for complex spells that require actions to occur in a particular sequence, have different means of achieving different effects in different circumstances, or have long-lasting effects.
GM InfoOptionalOnly appears if the message is for the GM (though other players included in the same message will also see it). Instructions for the GM on how to use the spell or spell-like effect, such as how to tailor for your own campaigns.
Desc / Desc(1-9)OptionalUp to 10 description fields can be added to the bottom of any RPGMaster spell, potion or scroll template. The field tag is not displayed. These can, for example, hold reminders of special outcomes of the spell depending on the creature targeted, or anything else the GM thinks useful but does not fit in any other field.

RPGMmessage

This template is mostly used internally by the RPGMaster APIs to send messages to the GM and Players. It provides a very simple template with a minimum of overhead. As with any template, the text in any of the fields can be anything allowed by Roll20 in a macro or template, except where noted otherwise. If to be used with a RPGMaster API database, the Specs and Data fields must be configured in line with the relevant database documentation and placed between the template fields so as not to be seen by the Players when the Roll Template is displayed.

Title / NameOptionalThe title text for the template. In a Message Template, the title/name is optional and a message can appear without a title if so desired. Either field tag can be used, and is not displayed.
Desc / Desc(1-9)OptionalUp to 10 description fields can be defined, though usually it is just the one, which will contain the message. The field tag is not displayed.

RPGMdefault

All template definitions other than those described above use the base RPGMdefault template structure, with different colour swatches, textures and images. This template type is the most flexible, and will display pretty much any field tag that is added. Only a few are predefined, which provide the ability to structure the template. As with any template, the text in any of the fields can be anything allowed by Roll20 in a macro or template, except where noted otherwise. If to be used with a RPGMaster API database, the Specs and Data fields must be configured in line with the relevant database documentation and placed between the template fields so as not to be seen by the Players when the Roll Template is displayed.

Title / NameMandatoryThe title text for the template. Either field tag can be used, and the tag is not displayed.
SubtitleOptionalThe subtitle text for the template. The tag is not displayed.
Section / Section(1-9)OptionalA section header, separating other user-defined field tags (not the Desc description field tags, which always appear at the bottom of the template). The field tag is not displayed, and the contents are centred in the row.
Any User-defined tagOptionalAs many different user-defined field tags as are desired, using A-Z a-z - _ 0-9 and Space but always starting with an Alpha.
ResultOptionalA comparison function between any two other field tags which have numeric data or calculations and attribute look-ups that result in numeric data. The field tag names to be compared should have underscores '_' instead of spaces. Can use any test from: = < > <= >= <> != e.g. AC_Hit<=Target_AC if true will give a green Success bar, if false will give a red Failure.
SuccessCmdOptionalThe text provided will not be displayed but will be sent to the chat window if the Result comparison indicates success. Normally used to send an API command on a successful attack result
FailCmdOptionalThe text provided will not be displayed but will be sent to the chat window if the Result comparison indicates failure. Normally used to send an API command on a failed attack result
GM InfoOptionalOnly appears if the message is for the GM (though other players included in the same message will also see it). Instructions for the GM on whatever the roll template is about, such as how to tailor a magic item for your own campaigns.
Looks LikeOptionalA description of what the item looks like, especially useful for hidden items.
Desc / Desc(1-9)OptionalUp to 10 description fields can be defined, which will all be displayed at the bottom of the template in numeric order. The field tags are not displayed.

API Library Accessible Functions

In addition to the RPGM Templates described in Section 2, the RPGMaster Library provides a number of functions, objects and methods that might be of use to API authors, independantly of the RPGMaster series of APIs. These are described in this section. To access these, the functions can be accessed using the following syntax from other APIs:

LibRPGMaster.function( parameters )

Alternatively, so as not to need to reference the Library, and/or to facilitate an easily alterable and maintainable reference that can be changed in one place, the Library reference can be made within a function mapping, like this:

const localFunctionName = (...a) => libRPGMaster.functionName(...a);

The Library function can then be accessed using the localFunctionName in the API as required and, should the Library function call change, the change can be made in just one place.

The rest of this Section describes the accessible functions, objects and methods.

Get Character Sheet Field Map and Global Data

The RPGMaster Library holds RPG-version-specific data which other APIs can access, and a map of the important fields on the Roll20 Character Sheet version supported. References to each of these data items can be acquired using the getRPGMap() function:

[fields,RPGMap] = getRPGMap()

This function does not take any parameters, but returns an array of two object references:

  • fields: A reference for the object mapping standard internal API field names to the definitions for those fields on the supported Character Sheet. Using this field map means the programming of the API does not need to change for each Character Sheet. Each field definition has the structure
    api_field_name: [char_sheet_field_name,property,<defaultValue>,<sheetWorkerFlag>]
    where property is current or max, an optional defaultValue can be provided which is used if the field is undefined when read, and the sheetWorkerFlag (optional) is true if the field is to be set with the Roll20 setWithSheetWorker() method or false if the Roll20 set() method is to be used (default false).
  • RPGMap: a reference to an object with handles to each of the global data items available in the Library. The contents of these data items are specific to the versions of the RPG and Character Sheet supported by the Library. The data is as in the table below:
dbNamesAn array of the database objects of the standard, RPGMaster provided databases, indexed by name.
fieldGroupsAn object defining the groups of fields held in repeating tables on the Character Sheet and named in the fields object
spellsPerLevelAn object specifying the number of spells that can be memorised at each level by each class of spellcaster
specMUAn array of strings naming the standard specialist wizard classes for this RPG version
ordMUAn array of strings naming the standard ordinary wizard classes for this RPG version
wisdomSpellsAn array holding the additional spell slots or points per level for high wisdom scores
raceToHitModsAn object of race toHit modifiers with various weapon types and super-types
rangedWeapModsThe standard range mods to the toHit roll for firing ranged weapons at Near, Point Blank, Short, Medium, Long and Far ranges for this RPG version
saveLevelsAn object mapping class levels to the baseSaves table saving throw entries
baseSavesAn object holding for each base class an array of base saving throws with improvement by level progression mapped by saveLevels
classSaveModsAn object of class modifiers to the base saving throws
raceSaveModsAn object of race modifiers to the base saving throws

Please contact the author if you wish more in-depth specifications for any of these data elements.


Manage Character Sheet Tables

Some data on Character Sheets is best represented in tables, made up of multiple rows of multiple fields. Some tables can also have multiple columns of rows, each column containing rows which in turn have multiple fields (in fact, each column is considered a table in itself). Having a structured set of functions to add to, find, read, update, and remove data in these tables is a useful function to have. the ChatSetAttr API from The Aaron provides an amount of such functionality, but the RPGMaster Library provides a full suite of management functions, based on the definition of a standard Table Object, with associated Methods. The mechanics of the Character Sheet table are then hidden from the author of the API, who can concentrate on other functionality.

The Library consists of the Table Object, and the Methods. The mechanics of the Table Object are hidden from the API (but can be exposed & used if you know what you are doing and understand the structure of Character Sheet tables fully). The important aspects to know are the functions to get the table object from the character sheet, and the methods to manipulate the table object.

Table Management Functions

tableObject = getTable(character,fieldGroupDef,<column>,<tableObject>,<caseSensitive>)

Gets a complete table object from a character sheet. Also discovers all the valid default values for the table fields from the fields object. Takes the following parameters:

  • character: the character sheet object for the character sheet from which to get the table
  • fieldGroupDef: an entry from the fieldGroups object (obtained in the RPGMap with getRPGMap() - see Section 3.1). One of fieldGroup.MELEE .DMG .RANGED .AMMO .WPROF .MI .MAGIC .SPELLS .POWERS .INHAND .QUIVER .STYLES .GEAR .STORED .DUSTS .SCROLLS .MONWEAP .ALTWIZ .ALTPRI
  • column: (optional) for tables that have multiple columns, this is the column number to obtain. Each column is recovered as a complete table in itself
  • tableObj: (optional) an existing table object that will be overwritten with the complete table obtained by this command
  • caseSensitive: (optional) a true/false flag which, if true, makes all matches with table and field names in the table case sensitive (default is false, i.e. not case sensitive)

tableObject = getTableField(character,tableObject,tableDef,attributeDef,<column>,<defaultVal>,<caseSensitive>)

Gets all rows for one field of a table. Adds that to the table object passed as a parameter. Faster than obtaining the full table with getTable(), but should only be used for finding and reading data and not for writing or adding new data and especially not adding rows with the .addTableRow() method. Takes the following parameters:

  • character: the character sheet object for the character sheet from which to get the table
  • tableObject: an existing table object to add the field to, or an empty object '{}' to create a new table object with just this one field
  • tableDef: the table definition from the fields object obtained with the getRPGMap() function (see Section 3.1). This will be the entry 'fields.xxx_table' that defines the character sheet repeating table name and the first row index for the table
  • attributeDef: the table field definition from the fields object obtained with the getRPGMap() function (see Section 3.1). E.g. The entry for fieldName will be 'fields.xxx_fieldName' that defines the character sheet table field name and property (current or max)
  • column: (optional) for tables that have multiple columns, this is the column number to obtain. Each column is recovered as a complete table in itself
  • defaultVal: (optional) the default value to be given to this field if a row is blanked, or created without a value specified for this field. If not provided, it itself is defaulted to the default value provided for the field in the fields object obtained with getRPGMap()
  • caseSensitive: (optional) a true/false flag which, if true, makes all matches with table and field names in the table case sensitive (default is false, i.e. not case sensitive)

defaultValues = initValues(fieldGroupDef)

Gets a new default values object for the table defined by the provided field group definition from the fieldGroup object from the RPGMap obtained with getRPGMap() (see Section 3.1). The default values are those set for the table fields in the fields object. The structure of the values object is values[field_name][field_property]. Takes the following parameter:

  • fieldGroupDef: an entry from the fieldGroups object (obtained in the RPGMap, see getRPGMap() in Section 3.1). One of fieldGroup.MELEE .DMG .RANGED .AMMO .WPROF .MI .MAGIC .SPELLS .POWERS .INHAND .QUIVER .STYLES .GEAR .STORED .DUSTS .SCROLLS .MONWEAP .ALTWIZ .ALTPRI

Table Object Methods

value = tableObject.tableLookup(attributeDef,row,<defaultValue>,<returnObj>)

Looks up the value stored in a specified field in the specified row of the table object. Can take an optional default value (which will override the default value for the field stored in the table object itself), and an optional returnObj parameter to determine what is returned (value or object). Takes the following parameters:

  • attributeDef: the table field definition from the fields object obtained with the getRPGMap() function (see Section 3.1). For field fieldName,This will be the entry 'fields.xxx_fieldName' that defines the character sheet table field name and property (current or max)
  • row: the row number of the row to get the field value from. If the row number is beyond the current end of the table, will return a default value or < undefined >, depending on the value of the defaultValue parameter
  • defaultValue: a value or true or false (absolute boolian values). Defaults to true. If the field requested does not exist or does not have a value: true (or not provided) returns the default value stored for that field in the table object; false returns < undefined >; any other value is returned instead of the default value stored for that field in the table object
  • returnObj: an attributeDef or true or false (absolute boolean values). Defaults to false. false (or not provided) returns the value or default value of the requested field; true returns the field object from the table instead of the value; an attributeDef specifies a different property to return, e.g. current or max (uses only the property field of the attributeDef)

tableObject = tableObject.tableSet(attributeDef,row,value,<caseSensitive>)

Sets the value of the specified table field in the specified row to be the value provided. tableObject is changed in-place. Takes the following parameters:

  • attributeDef: the table field definition from the fields object obtained with the getRPGMap() function (see Section 3.1). For field fieldName, this will be the entry 'fields.xxx_fieldName' that defines the character sheet table field name and property (current or max)
  • row: the row number of the row to set the field value in. If the row number is beyond the current end of the table, will create a new object for that field and the row specified: WARNING: creating a new field in a row this way can have unpredictable results. It is better to use the addTableRow() method to add complete new rows or to define all the fields in an existing row
  • value: the value to store in the specified field in the specified row of the table
  • caseSensitive (optional) a true/false flag which, if true, makes all matches with table and field names in the table case sensitive (default is false, i.e. not case sensitive)
tableObject = tableObject.addTableRow(row,<values>)

Either add a new row to a table object with the provided or default values, or replace a current row with the provided or default values. tableObject is changed in-place. Takes the following parameters:

  • row: the row number of the row to write the values to. If the row number is beyond the current end of the table, will create all the fields in a new row of the Table Object, either with the values provided, or the default values
  • values: a values object (optional), created using the initValues() table function, and modified as required with new values for the fields. If not provided, defaults to the default values for the table fields held by the Table Object itself (effectively blanking the row). See the description of the initValues() function for the structure of the values object
row = tableObject.tableFind(attributeDef,valToFind)

Find the first row in the Table Object with an entry in the field defined by the attributeDef with the value of valToFind. If found, row will be a valid table row number; otherwise the method returns < undefined >. Takes the following parameters:

  • attributeDef: the table field definition from the fields object obtained with the getRPGMap() function (see Section 3.1). For the field fieldName, this will be the entry 'fields.xxx_fieldName' that defines the character sheet table field name and property (current or max) to search
  • valToFind: the value to be searched for in the attributeDef field
  • row: the row number of the first row on which a match occurs, or < undefined > if no match was found

Attribute Management

Two functions that get and set attribute values on the character sheet:

value = attrLookup( character, attributeDef, <tableDef>, <row>, <column>, <caseSensitive>, <defaultValue> );

A function that can get the value of an attribute from a character sheet, either from a standard attribute, or from a repeating table. However: for table field values using the Table Management functions, objects and methods is preferred and may suffer from fewer issues in future. Takes the following parameters:

  • character: the character sheet object for the character sheet from which to get the value
  • attributeDef: the attribute field definition from the fields object obtained with the getRPGMap() function (see Section 3.1). For a field fieldName this will be the entry 'fields.fieldName' that defines the character sheet attribute field name and property (current or max)
  • tableDef: (optional) the table definition from the fields object obtained with the getRPGMap() function (see Section 3.1). This will be the entry 'fields.xxx_table' that defines the character sheet repeating table name and the first row index for the table
  • row: (optional) the row number of the row to get the field value from. If the row number is beyond the current end of the table, will return a default value or < undefined >, depending on the value of the defaultValue parameter
  • column: (optional) for tables that have multiple columns, this is the column number from which to obtain the field value.
  • caseSensitive (optional) a true/false flag which, if true, makes all matches with table and field names case sensitive (default is false, i.e. not case sensitive)
  • defaultValue: (optional) a value or true or false (absolute boolian values). Defaults to true. If the field requested does not exist or does not have a value: true (or not provided) returns the default value stored for that field in the fields object; false returns < undefined >; any other value is returned instead of the default value stored for that field in the fields object

attributeObj = setAttr( character, attributeDef, value, <tableDef>, <row>, <column>, <caseSensitive> );

A function that sets the value held by an attribute on a character sheet. Can also set values in repeating tables on the character sheet. However: for table attributes it is highly recommended that the Table Management functions, objects and methods (see Section 3.2) are used to get and set repeating table field values, as this might suffer from fewer issues in the future. Takes for following parameters:

  • character: the character sheet object for the character sheet on which to set the value
  • attributeDef: the attribute field definition from the fields object obtained with the getRPGMap() function (see Section 3.1). For field fieldName this will be the entry 'fields.fieldName' that defines the character sheet attribute field name and property (current or max). If the attribute object does not exist on the character sheet (and is not a table field) it will be created
  • value: the value to store in the specified attribute of the specified character sheet
  • tableDef: (optional) the table definition from the fields object obtained with the getRPGMap() function (see Section 3.1). This will be the entry 'fields.xxx_table' that defines the character sheet repeating table name and the first row index for the table
  • row: (optional) the row number of the row to set the field value in. If the row number is beyond the current end of the table, the function will attempt to create the new row, and put the value in it
  • column: (optional) for tables that have multiple columns, this is the column number in which to set the field value. If the column does not exist, the function will return < undefined >
  • caseSensitive (optional) a true/false flag which, if true, makes all matches with table and field names case sensitive (default is false, i.e. not case sensitive)
  • attributeObj: the function returns the attribute object found and in which the value has been set, or < undefined > if a table field or row does not exist

Database Management

The RPGMaster series of APIs use a number of databases holding data about spells, powers, magic items, character classes, attack macros, and other aspects. These are held as objects within the game-version and character sheet-version specific RPGMaster Library, and can be supplemented by GM provided additional databases held in Roll20 character sheets. See the database help handouts distributed with the RPGMaster APIs for more information on each type of database.

The RPGMaster Library provides a number of database management functions which can be used by APIs to manage the provided databases. These functions are described here.

DBindex = getDBindex( <forceUpdate> )

A function to build or get and return an index to all entries in the RPGMaster databases. This function must be called before any items in the databases are queried or acted upon with the other database management functions. Having this index (which is globally held in the system) speeds up database access considerably over relying on the Roll20 object management functions, and allows the APIs to seamlessly access items that might be in either internal object databases or held in external character sheet databases, and supports the prioritisation of user-defined database items over Library defined items. Takes one optional parameter:

  • forceUpdate: (optional) A boolean flag: if true, forces the global database index to be recreated from scratch. If false or not provided, only builds the index if it does not already exist (e.g. when the game session has just started and the APIs initialise)

dbItemObject = abilityLookup( rootDB, dbItemName, <character>, <silent>, <default> );

A function to get an entry from a database. Uses the global DBindex internally to access the correct database entry directly, eliminating the speed of a Roll20 object search. The building of the index using getDBindex() will determine the priority order of the potential sources for database items: see that function description for details. However, if the item does not have an entry in the DBindex (i.e. is not in any currently loaded database), and if a character sheet object is passed as a parameter, this abilityLookup() function will also search the character sheet for a copy of the database item which might have previously been placed there by a getAbility() function call. This allows characters to have items that come from user-defined databases in one campaign that are carried with them to other campaigns which perhaps don't have the same user-defined databases loaded.

Takes the following parameters:

  • rootDB: The root database name for the type of item being recovered. Will access indexes from any database name that starts with the rootDB name. Can be one of MU-Spells-DB, PR-Spells-DB, Powers-DB, MI-DB, Attacks-DB, Class-DB
  • dbItemName: The name of the item being searched for. The following characters are ignored: '-', '_', 'space'.
  • character: (optional) the character sheet object for the character sheet for which the item is relevant, and which might hold any orphaned item that is not available in current databases.
  • silent: (optional) a boolean value which, if true, will surpress any error message if the rootDB is invalid or the item cannot be found. False or not provided will result in error messages being returned.
  • default: (optional) a boolean value which, if false, returns < undefined > for any database item object if the item is not found or other errors occur, or if true or not defined returns a default item with the following structure:
    {name:'-',type:'',ct:'0',charge:'uncharged',cost:'0',body:'This is a blank slot. Go search out something new to fill it up!'}
  • dbItemObject A database item object, of class AbilityObj, with structure:
    	class AbilityObj {<br>
    		constructor( dBname, abilityObj, ctObj, source ) {<br>
    			this.dB = dBname;<br>
    			this.obj = abilityObj;<br>
    			this.ct = ctObj;<br>
    			this.source = source;<br>
    			this.api = (abilityObj && abilityObj[1]) ? (abilityObj[1].body.trim()[0] == '!') : false;<br>
    		}

dbItemObject = getAbility( rootDB, dbItemName, character, <silent> )

A special version of abilityLookup() that not only gets the requested database item from the databases, but also saves that item to the stated character sheet for later reference. All parameters are defined the same as those for AbilityLookup() above. The returned dbItemObject.dB object attribute always holds the name of the character sheet, so that after a call to getAbility(), the standard Roll20 syntax of `%{${dbItemObject.dB}|${dbItemName}}` will work to display the database item in the chat window.


itemObject = setAbility( character, itemName, itemBody, <actionBar> )

A function to set or update a database item or an ability macro in a character sheet (database items are stored as ability macros on a character sheet). Note: the API in-memory databases cannot be updated in this way. Only items and ability macros on character sheets can be created and updated. Takes the following parameters:

  • character: the character sheet object of the character sheet on which the item is to be stored or updated.
  • dbItemName: The name of the item being set. The case of the name and the following characters will be saved as part of the name, but are ignored for indexing and matching of the item name to those already stored on the character sheet: '-', '_', 'space'.
  • dbItemBody: The content to store as the data item, which will be stored as a character sheet Ability Macro body. Can consist of any text that can be stored in an Ability Macro body
  • actionBar: (optional) a boolean value which, if true, will set the "Show as Token Action" flag for the Ability Macro that represents the item. Default is false
  • itemObject: the returned item object which represents the item just set. Has the same definition as dbItemObject defined for the abilityObject() function

errFlag = buildCSdb( dbFullName, dbObj, typeList, <silent> )

A function to extract an API databse from memory into a Character Sheet Database representation, so that the GM can examine the standard items stored there. Note: the function does not re-index the databases, so the Character Sheet database representation so created will not actually be used to recover data from by the system. If use of the Character Sheet database is required, it will be necessary to run a getDBindex( true ) function to force an index update. Takes the following parameters:

  • dbFullName: the name of the database to be built, which should be one of the databases named in the dbNames object returned by the getRPGMap() function (see Section 3.1), but does not have to be
  • dbObj: the database object in dbNames that is to be extracted to the Character Sheet database named dbFullName
  • typeList: one of clTypeLists (for character classes), spTypeLists (for all types of spell or power), or miTypeLists (for all other items), which have been obtained using getRPGMap() (see Section 3.1)
  • silent: (optional) a boolean value which, if true, will surpress any error messages. False or not provided will result in error messages being sent to chat. An error flag is always returned
  • errFlag: a boolean value indicating if an error occurred.

checkCSdb( <dbName> );

A function to check any character sheet database for completeness and accuracy. If the body texts of the item Ability Macros have been set up in accordance with the relevant database documentation handout, this function will ensure that all other attributes, lists and fields are set up to match the database item Ability Macros. Takes the following parameter:

  • dbName (optional) the name of the character sheet database to check. If not provided, or dbName = '-db', all character sheet databases will be checked

Changelog

v1.3.00 (2022-09-21)

  • First release to GitHub.
  • Updated to delete old versions of standard character sheet databases.


v1.3.01 (2022-10-01)

  • Fix issue with database lookup if a character has a name that includes "spell" or "power" in their name.
  • Added support for direct access to MU & PR spells, and/or other Magic Items as powers for characters and magic items.


v1.3.02 (2022-10-10)

  • Fixed errors in the coding of spells that requite a To-Hit roll but do damage rather than targeted magic.
  • Changed initiative modifier char sheet field from comreact to custom field init-mod.
  • Added spell as weapon flag to spell tables.


v1.3.03 (2022-10-22)

  • Support for the Race Database.


v1.3.04 (2022-11-15)

  • Allow handleCheckSaves() to work in silent mode.
  • Added support for the Creatures database.


v1.4.01 (2022-11-28)

  • Support for the Fighting Styles database & creature setup.
  • Allowalphabetically indexed lists.
  • Support %{DB


v1.4.02 (2022-12-16)

  • More creature definitions, and supporting powers.
  • Add ability to specify weapons and armour for creatures with probability of different sets.
  • Also added ammo reuse type 2: becomes only possible ammo of several for that weapon e.g. spitting snake venom, and type 3: reduces in qty by 1, and all other ammo for same weapon increases qty b 1.


v1.4.03 (2023-01-16)

  • Added Attack messages (similar to damage messages) using Ranged weapons notes field.
  • Added ability for creature innate attacks to have damage roll before attack name so they work with CS buttons.
  • Fixed issue with abilityLookup() if ability name undefined.
  • Fixed issue with resolveData() if not defaulting values & ns: attribute not specified.


v1.4.04 (2022-01-16)

  • Added creature attkmsg & dmgmsg attributes to support messages to display with attack and damage rolls respectively.
  • Added table & function to return calculated base Thac0.
  • Made attrLookup() and getTokenValue() more robust vs. Character Sheet errors.
  • Added support in getTokenValue() for redefined default token bars.
  • Added support for Character Sheet conversion.
  • Gave Ammo its own lookup table capability.


v1.4.04 (2023-02-02)

  • Added code necessary to support new Rods, Staves & Wands, the new Magic item class, and charges expended on successful hit.
  • Fixed DB entries that incorrectly use parentheses.
  • Modified tableFind() to compare field values using dbName().
  • Decouple AttackMaster and MagicMaster config values from parseOutput().
  • Better error handling for several library functions.
  • Moved caster level parsing to the library.


v1.4.05 (2023-04-09)

  • Updated MI database and Magic Database Help to add ability for bags to automatically create item-holding character sheet, and optionally for it to auto-populate initial items in the bag.
  • Added "GM Info" as a possible line tag for RPGMspell & RPGMdefault Roll Templates, that is shown only if the GM is one of the recipients for the message.


v1.4.07 (2023-04-15) max attribute on character sheet.


v1.4.08 (2023-04-20)

  • Updated MI database items to compress using %{...


v1.5.01 (2023-05-17)

  • Fixed db reData parsing to only recover relevant text.
  • Fixed reDataCharge parsing to accept + as a valid character.
  • Fixed db Specs field parsing to only recover relevant data.
  • Added string trueCompare(txt) prototype.
  • Added the dispName() string prototype to replace hyphens with spaces in names to display.
  • Added improved handling of hidden magic items.
  • Added "Looks Like" special template tag which will auto-hide an item and display only what it looks like until revealed.
  • Default unknown magic item classes to be the same as "miscellaneous".
  • Allow character_ids to be substituted for token_ids in calls to getCharacter().
  • Added the ability to alphabetise lists.
  • Allow 'PW' to substitute 'POWER' in calls to caster() and related functions.