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

[Script] Turn Tracker: Automatically add Custom Item w/ Round Calculations?

Is there an easy way to automatically enter a Custom Item into the Turn tracker, give it a Round Calculation, and have it appear at the top of the Turn Tracker? Example:  As a test, I want to start all combats w/ a Round tracker entry at the top of the list in the Turn Tracker and have it auto-increment by 1 each time its turn comes up.  I can manually do this, but is there a way to automate it? My googling has led me to believe the answer is no.  But I figure there's a chance I missed something. Thanks!
1462638378
Silvyre
Forum Champion
There exist a few API Scripts that can add such an item to the Turn Tracker using chat commands, such as TurnMarker1 .
I saw that script, but I was hoping for something more generic. Because I'd like to be able to create a macro that automatically adds a Custom Item called Bless w/ an initial value of 10 that reduces by 1 each time its turn comes up. Sorry for the confusion.  My example was pretty specific.
1462641639

Edited 1573172627
The Aaron
Pro
API Scripter
See if this fits the bill... !act <change: default +1> <initial value: default 0> --<what to call it> examples: !act -1 10 --Count down from ten !act +3 --Count up from 0 by threes !act --counter starts at 0 and goes up by 1 !act -1 [[3d8]] --Something that lasts 3d8 rounds !act -[[1d2]] 10 --something that might go twice as fast... Code: on('ready',() => { const checkFormulaOnTurn = () => { let to=JSON.parse(Campaign().get('turnorder')||'[]'); if(to.length && to[0].id==='-1'){ sendChat('',`[[${to[0].pr}+(${to[0].formula||0})]]`,(r)=>{ to[0].pr=r[0].inlinerolls[0].results.total; Campaign().set('turnorder',JSON.stringify(to)); }); } }; on('chat:message',(msg) => { if('api' === msg.type) { if(msg.content.match(/^!act\b/) ){ let who=(getObj('player',msg.playerid)||{get:()=>'API'}).get('_displayname'); if(_.has(msg,'inlinerolls')){ msg.content = _.chain(msg.inlinerolls) .reduce((m,v,k) => { let ti=_.reduce(v.results.rolls,(m2,v2) => { if(_.has(v2,'table')){ m2.push(_.reduce(v2.results,(m3,v3) => { m3.push(v3.tableItem.name); return m3; },[]).join(', ')); } return m2; },[]).join(', '); m['$[['+k+']]']= (ti.length && ti) || v.results.total || 0; return m; },{}) .reduce((m,v,k) => { return m.replace(k,v); },msg.content) .value(); } let args = msg.content .replace(/<br\/>\n/g, ' ') .replace(/(\{\{(.*?)\}\})/g," $2 ") .split(/\s+--/); let cmds=args.shift().split(/\s+/); let change=parseFloat(cmds[1]); change = Number.isNaN(change) ? '+1' : change; change = `${/^[+-]\d/.test(change)?'':'+'}${change}`; let initial = parseFloat(cmds[2])||0; let entry = args.join(' '); if(entry.length){ let to=JSON.parse(Campaign().get('turnorder')||'[]'); to.unshift({ id: "-1", pr: initial, custom: entry, formula: change }); Campaign().set('turnorder',JSON.stringify(to)); if(!playerIsGM(msg.playerid)){ sendChat('ACT',`/w gm <div style="padding:1px 3px;border: 1px solid #8B4513;background: #eeffee; color: #8B4513; font-size: 80%;"><div style="background-color: #ffeeee;"><b>${who}</b> added entry for <b>${entry}</b> starting at <b>${initial}</b> and changing by <b>${change}</b>.</div></div>`); } } else { sendChat('ACT',`/w "${who}" <div style="padding:1px 3px;border: 1px solid #8B4513;background: #eeffee; color: #8B4513; font-size: 80%;"><div style="background-color: #ffeeee;">Use <b><pre>!act [formula] [starting value] --[description]</pre></b></div></div>`); } } else if(msg.content.match(/^!eot/i)){ _.defer(checkFormulaOnTurn); } } }); }); Edit (2019/11/07): Fixed using an increment of 0 to add a static turn with an unchanging value.
That's perfect, Aaron! Thanks yet again!
1462643157
The Aaron
Pro
API Scripter
No problem. =D
There is also the script by Krackerjacker as well for a fancier version :)
Saevar L. "Liquid-Sonic" said: There is also the script by Krackerjacker as well for a fancier version :) Do you mean the TrackerJacker script by Ken L.?  I looked for KrackerJacker, but was unable to find anyone or anything by that name.
1462675307
The Aaron
Pro
API Scripter
Yeah, that's what he means. =D
More brilliance, Aaron! Full-featured scripts that do many things are wonderful, but there are times you want a singular dedicated function like this one. I have added a macro button to make it easier for me to use (and to remember the syntax): !act ?{Increment?|1} ?{Start?|1} --?{Name?|Round} Many thanks for this!
1462693590
The Aaron
Pro
API Scripter
:). Happy to help!
Three of Swords said: Saevar L. "Liquid-Sonic" said: There is also the script by Krackerjacker as well for a fancier version :) Do you mean the TrackerJacker script by Ken L.?  I looked for KrackerJacker, but was unable to find anyone or anything by that name. Man sorry, I was sleepy when I wrote this clearly.
Man sorry, I was sleepy when I wrote this clearly. NP.  I just wanted to make sure I wasn't missing something.  I've done similar things in the past.  :)