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

[Help] Of Madness and APIs

So I'm working on a system for battlefield encounters for a DnD-esque game to occur in the background and have been trying to set up a macro that I can fire off as an attack action. The calculation should (hypothetically) be: Roll [unitSize]d20 + toHit get the number that pass the enemy AC ([[@{selected|bar1}d20+@{ToHit}}>@{target|Target|AC}]]) Roll [hitCount]d[unit's damage die] + [unit's damage mod] and get the number of insta-kills ([[{@{Hits}d@{Damage_die}+@{Damage_mod}}>@{target|Target|bar3}]]) Then go to the targeted token and set its Count to [count] - [kills] Then modify the unit's hp by: -1*roundDown((1d[unit damage die] + [unit damage mod])*([hits]-[kills]/[newcount])) I went out of my way to get the API so I could try to save values by storing them to the character that is attacking, so I've got the following: // using the setattr and token-mod APIs !setattr --name Kislev Musketeer Cohort --hits|[[@{selected|bar1}d20+@{ToHit}}>[[@{target|Target|AC}]]]] !setattr  --name Kislev Musketeer Cohort --kills|[[{@{Hits}d@{Damage_die}+@{Damage_mod}}>[[@{target|Target|bar3}]]]] &{template:default} {{name=*Kislev Musketeers*}} {{Hits=@{Hits}}}{{Kills= @{Kills}}} !token-mod --set bar1_value|[[@{target|Target|bar1}]]-@{Kills} !token-mod --set bar3_value|[[@{target|Target|bar3}]] -[[floor[[[[1d@{Damage_die}+@{Damage_mod}]]*(@{Hits}-@{Kills})/[[@{target|Target|bar1}]]-@{Kills}]]]] Now I can guess that someone here has already noticed whatever the problem is, but I cannot, short of: it's broken. Every time I fire the macro and select a target it hangs up and refuses to select any  token I kindly ask it to select.  I have spent many dollars, hours, and am contemplating just signing a pact with the nearest devil just to figure out what's wrong. Anyone want to take a stab? PS. If someone knows of something that can do what I am obviously failing at doing, please link it. Thanks!
1620766534

Edited 1620766695
Kraynic
Pro
Sheet Author
I think I see a couple things.  I haven't tested this, so I will leave that bit to you! First, when using a generic call to pull an attribute from the sheet associated with a single token, it is just "@{selected|" or @{target|"  to do so.  Your second Target is only to be used if you are needing to pull from multiple targets in one macro so that you can designate Target1, Target2, etc.  With only a single target, you don't need that at all, so change the target macro calls all the way through to not use that second Target: @{target|AC} @{target|bar3} See how that goes. Edit: If this isn't all being run as a character sheet ability macro, you will probably need selected on the Hits, Damage_die, and Damage_mod attributes. 
1620768667
timmaugh
Forum Champion
API Scripter
Kraynic is absolutely right about this looking like you would run it from the character whose Hits, Damage_die, and Damage_mod you want to reference. To put a fine point on it... from the character sheet, the character is defaulted, so you can do something like: @{Hits} But from some other origin, you have to put a reference to the character in somehow. This can be the character name, character ID, token name, token ID, "target", or "selected": @{selected|Hits} (Running individual macros from every character seems inefficient and not what you're looking for, but I could be wrong.) One other point... when you use a target in a macro, the messages that come out of that macro don't contain the selected tokens. You can pull data off the selected token in your command line (stuff like @{selected|Damage_mod} will be rendered down to the data you want), but there is no array of selected tokens for the API script you are calling to work with. This matters for scripts that intend for you to have a selected token before you call them... like TokenMod. (I forget if ChatSetAttr expects a selected token or not...) TokenMod lets you get around it by specifying IDs to target with the --ids argument, but if you want players to be able to do that, you have to enable it in the help ( !token-mod --help scroll to the bottom). Another option is to use the SelectManager meta-script and virtually select the tokens you want to adjust right inline of your other macro call: {& select Kislev Musketeers}
1620778085
timmaugh
Forum Champion
API Scripter
Also, if you want to save values between commands, you can look at Muler , another meta-script. Set up your Mule (an ability on a character -- even one only intended for this purpose). Again, as a meta script this will work in your other calls... so if you wanted to save a roll total, for instance, you could load the Mule and then save to a variable. For a Mule named BattleProgress, that might look like: !token-mod --set someprop|[[2d10]] {&mule BattleProgress}set.LastUnitsKilled = $[[1]].value/set (Note that the .value construction comes from ZeroFrame, and extracts the value of a roll to the command line.) In another call, if you wanted to retrieve it, you would load the Mule, and use a get: !token-mod --set someOtherProp|get.LastUnitsKilld/get {&mule BattleProgress}