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

addCustomTurn for Shield spell: get tracker position/index?

Hello all, first post on the forums. I'm using The Aaron's AddCustomTurn script, and I'd like to add it to a spell-casting macro to track spell duration, specifically for a 5e Shield spell. Shield can be cast on a Reaction (any time during a round). This means the party's wizard can cast from any position in the turn tracker. If it is his turn, he is at first position/top of tracker, and we use !act -1 1 --Shield --delete-on-zero the custom turn is added at position 0 and bumps the wizard down one in the tracker list. We click the tracker button twice to move the turn forward (once past the custom Shield spell, once past the wizard) for the next character's turn. Just before his next turn, the Shield spell will be removed from the tracker.  If it is NOT his turn, and he uses his Reaction to cast Shield, and he is somewhere down the tracker order, and we use that same code above, the custom turn is again added at position 0. But because I want the tracker to maximize the spell's duration for him (until the beginning of his next turn), I manually move the custom Shield item down 'in front' or 'above' his wizard.  However, now if we click forward, the --delete-on-zero will trigger too early, since I've moved the custom Shield item out of first position. In this latter instance, the issue can be circumvented by using !act -1 2 --Shield --delete-on-zero so that the spell lasts 2 tracker cycles. Then I guess we could implement a query macro, where he could select the 1 or 2 in a drop-down, depending on where he is in the tracker.  However I'm wondering if there is a way of using ACT's --index [x] option to 'tuck' the custom item just ahead of the wizard? I'm not sure how to obtain the positional number of an item in the tracker, something like @{tracker|MyWizard} only for index, not initiative number? Thanks for any insight.
I can't speak to automatically finding the index number of a specific token to add an effect before/after their turn, but if you want the default to add the spell effect to the end of the turn order, I changed line #356 to:          let idx = 9999; to make the default place at the end of the turn tracker.  You can still use the --index argument to place an item elsewhere (such as 0 to make it the first entry).
Right, that's a good thought, Jarren. Thanks for that. 
1651844505

Edited 1651845454
Update: I suppose I was misunderstanding how Shield worked: because it says 1 round duration, I was thinking it always lasted 1 round. But that duration is qualified by what it says in the description "Until the start of your next turn...". So it's whichever comes first. My bad.  Anyway, I still wanted the Shield turn tracker item to be inserted just before the wizard, instead of always at the top, so I used your idea Jarren, and inserted these lines to AddCustomTurn.js, v 0.1.1., at lines 364-367: case 'before': let position = getTurnArray().findIndex(o => o.id === parts[1]) idx = position > 0 ? position : 9999 break; which lets you write something like  !act -1 1 --Shield --delete-on-zero --before @{selected|token_id} and it then adds the turn marker before the caster if he is in any position but first, and at the very end of the turn order if he is first, so that it is removed at the right time.  Update 2: Actually, the script doesn't even need to put the item at the bottom of the list if the caster is in first position. The item can just be put inserted at the top. I was trying to account for something that isn't even an issue! Coding is hard. 
1651933438
The Aaron
Roll20 Production Team
API Scripter
Glad you got it worked out!  Let me know if you hit any more snags. 
The Aaron, your scripts are brilliant. Thanks so much.