Character Vault
Any Concept / Any System
Compendium
Your System Come To Life
Roll20 for Android
Streamlined for your Tablet
Roll20 for iPad
Streamlined for your Tablet

Personal tools

Difference between revisions of "Script:Store Commands"

From Roll20 Wiki

Jump to: navigation, search
m
(redirect to Script Index, API no longer available)
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
The following script creates the API commands <code>!delay</code>, <code>!store</code>, <code>!clearstore</code>, <code>!echostore</code>, and <code>!run</code>.
+
#Redirect[[API:Script Index]]
 +
<!-- Don't delete redirect, help center links to this page even though API have been removed
 +
[[Category:Discontinued API Scripts]] -->
  
==== Syntax ====
+
script overview
 +
|name=Store Commands
 +
|author={{user profile|235259|Brian}}
 +
|version=2.3
 +
|lastmodified=2016-03-09
 +
|dependencies={{api repository link|splitArgs}}
 +
|conflicts={{api repository link|Dynamic Lighting Animation}}
  
<blockquote style="border:1px #0088ee solid;background:#eee;padding:0.5em">!delay ''time''<br>
+
'''Store Commands''' creates the API commands <code>!delay</code>, <code>!store</code>, <code>!clearstore</code>, <code>!echostore</code>, and <code>!run</code>. Together, these commands allow a user to store a series of commands, and then run these commands in order, with a delay between them.
!store [-''time''] ''command''<br>
+
<br clear="all">
!clearstore<br>
+
!echostore<br>
+
!run</blockquote>
+
  
{| class="wikitable"
+
=== Syntax ===
|-
+
<!-- suppress category
! Parameter
+
{{syntaxbox top|Store Commands|formal=true}}
! Values
+
{{API command|delay}} {{API parameter|name=time}}<br>
|-
+
{{API command|store}} {{API parameter|name=</em>-<em>time|optional=true}} {{API parameter|name=command}}<br>
| time
+
{{API command|clearstore}}<br>
| A time delay in milliseconds. The <code>!delay</code> command will set the default delay for the <code>!store</code> command. A delay set using the <code>!store</code> command will override that default, but only for that command. Using <code>!delay</code> will not change the delays of already stored commands. 500ms will be used if no delay is ever specified.
+
{{API command|echostore}}<br>
|-
+
{{API command|run}}
| command
+
{{Formal API command|
| A command to store for later use. This can be anything you could normally enter in chat, as well as the [[API:Chat#Chat Functions|/direct]] command.
+
{{token|S}} {{rarr}} {{API command|delay}} {{integer|-}}
|}
+
{{token|S}} {{rarr}} {{API command|store}} -{{integer}} {{string|-}}
 +
{{token|S}} {{rarr}} {{API command|store}} {{string|-}}
 +
{{token|S}} {{rarr}} {{API command|clearstore}}<br>
 +
{{token|S}} {{rarr}} {{API command|echostore}}<br>
 +
{{token|S}} {{rarr}} {{API command|run}}
 +
}}
 +
{{syntaxbox bottom}}
  
 +
{{param description top}}
 +
{{param description|name=time|value=A time delay in milliseconds. The <code>!delay</code> command will set the default delay for the <code>!store</code> command. A delay set using the <code>!store</code> command will override that default, but only for that command. Using <code>!delay</code> will not change the delays of already stored commands. 500ms will be used if no delay is ever specified.}}
 +
{{param description|name=command|value=A command to store for later use. This can be anything you could normally enter in chat, as well as the [[API:Chat#Chat Functions|/direct]] command.}}
 +
{{param description bottom}}
 +
-->
 
==== Using the commands ====
 
==== Using the commands ====
  
Line 29: Line 45:
 
<code>!clearstore</code> will clear your current store of commands. <code>!echostore</code> will tell you exactly what you have stored at the moment, and what the delay values are.
 
<code>!clearstore</code> will clear your current store of commands. <code>!echostore</code> will tell you exactly what you have stored at the moment, and what the delay values are.
  
When you call <code>!run</code> all of the store commands will be used in order, with their delay between each one. Any messages to the chat will be sent as though you (the player) sent the message. The <code>!run</code> command does '''not''' clear your store, so you can run it again several times in a row.
+
When you call <code>!run</code>, all of the stored commands will be used in order, with their delay between each one. Any messages to the chat will be sent as though you (the player) sent the message. The <code>!run</code> command does '''not''' clear your store, so you can run it again several times in a row.
  
 
Stores are not maintained between sessions, and each player has his or her own store.
 
Stores are not maintained between sessions, and each player has his or her own store.
  
==== Code ====
+
=== Changelog ===
 
+
{{changelog version|2.3|2016-03-09|* Update for one-click install}}
<pre data-language="javascript">
+
{{changelog version|2.2|2015-01-24|* [bugfix] no-arg crash}}
var store_commands = store_commands || {};
+
{{changelog version|2.1|2015-01-22|* Fixed transcription error}}
 
+
{{changelog version|2.0|2015-01-08|* Release}}
store_commands.list = {};
+
 
+
on('chat:message', function(msg) {
+
    if(msg.type != 'api') return;
+
   
+
    var parts = msg.content.split(' ');
+
    var command = parts.shift().substring(1);
+
    var id = msg.playerid;
+
   
+
    if(!store_commands.list[id]) store_commands.list[id] = { cmds: [], delay: 500 };
+
   
+
    switch(command)
+
    {
+
        case 'delay':
+
            store_commands.list[id].delay = parseInt(parts[0], 10);
+
            break;
+
        case 'store':
+
            var delay = 500;
+
            if(parts[0].indexOf('-') == 0)
+
                delay = parseInt(parts.shift().substring(1), 10);
+
            else if(store_commands.list[id].delay)
+
                delay = store_commands.list[id].delay;
+
           
+
            var obj = { text: parts.join(' '), delay: delay };
+
            store_commands.list[id].cmds.push(obj);
+
            break;
+
        case 'clearstore':
+
            store_commands.list[id].cmds = [];
+
            break;
+
        case 'echostore':
+
            for(var i = 0; i < store_commands.list[id].cmds.length; i++)
+
            {
+
                var obj = store_commands.list[id].cmds[i];
+
                sendChat('Store Commands.js', '/w ' + msg.who + ' {' + obj.delay + 'ms, ' + obj.text + '}');
+
            }
+
            break;
+
        case 'run':
+
            var count = 0;
+
            for(var i = 0; i < store_commands.list[id].cmds.length; i++)
+
            {
+
                var obj = store_commands.list[id].cmds[i];
+
                store_commands.echo(id, obj.text, count + obj.delay);
+
                count += obj.delay;
+
            }
+
            break;
+
        default:
+
            break;
+
    }
+
});
+
 
+
store_commands.echo = function(id, text, delay)
+
{
+
    setTimeout(function(){ sendChat('player|'+id, text); }, delay);
+
};</pre>
+
 
+
[[Category:User API Scripts|Store Commands]]
+
[[Category:API Commands|Store Commands]]
+

Latest revision as of 19:56, 20 September 2021

  1. RedirectAPI:Script Index

script overview |name=Store Commands |author=Brian |version=2.3 |lastmodified=2016-03-09 |dependencies=splitArgs |conflicts=Dynamic Lighting Animation

Store Commands creates the API commands !delay, !store, !clearstore, !echostore, and !run. Together, these commands allow a user to store a series of commands, and then run these commands in order, with a delay between them.

[edit] Syntax

[edit] Using the commands

Use !delay to set a default delay between commands. Alternatively, the optional argument of !store can be used to set the delay for one command. If no delay is set, 500ms will be used.

Use !store to store commands to be executed later. Any command can be stored, from regular chat to whispers to API commands to the /direct command that is normally accessible only from the API.

!clearstore will clear your current store of commands. !echostore will tell you exactly what you have stored at the moment, and what the delay values are.

When you call !run, all of the stored commands will be used in order, with their delay between each one. Any messages to the chat will be sent as though you (the player) sent the message. The !run command does not clear your store, so you can run it again several times in a row.

Stores are not maintained between sessions, and each player has his or her own store.

[edit] Changelog

v2.3 (2016-03-09)

  • Update for one-click install


v2.2 (2015-01-24)

  • [bugfix] no-arg crash


v2.1 (2015-01-22)

  • Fixed transcription error


v2.0 (2015-01-08)

  • Release