browser icon
You are using an insecure version of your web browser. Please update your browser!
Using an outdated browser makes your computer unsafe. For a safer, faster, more enjoyable user experience, please update your browser today or try a newer browser.

Creating a JSON Weapon Array in Maptool

Posted by on August 11, 2010

Currently working on a bit of the framework to list available weapons and stats in MapTool so they can be called, bit by bit, onto characters as needed.  This is one of the most annoying of the MT tasks I want to accomplish in the next couple of weeks, but should lay the groundwork for future improvements to help make combat faster and easier, as well as improving my understanding of MapTool, thus taking care of two glaring personal deficiencies at once.

I created a token called Lib:Weapons and gave it two properties (more will be added later):  WeaponList and SkillsMelee.  I am only adding melee weapons for now.  Additional macros will allow me to add a missile weapon, modify existing weapons in the list, add a shield, and add more attack types.  The basic create macro only creates one attack type, saved as a JSON object inside the weapon object, and represents a single attack mode, for instance a swing attack with a staff using Staff skill.

The WeaponList property I just manually edited to {}, which is an empty JSON object.  The SkillsMelee list is bracketed, and I just manually typed in a bunch of relevant melee skills:

[“Axe/Mace”, “Boxing”, “Brawling”, “Broadsword”, “DX”, “Flail”, “Force Sword”, “Garrote”, “Judo”, “Karate”, “Knife”, “Kusari”, “Lance”, “Main-Gauche”, “Monowire Whip”, “Polearm”, “Rapier”, “Saber”, “Shield”, “Shortsword”, “Smallsword”, “Spear”, “Staff”, “Two-Handed Axe/Mace”, “Two-Handed Flail”, “Two-Handed Sword”, “Whip”]

(Note that force swords and monowire whips are unlikely to appear in Cago and I will remove them from the list at some point.)

I stole took inspiration from a macro from a post about a 6E MapTool framework, debugged it a bunch, and modified it heavily.  There are a bunch of weapon properties in there that apply to advanced combat rules, and I am not using them right now, but may integrate them at a future date depending on how well my other macros turn out.  The code for Add_New_Melee_Weapon, run directly from Lib:Weapons, looks like this:

<!– Adding a new melee weapon to the library token. The property WeaponList on the token must be filled in to define an empty JSON object prior to running the first time. –>

[h: weaponList2 = getLibProperty(“WeaponList”, “Lib:Weapons”)]

<!– The property SkillsMelee on the library token must be defined as a JSON array containing all melee skill names to be used in the campaign. –>

[h: SkillList= json.toList(SkillsMelee)]

<!– Define the weapon’s basic parameters and the primary attack mode.  Additional modes to be added after weapon creation in a different macro. –>

[h: newWeapon =
“wName|No Weapon|Weapon Name|TEXT”,
“wDR||DR (for breakage)|TEXT”,
“wMaxHP||Maximum HP|TEXT”,

“wAttack1||Attack 1 Label|TEXT”,
“wSkill1|”+SkillList+”|Skill Used|LIST|SELECT=0 VALUE=STRING”,
“wDamBase1|none,thrust,swing,static|Damage Base 1|LIST|SELECT=0 VALUE=STRING”,
“wDamMod1|0|Damage Modifier 1 (0/+#/-#/dice expression)|TEXT”,
“wDamType1|crushing,cutting,impaling,pi-,pi,pi+,pi++|Damage Type 1|LIST|SELECT=0 VALUE=STRING”,
“wReach1|0,0-1,1,1-2,1-3,1-4,1-7,2,2-3,4|Reaches (C = 0)|LIST|SELECT=0 VALUE=STRING”,
“wGripChange1|0|Ready Maneuver to Change Grip?|CHECK”,
“wParry1|0,0U,0F,-1,-2U,+2|Parry|LIST|SELECT=0 VALUE=STRING”,
“wMinST1||Minimum Strength|TEXT”,
“wStuck1|0|Can get stuck?|CHECK”


<!– Create the new weapon JSON object and the attack1 sub-object to store to the master WeaponList array.  If the OK button is clicked without changing the No Weapon default, do not execute. –>

[r, if (wName != “No Weapon”), code:
[h: weaponStats = “{}”]
[h: attack1Stats = “{}”]

[h: weaponStats = json.set(weaponStats, “Name”, wName)]
[h: weaponStats = json.set(weaponStats, “Weight”, wWeight)]
[h: weaponStats = json.set(weaponStats, “DR”, wDR)]
[h: weaponStats = json.set(weaponStats, “MaxHP”, wMaxHP)]

[h: attack1Stats = json.set(attack1Stats, “Label”, wAttack1)]
[h: attack1Stats = json.set(attack1Stats, “Skill”, wSkill1)]
[h: attack1Stats = json.set(attack1Stats, “DamBase”, wDamBase1)]
[h: attack1Stats = json.set(attack1Stats, “DamMod”, wDamMod1)]
[h: attack1Stats = json.set(attack1Stats, “DamType”, wDamType1)]
[h: attack1Stats = json.set(attack1Stats, “Reach”, wReach1)]
[h: attack1Stats = json.set(attack1Stats, “GripChange”, wGripChange1)]
[h: attack1Stats = json.set(attack1Stats, “Parry”, wParry1)]
[h: attack1Stats = json.set(attack1Stats, “MinST”, wMinST1)]
[h: attack1Stats = json.set(attack1Stats, “Hand”, wHand1)]
[h: attack1Stats = json.set(attack1Stats, “Stuck”, wStuck1)]

[h: weaponStats = json.set(weaponStats, “Attack1”, attack1Stats)]

[h: weaponList2 = json.set(weaponList2, wName, weaponStats)]

[h: setLibProperty(“WeaponList”, weaponList2, “Lib:Weapons”)]

Weapon ‘[r: wName]’ added to WeaponList.
{ No weapon added. }]

The input prompt looks like this, and I entered values as shown:

Looking back at the WeaponList property on the token, I see I was partially successful:

{“Test Sword”:{“Name”:”Test Sword”, “Weight”:2, “DR”:6, “MaxHP”:12, “Attack1”:{“Label”:”Swing”, “Skill”:”Broadsword”, “DamBase”:”swing”, “DamMod”:2, “DamType”:”cutting”, “Reach”:1, “GripChange”:0, “Parry”:0, “MinST”:10, “Hand”:”RH”, “Stuck”:0}}}

The problem is that the DamMod property should be listed as +2, not 2, and the Reach property is also an integer.  DamMod is specifically a text field so that for a gun, you could enter “none” as the DamBase value and “2d6-1” as the mod expression, to represent static damage.  Also, Reach properties can be expressed as 1-7 for a whip, for instance.  Better test.

{“Test Sword”:{“Name”:”Test Sword”, “Weight”:2, “DR”:6, “MaxHP”:12, “Attack1”:{“Label”:”Swing”, “Skill”:”Broadsword”, “DamBase”:”swing”, “DamMod”:2, “DamType”:”cutting”, “Reach”:1, “GripChange”:0, “Parry”:0, “MinST”:10, “Hand”:”RH”, “Stuck”:0}}, “Test Weapon”:{“Name”:”Test Weapon”, “Weight”:0, “DR”:0, “MaxHP”:0, “Attack1”:{“Label”:”Fight”, “Skill”:”Whip”, “DamBase”:”none”, “DamMod”:”2d6-1″, “DamType”:”pi-“, “Reach”:”1-7″, “GripChange”:0, “Parry”:0, “MinST”:0, “Hand”:”RH”, “Stuck”:0}}}

What a relief.

Leave a Reply

Your email address will not be published. Required fields are marked *