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

Is there a game state or heartbeat object that is accessible through the API?

1529982821
Victor B.
Pro
Sheet Author
API Scripter
Shouldn't.  Once your in token-mod it rules.  This just delays a few seconds before invoking it.  
1529983037
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Thanks, I think we leapfrogged each other. I was responding to Kastion's post about changing lines in Token-mod.
1529983258
Victor B.
Pro
Sheet Author
API Scripter
In looking at some of the roll20AM commands, I'd definitely do comma separated commands rather than --.  Parsing by -- will cause problems.   So !delay,5,!roll20AM,audio,play|<whatever> and parse the command by ! everything before is for delay, everything after is neatly setup for target api.  
1530009238

Edited 1530009281
MyRoll20Stuffs
API Scripter
keithcurtis said: Thanks, I think we leapfrogged each other. I was responding to Kastion's post about changing lines in Token-mod. First get the most recent copy of !delay from this thread. Then go to line 2332 of token-mod in the handleInput function right below this:             if (msg.type !== "api") {                 return;             } Add the following:                 if (!state.tokenmod_pid)                     state.tokenmod_pid = "API";                                  if (msg.playerid !== "API")                     state.tokenmod_pid = msg.playerid;                 else                     msg.playerid = state.tokenmod_pid; This will make !delay work with !token-mod
1530010100

Edited 1530067961
MyRoll20Stuffs
API Scripter
Here is an example of what you can do with !delay <a href="https://www.youtube.com/watch?v=0PFj0yY-5_A" rel="nofollow">https://www.youtube.com/watch?v=0PFj0yY-5_A</a> In the video I use !delay with the following commands: !token-mod !cfx !sfx !kaboom !ping (New function I wrote) I have yet to test it with any other commands so far but if they use msg.playerid I'll likely have to add a few lines of code to it like I did with !token-mod
Now compatible with inline rolls. Thoroughly tested but if you have any issues with this let me know: /* Delay Function / Command by Kastion the Scriptomancer Profile: <a href="https://app.roll20.net/users/3173313/kastion" rel="nofollow">https://app.roll20.net/users/3173313/kastion</a> Syntax: !delay [seconds] \\ [speaker] -- [command] */ function processInlinerolls(msg) { if(_.has(msg,'inlinerolls')){ return _.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(); } else { return msg.content; } } function delayFunction(speaker, output, pid) { return function() { if (output.indexOf("!") !== -1) sendChat("player|" + pid.trim(), output.trim()); else sendChat(speaker.trim(), output.trim()); } } on("chat:message", function(msg) { if('api' !== msg.type ) { return; } var cmdName = "!delay"; var msgTxt = msg.content; if(msg.type == "api" &amp;&amp; msgTxt.indexOf(cmdName) !== -1 &amp;&amp; playerIsGM(msg.playerid)) { var inline_rolls = processInlinerolls(msg); var seconds = msg.content.split(' ')[1]; var speaking = msg.content.split('\\')[1]; var command = inline_rolls.substring(inline_rolls.indexOf('--')+2); var pid = msg.playerid; if (speaking) speaking = speaking.split('--')[0]; else speaking = ""; if (!isNaN(seconds) &amp;&amp; command) var delay_length = seconds * 1000; else return; setTimeout(delayFunction(speaking, command, pid), delay_length); }; }); on('ready',function(){ log("-=&gt; Delay command loaded (!delay) &lt;=-"); }); To make certain scripts that use msg.playerid in them work with !delay, generally search for the following (Using token-mod as an example): if (msg.type !== "api") { return; } Add this right below the above code: if (!state.tokenmod_pid) state.tokenmod_pid = "API"; if (msg.playerid !== "API") state.tokenmod_pid = msg.playerid; else msg.playerid = state.tokenmod_pid; If you have any issues with the script let me know.
1530050110
vÍnce
Pro
Sheet Author
Kastion said: Now compatible with inline rolls. Thoroughly tested but if you have any issues with this let me know: If you have any issues with the script let me know. TL;DR What does this script do exactly, Kastion?
Vince said: TL;DR What does this script do exactly, Kastion? It can delay most chat commands and be worked with to delay api scripts to any length of time to wait before executing. Watch this video: <a href="https://www.youtube.com/embed/0PFj0yY-5_A?end=41&amp;autoplay=1" rel="nofollow">https://www.youtube.com/embed/0PFj0yY-5_A?end=41&amp;autoplay=1</a> Which does the following (the video does ALMOST exactly this, the below macro is the most up to date): !fade BRNA !sfx song:Ambush2 action:play unique:true volume:100 !sfx song:Bones1 action:play unique:true volume:100 !ping -LAHF5tOCLTscmYyPkEX !delay 1 --!token-mod --flip showplayers_bar3 showplayers_name --set currentside|+1 --ids -LAHF5tOCLTscmYyPkEX !delay 1 --!cfx bomb-death -LAHTP5U47IaVZdebP4m -LAHF5tOCLTscmYyPkEX !delay 1 --!sfx song:Vanish action:play unique:true volume:100 !delay 3 --!token-mod --flip showplayers_bar3 showplayers_name --set currentside|+1 --ids -LAHFPyR5lMGsj1q6aGW !delay 3 --!cfx bomb-death -LAHSx-pBVRZKudBuf2V -LAHFPyR5lMGsj1q6aGW !delay 3 --!sfx song:Vanish1 action:play unique:true volume:100 !delay 3 --!sfx song:Zombie1 action:play unique:true volume:100 !delay 6 --!token-mod --flip showplayers_bar3 showplayers_name --set currentside|+1 --ids -LAHFKhaAZKcpNW9Nw9e !delay 6 --!cfx bomb-death -LAHRkQglUu1JD9kNdRG -LAHFKhaAZKcpNW9Nw9e !delay 6 --!sfx song:Vanish2 action:play unique:true volume:100 !delay 6 --!sfx song:Zombie2 action:play unique:true volume:100 !delay 9 --!token-mod --flip showplayers_bar3 showplayers_name --set currentside|+1 --ids -LAHFG1-GkNjk1eFGi_0 !delay 9 --!cfx bomb-death -LAHSVmIwKMEibXooDvN -LAHFG1-GkNjk1eFGi_0 !delay 9 --!sfx song:Vanish3 action:play unique:true volume:100 !delay 9 --!sfx song:Zombie3 action:play unique:true volume:100 !delay 12 --!ping -LAH7fK7jLnwsObDJ8nU !delay 12 --!sfx song:Bones1 action:play unique:true volume:100 !delay 12 --!token-mod --flip showplayers_bar3 showplayers_name --set currentside|+1 --ids -LAH7fK7jLnwsObDJ8nU !delay 12 --!cfx bomb-death -LAHV3MLf9NdxllNQApk -LAH7fK7jLnwsObDJ8nU !delay 12 --!sfx song:Vanish action:play unique:true volume:100 !delay 15 --!token-mod --flip showplayers_bar3 showplayers_name --set currentside|+1 --ids -LAH7z0KO7TSATVX4yLr !delay 15 --!cfx bomb-death -LAHV3YTBg-W4pX3n3MS -LAH7z0KO7TSATVX4yLr !delay 15 --!sfx song:Vanish1 action:play unique:true volume:100 !delay 15 --!sfx song:Zombie1 action:play unique:true volume:100 !delay 18 --!token-mod --flip showplayers_bar3 showplayers_name --set currentside|+1 --ids -LAH7myPOl_0xVcmp6hc !delay 18 --!cfx bomb-death -LAHU-34OSIywtnxQdY4 -LAH7myPOl_0xVcmp6hc !delay 18 --!sfx song:Vanish2 action:play unique:true volume:100 !delay 18 --!sfx song:Zombie2 action:play unique:true volume:100 !delay 21 --!token-mod --flip showplayers_bar3 showplayers_name --set currentside|+1 --ids -LAH7wlmchqgXQqd2FXD !delay 21 --!cfx bomb-death -LAHV32TtE1ECrAJuUQp -LAH7wlmchqgXQqd2FXD !delay 21 --!sfx song:Vanish3 action:play unique:true volume:100 !delay 21 --!sfx song:Zombie3 action:play unique:true volume:100 !delay 23 --!sfx song:Mephit1 action:play unique:true volume:100 !delay 24 --!ping -LAHZyCjzLsE1-hs4mqz !delay 27 --!ping -LAHXttRTQHOMFAD_9ic !delay 27 --!sfx song:Bones2 action:play unique:true volume:100 !delay 28 --!cfx nova-death -LAHWGF4voPddycMLbje -LAHXttRTQHOMFAD_9ic !delay 28 --!token-mod --flip showplayers_bar3 showplayers_name --set currentside|+1 --ids -LAHXttRTQHOMFAD_9ic -LAH7tRDx4vG3rCcWi1X -LAH7IoNq4T19BxG1pIp -LAH7ASZLpua7udsz2UQ -LAH71GtfZ8ukdXc6Kc5 -LAH76mYFjH6vsCkN2_H -LAH7E4rnJAJ4KEo8li8 -LAH7IoNq4T19BxG1pIp !delay 31 --!sfx song:Ogre1 action:play unique:true volume:100 !delay 32 --!kaboom 20 50 scatter --death --ids -LAHXttRTQHOMFAD_9ic !delay 36 --!ping -LB9djHBooIt4U1BCLm0
1530074897
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
What script gives you the !ping command? That's pretty neat.
keithcurtis said: What script gives you the !ping command? That's pretty neat. I wrote it myself. Feel free to use it. Here it is: /* Custom Ping Function / Command by Kastion the Scriptomancer Profile: <a href="https://app.roll20.net/users/3173313/kastion" rel="nofollow">https://app.roll20.net/users/3173313/kastion</a> Syntax: !ping [token_id] */ on('ready',()=&gt;{ on('chat:message',(msg)=&gt;{ if('api' !== msg.type ) { return; } if (!state.ping_pid) state.ping_pid = "API"; if (msg.playerid !== "API") state.ping_pid = msg.playerid; else msg.playerid = state.ping_pid; var cmdName = "!ping"; var msgTxt = msg.content; if (msg.type == "api" &amp;&amp; msgTxt.indexOf(cmdName) !== -1 &amp;&amp; playerIsGM(msg.playerid)) { let args = msg.content.split(/\s+/); switch(args.shift().toLowerCase()){ case '!ping': { var t = findObjs({ _pageid: Campaign().get("playerpageid"), _type: "graphic", _id: args[0] }); _.each(t, function(obj) { sendPing(obj.get("left"), obj.get("top"), Campaign().get('playerpageid'), msg.playerid, true); }); } break; } } }); log("-=&gt; Ping command loaded (!ping) &lt;=-") });
1530103135
The Aaron
Pro
API Scripter
You may wish to replace your use of sendPing with this function: &nbsp; &nbsp; const fixedSendPing = (function(){ &nbsp; &nbsp; &nbsp; &nbsp; var last={}; &nbsp; &nbsp; &nbsp; &nbsp; return function(left,top,pageid,playerid,pull){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if( last.left&nbsp; &nbsp;=== left&nbsp; &nbsp;&amp;&amp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; last.top&nbsp; &nbsp; === top&nbsp; &nbsp; &amp;&amp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; last.pageid === pageid ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendPing(-100,-100,pageid,null,false); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendPing(left,top,pageid,playerid,pull); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; last.left=left; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; last.top=top; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; last.pageid=pageid; &nbsp; &nbsp; &nbsp; &nbsp; }; &nbsp; &nbsp; }()); sendPing() will not ping the same place twice without an intervening ping to another location.&nbsp; This function fixes that by detecting a repeat and issuing a ping to another location.
The Aaron said: sendPing() will not ping the same place twice without an intervening ping to another location.&nbsp; This function fixes that by detecting a repeat and issuing a ping to another location. I can't replicate what you're talking about at all. I select a token, run "!ping @{selected|token_id}", scroll down, run ping, scroll down, run ping and I can ping the same token over and over. Check this to see what I'm talking about
1530107656
The Aaron
Pro
API Scripter
I see the pulling, but not the pinging.
1530108854
vÍnce
Pro
Sheet Author
Kastion, you've been writing some nice scripts.&nbsp; I would suggest making a separate API thread for each once you get some downtime.&nbsp; Even if you don't plan to develop and/or support them further...&nbsp; This would help us plebs to better find and share your scripts.&nbsp; Thanks for sharing your work btw.&nbsp; Cheers
1530112187

Edited 1530112603
MyRoll20Stuffs
API Scripter
The Aaron said: I see the pulling, but not the pinging. I wasn't aware there was supposed to be a colored circle expanding like when you manually ping a location. "sendPing" has NEVER under ANY circumstances done that for me. I'm not really sure what I'm missing but there has never been a "ping" just a "pull. Vince said: Kastion, you've been writing some nice scripts.&nbsp; I would suggest making a separate API thread for each once you get some downtime.&nbsp; Even if you don't plan to develop and/or support them further...&nbsp; This would help us plebs to better find and share your scripts.&nbsp; Thanks for sharing your work btw.&nbsp; Cheers Thanks. Yeah I'll make some separate threads for them later on today. EDIT: I've been passing my (the GM) msg.playerid to the sendPing function and have seen no "pings" just the "pulls". When I set the optional playerid field in the function to null a yellow ping started to appear. Apparently if the GM is the player it doesn't show the expanding circle. Not sure if players see the GM's "ping" I'll have to log in with a test player account and try it out. On the same note though I prefer it without the expanding colored circle and just a pull.