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

[Request] Script to link playing a card, with a character sheet button

I really don't know how possible this request is likely to be with how playing cards actually work and what the API can call but it would be really neat if we could perhaps monitor the name of the card played to make it roll from the character sheet as it plays. My use case is that my player's spellbooks are getting increasingly big and clunky to manage in the Pathfinder sheet as they level and gain more spells so I am moving to card decks as a way of managing which spells they have memorised each day. As they cast it they play the card so it is easy to tell at a glance what they have left to work with. The problem is that if the spell has a roll component they still tend to go to the macro from the sheet to handle the rolls/get the full spell description. I would love if the act of putting the magic missile card on the table also rolls the magic missile macro to show damage etc. Possible or pipe dream?
1424119889
The Aaron
Pro
API Scripter
Possibly, but a bit tedious. You would need to add a handler for on('create:graphic',...) to watch for the creation of the card (graphic with subtype 'card' and a card_id). However, to know who played the card, you'd need to watch for a change on player's hands: on('change:hand',...) Next you'd need to lookup the card, find the name, check the player for the name as a macro... Then the harder part starts... You'd need to write something to parse the macro into commands that you can execute. You can't just send it to chat to execute because @{target|} and @{selected|} won't be evaluated. Bare references like @{name} will also fail because they aren't in the context of a character. For selected, you'd have to assume they would have their token selected, find a token on the current page for that character and do the substitution manually either with the value or with an inline roll syntax in the case of a formula attribute. For bare references, you can sub in the character's name for the front. For @{target}, you're kind of out of luck. You could probably work something out where by they could pre-target or post-target critters and then run the macro contents when you have what you need. Tedious. And that assumes they only have one character. Hands are specific to players, not characters, so you'd really need to do all the above for all characters controlled by the player, or assume the one whose turn it is currently in the Turn Order is the one doing it. I have a few ideas about how you could make that easier on the player, but they would be quite daunting on the programmer...
Bugger. I had a feeling it would be pretty hard with the current way cards work but thought it worth asking. Thanks Aaron
1424121213
The Aaron
Pro
API Scripter
yup. I'll add that on the end of my scripts to write list.... (that puts it at about 97...) =D
1424171318
Ziechael
Forum Champion
Sheet Author
API Scripter
The Aaron said: yup. I'll add that on the end of my scripts to write list.... (that puts it at about 97...) =D Less than a hundred... i'd best get requesting things then, got to keep you sharp! On a related note, I like this idea and would certainly steal use a script that could produce the desired effect. Nice thinking Zepth!
How hard would it be to simply send the name of the card to chat? If we made the name in the format of an API button then the player simply plays the card, and presses the api button with their token selected to roll the command. If we combine it with the script you were helping with to send %{button} commands through the API it could work.
1424226285
The Aaron
Pro
API Scripter
Very doable, something like this might work (untested, and technically, API buttons execute API commands, so this is a hack to try and get around that limitation...)... on('ready',function(){ "use strict"; on('create:graphic',function(obj){ var card; if('card' === obj.get('subtype')){ card = getObj('card',obj.get('cardid')); if(card) { sendChat( 'Card Action', '<a href="!!\n%{selected|'+card.get('name')+'}">'+card.get('name')+'</a>' ); } } }); });