
Edited July 3rd 2018
!delay version 0.8.3
New Syntax: !delay [seconds]|[loops (optional)] \\[speaker (optional)] --[command]
It works with the following chat commands:
- /desc
- /em
- /me
- /w
- /roll
- /gmroll
- normal chat support
- inline roll support
Here are some examples:
/desc
!delay 5 --/desc Bob waves hello.
Bob waves hello.
Chat
!delay 5 \\Joe --Hello
Joe: Hello
/em
!delay 5 \\Fred --/em smiles at you.
Fred smiles at you.
!delay 5 \\Bob --/me does a backflip.
Bob does a backflip.
/w
!delay 5 \\Kastion --/w gm Hello GM!
(From Kastion): Hello GM!
/roll
!delay 5 \\Norm --/roll 1d20
Norm: rolling 1d20
(9)
= 9
/gmroll
!delay 5 \\Kastion --/gmroll 1d20
Kastion: (To GM) rolling 1d20
(4)
= 4
Inline Roll Support
!delay 5 \\Kastion --/em swings his sword at Joe [[1d20]] and does [[1d8]] damage!
Kastion swings his sword at Joe rolling 17 for his attack roll and does 8 damage!
API COMMANDS:
You can call other API commands and delay them there is a catch however.
If the API command in question uses msg.playerid in it do the following to make it compatible with !delay
Search for the following in the function that handles chat:message:
if (msg.type !== "api") {
return;
}
And Directly Below it add the following:
if (!state.commandname_pid)
state.commandname_pid = "API";
if (msg.playerid !== "API")
state.commandname_pid = msg.playerid;
else
msg.playerid = state.commandname_pid;
Replace "commandname" with the command name in question or the script name.
Here is the updated version of the script that now supports looping and speaking as.
/*
Delay Function / Command by Kastion the Scriptomancer
Profile: https://app.roll20.net/users/3173313/kastion
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 && 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 (speaker.length > 0)
{
var token = findObjs({
_pageid: Campaign().get("playerpageid"),
_type: "graphic",
_name: speaker.trim()});
var char = "";
} else
var token = "";
if (token.length)
{
_.each(token, function(obj) {
var char = getObj("character", obj.get("represents"));
if (char)
sendChat("character|" + char.id, output.trim());
else
sendChat(speaker, output.trim());
});
} else
sendChat(speaker, output.trim());
}
}
on("chat:message", function(msg) {
if('api' !== msg.type ) {
return;
}
var cmdName = "!delay";
var msgTxt = msg.content;
if(msg.type == "api" && msgTxt.indexOf(cmdName) !== -1 && 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) && command)
var delay_length = seconds * 1000;
else
return;
setTimeout(delayFunction(speaking, command, pid), delay_length);
};
});
on('ready',function(){
log("-=> Delay command loaded (!delay) <=-");
});
Here is a video showing how powerful !delay can be if used with a number of different API commands.
The video uses the following commands:
- !tl
- !token-mod
- !cfx
- !sfx
- !kaboom
- !screenshake
- !ping (New function I wrote)
- !fade (New function I wrote)
This is the list of commands executed in the above video.
!tl lock
!fade out BRNA
!sfx song:Ambush2 action:loop 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 4 --!token-mod --flip showplayers_bar3 showplayers_name --set currentside|+1 --ids -LAHFPyR5lMGsj1q6aGW
!delay 4 --!cfx bomb-death -LAHSx-pBVRZKudBuf2V -LAHFPyR5lMGsj1q6aGW
!delay 4 --!sfx song:Vanish1 action:play unique:true volume:100
!delay 4 --!sfx song:Zombie1 action:play unique:true volume:100
!delay 7 --!token-mod --flip showplayers_bar3 showplayers_name --set currentside|+1 --ids -LAHFKhaAZKcpNW9Nw9e
!delay 7 --!cfx bomb-death -LAHRkQglUu1JD9kNdRG -LAHFKhaAZKcpNW9Nw9e
!delay 7 --!sfx song:Vanish2 action:play unique:true volume:100
!delay 7 --!sfx song:Zombie2 action:play unique:true volume:100
!delay 10 --!token-mod --flip showplayers_bar3 showplayers_name --set currentside|+1 --ids -LAHFG1-GkNjk1eFGi_0
!delay 10 --!cfx bomb-death -LAHSVmIwKMEibXooDvN -LAHFG1-GkNjk1eFGi_0
!delay 10 --!sfx song:Vanish3 action:play unique:true volume:100
!delay 10 --!sfx song:Zombie3 action:play unique:true volume:100
!delay 13 --!ping -LAH7fK7jLnwsObDJ8nU
!delay 15 --!sfx song:Bones1 action:play unique:true volume:100
!delay 15 --!token-mod --flip showplayers_bar3 showplayers_name --set currentside|+1 --ids -LAH7fK7jLnwsObDJ8nU
!delay 15 --!cfx bomb-death -LAHV3MLf9NdxllNQApk -LAH7fK7jLnwsObDJ8nU
!delay 15 --!sfx song:Vanish action:play unique:true volume:100
!delay 18 --!token-mod --flip showplayers_bar3 showplayers_name --set currentside|+1 --ids -LAH7z0KO7TSATVX4yLr
!delay 18 --!cfx bomb-death -LAHV3YTBg-W4pX3n3MS -LAH7z0KO7TSATVX4yLr
!delay 18 --!sfx song:Vanish1 action:play unique:true volume:100
!delay 18 --!sfx song:Zombie1 action:play unique:true volume:100
!delay 21 --!token-mod --flip showplayers_bar3 showplayers_name --set currentside|+1 --ids -LAH7myPOl_0xVcmp6hc
!delay 21 --!cfx bomb-death -LAHU-34OSIywtnxQdY4 -LAH7myPOl_0xVcmp6hc
!delay 21 --!sfx song:Vanish2 action:play unique:true volume:100
!delay 21 --!sfx song:Zombie2 action:play unique:true volume:100
!delay 24 --!token-mod --flip showplayers_bar3 showplayers_name --set currentside|+1 --ids -LAH7wlmchqgXQqd2FXD
!delay 24 --!cfx bomb-death -LAHV32TtE1ECrAJuUQp -LAH7wlmchqgXQqd2FXD
!delay 24 --!sfx song:Vanish3 action:play unique:true volume:100
!delay 24 --!sfx song:Zombie3 action:play unique:true volume:100
!delay 24 --!sfx song:Mephit1 action:play unique:true volume:100
!delay 27 --!ping -LAHZyCjzLsE1-hs4mqz
!delay 32 --!ping -LAHXttRTQHOMFAD_9ic
!delay 32 --!sfx song:Bones2 action:play unique:true volume:100
!delay 36 --!cfx nova-death -LAHWGF4voPddycMLbje -LAHXttRTQHOMFAD_9ic
!delay 36 --!sfx song:Ogre1 action:play unique:true volume:100
!delay 36 --!token-mod --flip showplayers_bar3 showplayers_name --set currentside|+1 --ids -LAHXttRTQHOMFAD_9ic -LAH7tRDx4vG3rCcWi1X -LAH7IoNq4T19BxG1pIp -LAH7ASZLpua7udsz2UQ -LAH71GtfZ8ukdXc6Kc5 -LAH76mYFjH6vsCkN2_H -LAH7E4rnJAJ4KEo8li8 -LAH7IoNq4T19BxG1pIp
!delay 38 --!kaboom 20 50 scatter --death --ids -LAHXttRTQHOMFAD_9ic
!delay 38 --!ScreenShake 6
!delay 42 --!ping -LB9djHBooIt4U1BCLm0
!delay 42 --!tl unlock
If you have any issues with the script or any feature suggestions please don't hesitate to reply to this thread.