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:Flight"

From Roll20 Wiki

Jump to: navigation, search
(new)
 
m
 
(14 intermediate revisions by one user not shown)
Line 1: Line 1:
The following two scripts both create the API command <code>!fly</code>. The first script is functionally limited to the values 1-9, while the second script is not. However, the second script makes use of an API feature which may or may not be intentional, meaning that it might be broken by an update to Roll20 in the future.
+
{{script overview
 +
|name=Flight
 +
|author={{user profile|235259|Brian}}, [[The Aaron]]
 +
|version=3.4
 +
|lastmodified=2016-08-15
 +
|dependencies={{api repository link|splitArgs}}}}
  
==== Syntax ====
+
'''Flight''' creates the API command <code>!fly</code>, which sets statusmarkers on the selected tokens to represent how high they are flying.
<blockquote style="border:1px #0088ee solid;background:#eee;padding:0.5em">!fly [''height'']</blockquote>
+
<br clear="all">
  
{| class="wikitable"
+
=== Syntax ===
|-
+
{{syntaxbox top|formal=true|Flight}}
! Parameter
+
{{API command|fly}} {{API parameter|name=height|optional=true}}
! Values
+
{{Formal API command|
|-
+
{{token|S}} {{rarr}} {{API command|fly}} {{token|height|-}}
| ''height''
+
{{token|height}} {{rarr}} {{epsilon}}
| Optional. Set the height of the selected token(s). If this parameter is 0, negative, or omitted, the flight value will be removed from the token(s).
+
{{token|height}} {{rarr}} {{integer}}
|}
+
}}
 +
{{syntaxbox end}}
  
==== Code: Version 1 ====
+
{{param description top}}
<pre data-language="javascript">
+
{{param description|name=height|value=Optional. Set the height of the selected token(s). If this parameter is 0, negative, or omitted, the flight value will be removed from the token(s).}}
on('chat:message', function(msg) {
+
{{param description bottom}}
    if(msg.type != 'api') return;
+
    var parts = msg.content.toLowerCase().split(' ');
+
    var command = parts.shift().substring(1);
+
    var selected = msg.selected;
+
    if(command != 'fly' || !selected) return; // use the !fly command, and have one or more things selected
+
    var height = +parts[0];
+
    if(!height) height = 0; // if no height is returned, treat as 0
+
    _.each(selected, function(obj) {
+
        if(obj._type != 'graphic') return; // only fly graphics
+
        var tok = getObj('graphic', obj._id);
+
        if(tok.get('subtype') != 'token') return; // don't try to fly cards
+
        tok.set('status_fluffy-wing', false);
+
        if(height > 0) tok.set('status_fluffy-wing', ''+height);
+
    });
+
});
+
</pre>
+
 
+
==== Code: Version 2 ====
+
<pre data-language="javascript">
+
on('chat:message', function(msg) {
+
    if(msg.type != 'api') return;
+
    var parts = msg.content.toLowerCase().split(' ');
+
    var command = parts.shift().substring(1);
+
    var selected = msg.selected;
+
    if(command != 'fly' || !selected) return; // use the !fly command, and have one or more things selected
+
    var height = +parts[0];
+
    if(!height) height = 0; // if no height is returned, treat as 0
+
    _.each(selected, function(obj) {
+
        if(obj._type != 'graphic') return; // only fly graphics
+
        var tok = getObj('graphic', obj._id);
+
        if(tok.get('subtype') != 'token') return; // don't try to fly cards
+
        tok.set('status_fluffy-wing', false);
+
        var wings = '';
+
        while(height > 0)
+
        {
+
            // get current digit, starting from ones
+
            var digit = height / 10;
+
            digit -= Math.floor(digit);
+
            digit = Math.round(digit * 10);
+
            // shift height
+
            height = Math.floor(height / 10);
+
            wings += 'fluffy-wing@'+digit+',';
+
        }
+
        if(wings.length > 0) wings = wings.substring(0, wings.length - 1); // trim trailing comma
+
        var markers = tok.get('statusmarkers');
+
        if(markers != '') markers += ',';
+
        markers += wings;
+
        tok.set('statusmarkers', markers);
+
    });
+
});
+
</pre>
+
  
 
=== Notes ===
 
=== Notes ===
In the second version of the script, numbers with multiple digits will create multiple wing statusmarkers, one for each digit. Zero digits (for example, the tens digit of "205") will show up as a wing statusmarker with no number.
+
Numbers with multiple digits will create multiple wing statusmarkers, one for each digit. Zero digits (for example, the tens digit of "205") will show up as a wing statusmarker with no number.
  
 
[[File:Flight_Example.jpg]]
 
[[File:Flight_Example.jpg]]
 +
 +
=== Changelog ===
 +
{{changelog version|3.4|2016-08-15|* Restructured code to make adding commands (for imported scripts) easier for a non-coder.}}
 +
{{changelog version|3.3|2016-03-09|* Update for one-click install}}
 +
{{changelog version|3.2|2015-01-24|* [bugfix] no-arg crash}}
 +
{{changelog version|3.1|2015-01-22|* Fixed transcription error}}
 +
{{changelog version|3.0|2015-01-08|* Release}}

Latest revision as of 20:57, 20 September 2021

API ScriptAuthor: Brian, The Aaron
Version: 3.4
Last Modified: 2016-08-15
Code: Flight
Dependencies: splitArgs
Conflicts: None

Flight creates the API command !fly, which sets statusmarkers on the selected tokens to represent how high they are flying.

[edit] Syntax

!fly [height]
Formally:

S

→ !fly height


height

→ ε

height

integer
Parameter Values
height Optional. Set the height of the selected token(s). If this parameter is 0, negative, or omitted, the flight value will be removed from the token(s).

[edit] Notes

Numbers with multiple digits will create multiple wing statusmarkers, one for each digit. Zero digits (for example, the tens digit of "205") will show up as a wing statusmarker with no number.

Flight Example.jpg

[edit] Changelog

v3.4 (2016-08-15)

  • Restructured code to make adding commands (for imported scripts) easier for a non-coder.


v3.3 (2016-03-09)

  • Update for one-click install


v3.2 (2015-01-24)

  • [bugfix] no-arg crash


v3.1 (2015-01-22)

  • Fixed transcription error


v3.0 (2015-01-08)

  • Release