Background

Some spells, like Spiritual Weapon and Scorching Ray, can result in multiple attack and damage rolls. However, the basic &{template:atkdmg} (and others) expends a spell slot for each attack. I've been working on a macro that will expend a spell slot only on the first attack roll.

!script {{
--#sourcetoken|@(selected.token_id) {& select @{character_name}} 
--#reentrant|[*S:character_id]SpiritualWeapon
--#whisper|self
--#hideTitleCard|1
--?@\(@(selected.character_name)'s Spiritual Weapon|bar1[none]) -eq none|>Spawn;"[*S:character_name]'s Spiritual Weapon"
--:Attack|
--#hideCard|1
-->AttackRoll|[*S:character_id]

--X|
--:Spawn|TokenName
--iSpiritual Weapon is normally a 2nd Level Spell;What level spell slot are you using?|q;Slot;Cast at What Level?|Level 2,2|Level 3,3|Level 4, 4|Level 5,5|Level 6,6|Level 7,7|Level 8,8|Level 9,9
--?[*S:lvl[&Slot]_slots_expended] -lt 1|[--+Out of level [&Slot] slots!| --X| --]|

--=Slot|[&Slot] / 2 {FLOOR} 
--@forselected|{^& select [*S:character_name]}Spawn _name|[%1%] _offset|1,1 _bar1|[&Slot] _order|back

--^Attack|

--:AttackRoll|char id
--Rfind|[%1%];Spiritual Weapon;repeating_attack;atkname

--&Template|{^&template:atkdmg}
-->AddTemplateParameters|mod=+[*[%1%]:spell_attack_bonus]
-->AddTemplateParameters|rname=Spiritual Weapon
-->BuildRoll|r1;1d20cs>20 + [*[%1%]:wisdom_mod][WIS] + [*[%1%]:pb][PROF]
-->AddTemplateParameters|r1=[&r1]
-->AddTemplateParameters|always=1
-->BuildRoll|r2;1d20cs>20 + [*[%1%]:wisdom_mod][WIS] + [*[%1%]:pb][PROF]
-->AddTemplateParameters|r2=[&r2]
-->AddTemplateParameters|attack=1
-->AddTemplateParameters|range=60 feet
-->AddTemplateParameters|damage=1
-->AddTemplateParameters|dmg1flag=1
-->BuildRoll|dmg1;d8 + [*[%1%]:wisdom_mod][WIS]
-->AddTemplateParameters|dmg1=[&dmg1]
-->AddTemplateParameters|dmg1type=Force
-->BuildRoll|crit1;d8[CRIT]
-->AddTemplateParameters|crit1=[&crit1]
--=HLDice|[&Slot] - 2
-->BuildRoll|hldmg;(.49*[$HLDice])d8
-->AddTemplateParameters|hldmg=[&hldmg]
-->BuildRoll|hldmgcrit;(.49*[$HLDice])d8[CRIT]
-->AddTemplateParameters|hldmgcrit=[&hldmgcrit]
-->AddTemplateParameters|{^& if @\(@(selected.character_name)'s Spiritual Weapon|bar1[none]) = none}spelllevel=[&Slot]{^& end}
--/&Template|+ammo=1
--/>AddTemplateParameters|charname=@{character_name}
-->AddTemplateParameters|desc=[Show Spell Description](`https://app.roll20.net/editor/~[%1%]%7C[*R>spelldesc_link])

--@as|[*[%1%]:character_name] [&Template] {{charname=@{character_name}@(Macros|Braces.max)
--X|

--:AddTemplateParameters|parameter=value

--~Trim|string;trim;@(Macros|Braces.max)
--#debug|1
--&Template|+@(Macros|Braces)[%1%]
--&Template|+[&Trim]
--#debug|0
--<|

--:BuildRoll|roll name;roll content
--&[%1%]|[
--&[%1%]|+[
--&[%1%]|+[%2%]
--&[%1%]|+]
--&[%1%]|+]
--<|

}}

APIs Required:

ScriptCards

ZeroFrame

APILogic

Fetch

SelectManager

Emas

SpawnDefaultToken

5th Edition OGL by Roll20 Companion

Status

What this Spiritual Weapon macro does is check to see if there is a token on the VTT for the Spiritual Weapon, Spawn one if there is not, and then make an attack, expending a spell slot only on the first run of the macro (i.e., when the token is Spawned).

From the Roll Templates wiki

&{template:atkdmg} {{mod=mod}} {{rname=rname}} {{r1=r1}} {{always=1}} {{r2=r2}} {{attack=1}} {{range=range}} {{damage=1}} {{dmg1flag=1}} {{dmg1=dmg1}} {{dmg1type=dmg1type}} {{dmg2flag=1}} {{dmg2=dmg2}} {{dmg2type=dmg2type}} {{crit1=crit1}} {{crit2=crit2}} {{save=1}} {{saveattr=saveattr}} {{savedesc=savedesc}} {{savedc=savedc}} {{desc=desc}} {{hldmg=hldmg}} {{spelllevel=spelllevel}} ammo=ammo {{charname=charname}}

These are the available parameters for the template. I've married them into the above macro.

Caveats

  • In order for the level field to properly expend the correct spell slot, the charname must resolve to match the exact name of a character sheet. (See spell slot tracking.)

Problem

Unfortunately, this part doesn't work. Compare:

Using the baked in Roll20 OGL ScriptUsing my above macro
19
 
 
11
60 feet
Spiritual Weapon (+9)
Thodin
5Force
SPELL SLOT LEVEL 22 OF 3 REMAINING
10
 
 
13
60 feet
Spiritual Weapon (+9 )
Thodin
5Force

You can also observe that the "Show Spell Description" link a) doesn't function and b) appears in the wrong place. I've examined the link which is generated by the baked-in 5e OGL API, and I'm confident that I have the correct structure for the link address itself, but clicking the link does nothing and it isn't in the right place.

The Question

What are the template parameters (i.e., {{parameter name=parameter content}}--like with {{charname=character name}}) that correctly identify the spell slot expenditure and create a functional link in the right place?