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

Manual Token Targeting

Hi, I've been scouring API docs but can't answer this question. Is there a way to manually define a token ID in a script? For instance, I want to create an FX macro that, when activated, will always use my character/token as the source of the FX. So instead of /fx beam-acid @{target|Source|token_id} @{target|Destination|token_id} I would want something like /fx beam-acid @{TOKEN NAME} @{target|Destination|token_id} Thanks!
1529509706
The Aaron
Pro
API Scripter
The API could do this in a roundabout way.  The pseudocode version would be: For character id,  find tokens representing character limit to tokens on the page where the calling player is spawn fx for each You'd then just need to pass the character id to an API script.
1529509892
The Aaron
Pro
API Scripter
Of course, you don't need the API, you could do: /fx beam-acid @{selected|token_id} @{target|Destination|token_id}
Thanks, I'll check that out. I really want to avoid having to select my token each time to do this if possible. One less click.
1529511354
The Aaron
Pro
API Scripter
Would look something like this completely untested script: on('ready',()=>{     const getPageForPlayer = (playerid) => {         let player = getObj('player',playerid);         if(playerIsGM(playerid)){             return player.get('lastpage');         }         let psp = Campaign().get('playerspecificpages');         if(psp[playerid]){             return psp[playerid];         }         return Campaign.get('playerpageid');     };     on('chat:message',(msg)=>{         if('api' !== msg.type ) {             return;         }         let args = msg.content.split(/\s+/);         const who = getObj('player',msg.playerid).get('_displayname');         switch(args.shift().toLowerCase()){             case '!cfx': {                     let character = getObj('character',args[1]);                     let destToken = getObj('graphic', args[2]);                     if(args[0] && character && destToken) {                         let pageid = getPageForPlayer(msg.playerid);                         let tokens = findObjs({                             represents: character.id,                             pageid: pageid                         });                         if(tokens){                             let destPt = {                                 x: destToken.get('left'),                                 y: destToken.get('top')                             };                             tokens.forEach((t)=>{                                 spawnFx(                                     {x:t.get('left'),y:t.get('top')},                                     destPt,                                     args[0],                                     pageid                                 );                             });                         } else {                             sendChat('cfx',`/w "${who}" no tokens for ${character.get('name')} on your current page.`);                         }                     } else {                         sendChat('cfx',`/w "${who}" use <code>!cfx [effect] [source character id] [destination token id]</code>.`);                     }                 }                 break;         }     }); }); Which you'd call something like: !cfx beam-acid @{Bob The Slayer|character_id} @{target|Destination|token_id} Could be interesting for having a bunch of traps all breath fire on one guy too. =D
Ultimately I've settled on just making my script a token ability, and using 'selected'. I think I just need to embrace the 'select token' mentality of activating abilities, instead of just clicking character sheet links like I'm used to.
Follow up question, is there a macro/API driven way to activating a clickable link on the character sheet? I know i could recreate the macro those links generate, but that seems like a duplication of efforts.
1529520689
The Aaron
Pro
API Scripter
Macro : yes, syntax is something like %{~CHARACTER_ID|ROLL_NAME} API : not really...  The API doesn't have the context necessary to expand macros/abilities correctly as @{target} and @{selected} don't really translate, and abilities can use a shorthand form for attribute references that omits the character.  You can do some translations (look at GroupInitiative, if you're curious), but it's not straight forward.