Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Conditional Attack modifiers based on NPC type

October 04 (6 years ago)

Edited October 04 (6 years ago)

I'm copying my help request over from the macro forums now that I know my GM has access to API scripts. I'm leaving it intact for reference sake and have included a pseudocode layout of my end goal. I'm at a bit of a loss as to how to start with the scripting; I've looked at the wiki's for powercards and extended expressions but I guess I need to be even more basic than that.

/-/-/-/-/-/-/-/

I'm playing my first game on Roll20 tonight (5e) and I'm trying to streamline my experience as I'm picking up with a group that's been on it for years. As a novice, I'm not sure my goal is even possible. I've tried searching this forum, but get repeated gateway errors instead of results, so I apologize if this has been answered before.

My understanding is that I'll be able to select the enemy token and then run a global macro not assigned to my PC token.

I'd like to make an attack macro that checks creature type from token "npc type" attribute and adds additional dice and/or damage if it meets a criteria. Examples are ranger favored enemy or a sun blade that deals extra vs undead, or ideally a combination of the two. The specific weapon attributes means I have to split out the attacks between favored enemies.

As it stands I have 6 attack variants for a single weapon (basic, basic + planar warrior from horizon walker, basic vs undead, basic vs undead + pw, basic vs fiend, basic + PW vs fiend) so cutting that back down to 2 would be great. It would also reduce the likelihood of me forgetting to add a bonus, confusion with damage types, or just missclicking in general.

Assuming I can even set it up, I'll have to filter the attribute data to skip the first word, since it goes <size> <type>,<alignment>. Or perhaps request the DM create a new attribute that is just the type.

From what I've gathered I could do something similar with drop-down requests when I make the attack, but I don't want to have to toggle them each time I attack. Using the attribute is the crux. If that's the only way, I'll probably be back looking for help setting it up.

Any help is appreciated!

/-/-/-/-/-/-/-/

I'll apologize up front for the idea being more convoluted than necessary as a starting point, but it's exactly what my character is set up for.

Ref:

Sun Blade: 1d8 radiant (+1d8 radiant if target is undead)

Planar Warrior: convert all damage of the attack to force and +1d8 force

Favored Enemy: +4 damage to rolls against favored enemies (Undead & Fiends in this case)


Player has own token selected (or hardcoded for self)
Player chooses attack (currently from offense section of shaped character sheet, could be from macro on table top view)
*ie. Sun Blade or Sun Blade + Planar Warrior
Player chooses target token for the attack
Script pulls npc_type data from target token into a string
Script truncates string to parse out <type> only
*ie. will omit everything up to and including the first space as well as the comma and everything after
*"Large undead, chaotic evil"
Script checks if weapon conditional special case and character conditional special case **exist**
*i assume these would need to be custom created attributes on the character sheet
*ie. Sun Blade cares about Undead, and/or character cares about Undead & Fiends (from favored enemy)
*ie. Sun_Blade_type_conditional_trigger (value would be "undead") & Sun_Blade_type_conditional_effect (value would be "1d8") & Sun_Blade_type_conditional_effect_type (value would be "radiant")
*ie. Char_favored_enemy_type (multiple, in this case; would use OR for comparison; value would be "undead, fiends") & Char_favored_enemy_effect (value would be "4")
        *may need to go even more general if unable to check two attribute values in one attribute
        *ie. number_conditional_types (value would be 2) then char_conditional_1 (value = "undead") & char_conditional_2 (value = "fiend")
Script checks against weapon conditional special case and character conditional special case
*these would have to be chosen for comparison based on the attack chosen in step 2, presumably hard coded into the macro since various characters will have differently named conditionals and effects
*ie. character case would be checked for all attacks, weapon case would be specific to the attack selected
*ie. i wouldn't want a standard short sword attack to use the sun blade bonus, but i would want it to get the favored enemy bonus 
Script rolls attack dice (no changes here since all dependent effects in this example are bonus damage)
Script rolls appropriate dice and added damage per options above
*if chosen attack = Sun Blade & Target = undead: basic radiant damage roll (1d8) + added radiant bonus vs undead damage roll (1d8) + favored enemy damage (+4)
*if chosen attack = Sun Blade + PW & Target = undead: basic force (due to conversion from PW) damage roll (1d8) + added PW force damage roll (1d8) + added radiant bonus vs undead damage roll (1d8) (GM has adjudicated the bonus remains radiant) + favored enemy damage (+4)
October 04 (6 years ago)
GiGs
Pro
Sheet Author
API Scripter

It's possible, though it's a fairly complex script to develop for a single weapons attacks.

The first thing you need to check though is if your GM is going to have

  1. All enemies represented by a token, and each token is linked to a character sheet
  2. All npcs and monsters have an appropriate npc_type attribute in the correct format that your script can check.

Both of these things have to be true, or your macro won't work. So you'd best check with your GM that these facts will be true before you get too involved.

A much simpler approach would be to use a macro which launches and Ability Command Menu, which will print 4 compact buttons into chat: default attack, favoured enemy, undead, both, and then you click the button and it launches the appropriate attack/damage routine.


October 04 (6 years ago)

Thanks for the feedback. The token and attribute are consistent (at least for the one game I'm in now). Additionally, I found a simple "type" attribute that already exists, so no string parsing should be needed.

I realize I'm punching way above my weight class given my lack of familiarity with system and JavaScript, so please know my replies aren't intended as argumentative!

My vision for the script overall is to automate the inclusion of target-type-specific bonuses (or debuffs) for any attack (starting with weapon for "simplicity")

Currently, I have the map/chat on one screen and my charsheet on another, so creating the mutli pop up attack option would just move my selection from one screen to another, without really automating anything. If I'm missing the forest for the trees with that assessment please let me know.

After sleeping on it, ignoring the weapon entirely and just checking based on a rangers favored enemy type would be enough to get the ball rolling. The remaining aspects should be the same implementation repeated.

October 04 (6 years ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator

I'd recommend using roll queries for this rather than trying to code a complicated script solution. Where this will go will depend on what system/sheet you're using, but in basic macro syntax this would look like (example taken from my Pathfinder ranger with favored enemy):

1d20 + ?{Favored Enemy|No,0|Giant,6|Orc,2|Dragon,2|Undead,2}

The ?{...} part is what you will put somewhere in your sheet most likely.

October 04 (6 years ago)

Edited October 04 (6 years ago)

Roll queries will still force me to pick from the drop down each time I use the attack though, correct? If so, that's precisely what I'm trying to avoid. If that's not how they work, I may be chasing my tail and request a better explanation.

A few other folks have gotten me to the following point:

API option:

using the ExtendedExpressions script, I can grab the |type attribute and then use the logical expressions to decide what to do

Macro option:

by creating individual macros based on creature

#undead
/roll 1d8[base]+1d8[undead bonus from sword]+4[favored enemy bonus]
#fiend
/roll 1d8[base]+4[favored enemy bonus]

I can then make another macro for the weapon which uses the |type pull to call the appropriate macro from above

#weapon-atk
#@{target|type}


However, in both cases, this only functions when checking types that do not have a subtype, ie undead. If, for instance, the player has bonuses to all humanoids, the macro will fail since the default attribute (at least for the campaign i'm in) is some variation of "humanoid (goblinoid)".

Short of having my GM go through and edit each NPC sheet to include a new "type" attribute without the subtype, I have to find a way to parse the text string to remove everything but the base type. The split command would do it, but a) i have yet to learn how to put that as a usable script command in the game and b) it forces API again.

Avoiding b) is just a nice-to-have so I can post it back to the community for all to use. If it has to be API, whatever I set up will require pro as previously discussed.


October 04 (6 years ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator

ah, yeah, short of a custom script, there's not much you can do.