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

Initiative Macro with no Tokens

Is there a way to use a macro to add a dice roll with a label to the initiative tracker without having a token? Can this be done in API otherwise?
1565828593
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Check out this wiki page:  Adding a Custom Item
I have, unless I'm missing something, there's nothing there that suggests you can add to the tracker without a token, excluding manually clicking the add button, which is what I'm wanting to bypass.
1565832908
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Sorry, I thought for sure that link had info along those lines. It cannot be done via macro to my knowledge. It can be done via API, though I do recall seeing a bug report on that recently. You might be able to find something useful in this thread . I'll ask around.
That definitely looks like it's in the right direction. Just gotta try and find my java knowledge and see if I can interpret it. Cheers!
1565835444
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Just to save you from any wild googling, JavaScript, not Java. :) I have asked about. I'll let you know if I hear anything.
1565839411
The Aaron
Roll20 Production Team
API Scripter
Something like this?&nbsp; <a href="https://app.roll20.net/forum/post/3954148/slug%7D" rel="nofollow">https://app.roll20.net/forum/post/3954148/slug%7D</a>
1565839577
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
That's the bunny!
1565839777
The Aaron
Roll20 Production Team
API Scripter
I've got another one that will do it with images instead of custom turns.. don't remember why that was important...&nbsp;
Ah perfect, The Aaron is the Man.
however, that script doesn't seem to be working. Just crashings the API out when I try to send it a command. Figured I was doing something wrong but it does it with your examples as well.
1565841122
The Aaron
Roll20 Production Team
API Scripter
Hmm. &nbsp;What is the error?
Your scripts are currently disabled due to an error that was detected. Please make appropriate changes to your scripts and click the "Save Script" button and we'll attempt to start running them again.&nbsp; More info... For reference, the error message generated was:&nbsp; SyntaxError: Unexpected end of JSON input SyntaxError: Unexpected end of JSON input at JSON.parse (&lt;anonymous&gt;) at apiscript.js:43:29 at eval (eval at &lt;anonymous&gt; (/home/node/d20-api-server/api.js:151:1), &lt;anonymous&gt;:65:16) at Object.publish (eval at &lt;anonymous&gt; (/home/node/d20-api-server/api.js:151:1), &lt;anonymous&gt;:70:8) at /home/node/d20-api-server/api.js:1634:12 at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:560 at hc (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:39:147) at Kd (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:546) at Id.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:489) at Zd.Ld.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:94:425)
1565841594

Edited 1565841629
The Aaron
Roll20 Production Team
API Scripter
Oh! &nbsp;I know that bug. Manually add something to the turn order and then remove it, it will work forevermore after. I think I have that fixed in my latest version, but I'm laying in bed and can't seem to get to it from my phone. I'll update tomorrow with the fixed one for completeness' sake.&nbsp;
1565841723
The Aaron
Roll20 Production Team
API Scripter
Or you can change this line: let to=JSON.parse(Campaign().get('turnorder'))||[]; To this: let to=JSON.parse(Campaign().get('turnorder')||'[]'); And that will fix it.&nbsp;
Well, it's not crashing the API now, but nothing happens.&nbsp;!act --Counter and nada. Updated the line in the API, and also tried putting something in the turn tracker.
1565843073
The Aaron
Roll20 Production Team
API Scripter
Hmm. I'll have to debug it tomorrow. :(
1565844492
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Could it be related to this bug ? This was the half-remembered thing I alluded to earlier.
1565868434
The Aaron
Roll20 Production Team
API Scripter
RIGHT! &nbsp;is that still a thing?
1565869854

Edited 1565986746
The Aaron
Roll20 Production Team
API Scripter
Ok, try this version, with the command !actg : on('ready',function(){ "use strict"; const aictImgSrc = "<a href="https://s3.amazonaws.com/files.d20.io/images/58732795/pfn3AoNw630KlzHP0dGMWw/thumb.png?1532188342" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/58732795/pfn3AoNw630KlzHP0dGMWw/thumb.png?1532188342</a>"; const activeAICTs = findObjs({type:'graphic',layer:'object'}) .filter((t)=&gt;/images\/58732795\/pfn3AoNw630KlzHP0dGMWw\//.test(t.get('imgsrc'))) .filter((()=&gt;{ const toIds = JSON.parse(Campaign().get('turnorder')||'[]').map(to=&gt;to.id); return t =&gt; { if( ! toIds.includes(t.id)){ t.remove(); return false; } return true; }; })()) .map((t)=&gt;t.id) ; const getPageForPlayer = (playerid) =&gt; { 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'); }; let lastTurnCache = ''; const checkFormulaOnTurn = _.debounce(() =&gt; { let to=JSON.parse(Campaign().get('turnorder')||'[]'); if(to.length){ if(to[0].id!==lastTurnCache &amp;&amp; activeAICTs.includes(to[0].id)) { sendChat('',`[[${to[0].pr}+(${to[0].formula||0})]]`,(r)=&gt;{ to[0].pr=r[0].inlinerolls[0].results.total; Campaign().set('turnorder',JSON.stringify(to)); }); } lastTurnCache = to[0].id; } },10); on('chat:message',function(msg){ var args,cmds,who,initial,change,entry; if('api' === msg.type) { if(msg.content.match(/^!actg\b/) ){ who=(getObj('player',msg.playerid)||{get:()=&gt;'API'}).get('_displayname'); if(_.has(msg,'inlinerolls')){ msg.content = _.chain(msg.inlinerolls) .reduce(function(m,v,k){ var ti=_.reduce(v.results.rolls,function(m2,v2){ if(_.has(v2,'table')){ m2.push(_.reduce(v2.results,function(m3,v3){ m3.push(v3.tableItem.name); return m3; },[]).join(', ')); } return m2; },[]).join(', '); m['$[['+k+']]']= (ti.length &amp;&amp; ti) || v.results.total || 0; return m; },{}) .reduce(function(m,v,k){ return m.replace(k,v); },msg.content) .value(); } args = msg.content .replace(/&lt;br\/&gt;\n/g, ' ') .replace(/(\{\{(.*?)\}\})/g," $2 ") .split(/\s+--/); cmds = args.shift().split(/\s+/); change = parseFloat(cmds[1]); change = ( isNaN(change) ? '+1': change ); change = `${/^[+-]\d/.test(change)?'':'+'}${change}`; initial = parseFloat(cmds[2])||0; entry = args.join(' '); if(entry.length){ let to=JSON.parse(Campaign().get('turnorder')||'[]'); let pageid = getPageForPlayer(msg.playerid); let token = createObj('graphic', { subtype: 'token', imgsrc: aictImgSrc, pageid: pageid, layer: 'objects', top: -100, left: -100, width: 70, height: 70, name: entry, showname: true }); activeAICTs.push(token.id); to.unshift({ id: token.id, pr: initial, formula: change }); Campaign().set('turnorder',JSON.stringify(to)); if(!playerIsGM(msg.playerid)){ sendChat('ACT',`/w gm &lt;div style="padding:1px 3px;border: 1px solid #8B4513;background: #eeffee; color: #8B4513; font-size: 80%;"&gt;&lt;div style="background-color: #ffeeee;"&gt;&lt;b&gt;${who}&lt;/b&gt; added entry for &lt;b&gt;${entry}&lt;/b&gt; starting at &lt;b&gt;${initial}&lt;/b&gt; and changing by &lt;b&gt;${change}&lt;/b&gt;.&lt;/div&gt;&lt;/div&gt;`); } } else { sendChat('ACT',`/w "${who}" &lt;div style="padding:1px 3px;border: 1px solid #8B4513;background: #eeffee; color: #8B4513; font-size: 80%;"&gt;&lt;div style="background-color: #ffeeee;"&gt;Use &lt;b&gt;&lt;pre&gt;!aict [formula] [starting value] --[description]&lt;/pre&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;`); } } else if(msg.content.match(/^!eot/i)){ _.defer(checkFormulaOnTurn); } } }); }); Edit : Fix for cases where no auto increment or decrement should occur.
1565870117
The Aaron
Roll20 Production Team
API Scripter
You'll need to clear the turn order from the menu first.&nbsp;
Gave it a shot, bugs out with the below. Your scripts are currently disabled due to an error that was detected. Please make appropriate changes to your scripts and click the "Save Script" button and we'll attempt to start running them again.&nbsp; More info... For reference, the error message generated was:&nbsp; TypeError: Cannot read property 'id' of undefined TypeError: Cannot read property 'id' of undefined at apiscript.js:105:43 at eval (eval at &lt;anonymous&gt; (/home/node/d20-api-server/api.js:151:1), &lt;anonymous&gt;:65:16) at Object.publish (eval at &lt;anonymous&gt; (/home/node/d20-api-server/api.js:151:1), &lt;anonymous&gt;:70:8) at /home/node/d20-api-server/api.js:1634:12 at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:560 at hc (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:39:147) at Kd (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:546) at Id.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:489) at Zd.Ld.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:94:425) at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:111:400
1565906617
The Aaron
Roll20 Production Team
API Scripter
OK, run install this script: on('ready',()=&gt;{ Campaign().set('turnorder','[]'); }); It will reset your turn order.&nbsp; The issue is likely that something is hanging out in your turnorder from the custom turns which are broken right now.&nbsp; Once you've restarted and it's cleared the turn order, disable or delete it and everything should work fine.
1565907700
The Aaron
Roll20 Production Team
API Scripter
Also, grab the code from the message above (<a href="https://app.roll20.net/forum/permalink/7690286/" rel="nofollow">https://app.roll20.net/forum/permalink/7690286/</a>) again, I adjusted one thing about the display (make it show up for players)
No dice. Getting this error. Looks like the same as above, tried running the one to clear out the turn order a couple of times. Threw it into a different campaign and it works as expected though. Your scripts are currently disabled due to an error that was detected. Please make appropriate changes to your scripts and click the "Save Script" button and we'll attempt to start running them again.&nbsp; More info... For reference, the error message generated was:&nbsp; TypeError: Cannot read property 'id' of undefined TypeError: Cannot read property 'id' of undefined at apiscript.js:105:43 at eval (eval at &lt;anonymous&gt; (/home/node/d20-api-server/api.js:151:1), &lt;anonymous&gt;:65:16) at Object.publish (eval at &lt;anonymous&gt; (/home/node/d20-api-server/api.js:151:1), &lt;anonymous&gt;:70:8) at /home/node/d20-api-server/api.js:1634:12 at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:560 at hc (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:39:147) at Kd (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:546) at Id.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:489) at Zd.Ld.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:94:425) at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:111:400
Is there a way to get it to not increment?
1565913091
The Aaron
Roll20 Production Team
API Scripter
If you specify a 0 fit the increment amount: !actg 0 10 --something always at 10
1565913133
The Aaron
Roll20 Production Team
API Scripter
If you want to PM me an invite to the game where it isn't working and GM me I can fix it for you.&nbsp;
Hmm, even when I specify 0, it still increments. All good. The one it's not working in is my API test ground, so it's all good.
Dope
1565986474
The Aaron
Roll20 Production Team
API Scripter
keithcurtis said: Could it be related to this bug ? This was the half-remembered thing I alluded to earlier. Ok, that bug seems not to be a thing anymore, even though this seems to have similar symptoms.
1565986767
The Aaron
Roll20 Production Team
API Scripter
DylanC said: Hmm, even when I specify 0, it still increments. All good. The one it's not working in is my API test ground, so it's all good. Ah, nice catch.&nbsp; I tracked down the issue and fixed the code posted above.
Perfection!