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:Marking Conditions"

From Roll20 Wiki

Jump to: navigation, search
(updated to use @target/@selected instead of poorly-implemented descriptors, and added means to remove singular markers)
m
 
(10 intermediate revisions by one user not shown)
Line 1: Line 1:
The following script creates the API commands <code>!mark</code>, <code>!unmark</code>, and <code>!clearmark</code>
+
{{revdate}}
 +
{{main|API:Script Index}}
  
==== Syntax ====
 
<blockquote style="border:1px #0088ee solid;background:#eee;padding:0.5em">!mark ''tokenid'' [''status'' [''type'']]<br>
 
!unmark ''tokenid'' [''status'' [''type'']]<br>
 
!clearmark ''tokenid''</blockquote>
 
  
{| class="wikitable"
+
{{script overview
|-
+
|name=Marking Conditions
! Parameter
+
|author={{user profile|235259|Brian}}
! Values
+
|dependencies={{api repository link|splitArgs}}
|-
+
|version=3.3
| ''tokenid''
+
|lastmodified=2015-03-26}}
| The ID of the token to mark. Use <code><nowiki>@{target|token_id}</nowiki></code> or <code><nowiki>@{selected|token_id}</nowiki></code> to get this value.
+
'''Marking Conditions''' creates the API commands <code>!mark</code>, <code>!unmark</code>, and <code>!clearmark</code>
|-
+
<br clear="all">
| ''status''
+
 
| (Optional) A D&D 4e status (except for dying, helpless, unconscious, insubstantial, or surprised) or the name of a [[API:Objects#Graphic (Token/Map/Card/Etc.)|statusmarker icon]]. The script has several aliases for the statuses. For example, immobilized, immobile, and immob all correspond to the same marker.
+
=== Syntax ===
 +
{{syntaxbox top|formal=true|Marking Conditions}}
 +
{{API command|mark}} {{API parameter|name=tokenid}} {{API parameter|name=status</em> {{API parameter|name=type|optional=true}}<em>|optional=true}}<br>
 +
{{API command|unmark}} {{API parameter|name=tokenid}} {{API parameter|optional=true|name=status</em> {{API parameter|optional=true|name=type}}<em>}}<br>
 +
{{API command|clearmark}} {{API parameter|name=tokenid}}
 +
{{Formal API command|
 +
{{token|S}} {{rarr}} {{API command|mark}} {{token|tokenid}} {{token|status|-}}
 +
{{token|S}} {{rarr}} {{API command|unmark}} {{token|tokenid}} {{token|status|-}}
 +
{{token|S}} {{rarr}} {{API command|clearmark}} {{token|tokenid|-}}
 +
{{token|tokenid}} {{rarr}} {{string|-}}
 +
{{token|status}} {{rarr}} {{epsilon}}
 +
{{token|status}} {{rarr}} {{string}}{{token|damage|-}}
 +
{{token|damage}} {{rarr}} {{epsilon}}
 +
{{token|damage}} {{rarr}} acid<br>
 +
{{token|damage}} {{rarr}} cold<br>
 +
{{token|damage}} {{rarr}} fire<br>
 +
{{token|damage}} {{rarr}} force<br>
 +
{{token|damage}} {{rarr}} lightning<br>
 +
{{token|damage}} {{rarr}} necrotic<br>
 +
{{token|damage}} {{rarr}} poison<br>
 +
{{token|damage}} {{rarr}} psychic<br>
 +
{{token|damage}} {{rarr}} radiant<br>
 +
{{token|damage}} {{rarr}} thunder
 +
}}
 +
{{syntaxbox end}}
 +
 
 +
{{param description top}}
 +
{{param description|name=tokenid|value=ID of a token object. This can be obtained with <code>@{target{{!}}token_id}</code> or <code>@{selected{{!}}token_id}</code>.}}
 +
{{param description|name=status|value=Optional. Either the name of a [[API:Objects#Graphic (Token/Map/Card/Etc.)|statusmarker icon]], or else one of many aliases to D&D 4e conditions.
  
If ''status'' is not specified, the purple statusmarker will be used.
+
 
|-
+
If ''status'' is not specified, the purple statusmarker will be used.}}
| ''type''
+
{{param description|name=type|value=Optional. A D&D 4e damage type. Only used if ''status'' is "ongoing", "damage", or "dam". If supplied, should be one of:
| (Optional) A D&D 4e damage type. Only used if ''status'' is ''ongoing'', ''damage'', or ''dam''. One of:
+
 
* acid
 
* acid
 
* cold
 
* cold
Line 31: Line 55:
 
* radiant
 
* radiant
 
* thunder
 
* thunder
If ''type'' is not specified, a statusmarker to represent untyped damage will be used.
+
If ''type'' is not specified, a statusmarker to represent untyped damage will be used.}}
|}
+
{{param description bottom}}
  
 
The <code>!mark</code> command will set a marker, while the <code>!unmark</code> command will clear it. <code>!clearmark</code> will clear all markers from the token.
 
The <code>!mark</code> command will set a marker, while the <code>!unmark</code> command will clear it. <code>!clearmark</code> will clear all markers from the token.
  
==== Code ====
+
==== Conditions and Aliases ====
<pre data-language="javascript">
+
The available ''status'' aliases and the D&D 4e conditions they map to are listed below.
on('chat:message', function(msg) {
+
    if(msg.type != 'api') return;
+
   
+
    var args = msg.content.split(' ');
+
    var command = args.shift().toLowerCase().substring(1);
+
   
+
    if (!(command == 'mark' || command == 'clearmark' || command == 'unmark')) return;
+
    if (args.length == 0) {
+
        sendChat('ERROR', '/w ' + msg.who + ' Please supply a token target with @{target|token_id}');
+
        return;
+
    }
+
   
+
    var mark = 'purple'; // default to defender's "mark" condition
+
    if(args[1]) {
+
        args[1] = args[1].toLowerCase();
+
        switch(args[1])
+
        {
+
            case 'blinded':
+
            case 'blind':
+
                mark = 'bleeding-eye';
+
                break;
+
            case 'dazed':
+
            case 'daze':
+
                mark = 'pummeled';
+
                break;
+
            case 'deafened':
+
            case 'deaf':
+
                mark = 'screaming';
+
                break;
+
            case 'dominated':
+
            case 'dominate':
+
                mark = 'chained-heart';
+
                break;
+
            case 'immobilized':
+
            case 'immobile':
+
            case 'immob':
+
                mark = 'fishing-net';
+
                break;
+
            case 'marked':
+
            case 'mark':
+
                mark = 'purple';
+
                break;
+
            case 'petrified':
+
            case 'petrify':
+
            case 'stone':
+
                mark = 'white-tower';
+
                break;
+
            case 'prone':
+
                mark = 'back-pain';
+
                break;
+
            case 'restrained':
+
                mark = 'aura';
+
                break;
+
            case 'slowed':
+
            case 'slow':
+
                mark = 'snail';
+
                break;
+
            case 'stunned':
+
            case 'stun':
+
                mark = 'lightning-helix';
+
                break;
+
            case 'weakened':
+
            case 'weak':
+
                mark = 'broken-heart';
+
                break;
+
            case 'ongoing':
+
            case 'damage':
+
            case 'dam':
+
                if(args[2]) {
+
                    args[2] = args[2].toLowerCase();
+
                    switch(args[2])
+
                    {
+
                        case 'acid':
+
                            mark = 'chemical-bolt';
+
                            break;
+
                        case 'cold':
+
                            mark = 'frozen-orb';
+
                            break;
+
                        case 'fire':
+
                            mark = 'half-haze';
+
                            break;
+
                        case 'force':
+
                            mark = 'blue';
+
                            break;
+
                        case 'lightning':
+
                            mark = 'edge-crack';
+
                            break;
+
                        case 'necrotic':
+
                            mark = 'death-zone';
+
                            break;
+
                        case 'poison':
+
                            mark = 'skull';
+
                            break;
+
                        case 'psychic':
+
                            mark = 'pink';
+
                            break;
+
                        case 'radiant':
+
                            mark = 'angel-outfit';
+
                            break;
+
                        case 'thunder':
+
                            mark = 'yellow';
+
                            break;
+
                        default:
+
                            sendChat('ERROR', '/w ' + msg.who + ' No damage type called ' + args[2]
+
                                    + '. If the damage has no type, do not include a type!');
+
                            return;
+
                    }
+
                }
+
                else mark = 'all-for-one'; // untyped ongoing damage
+
                break;
+
            case 'dying':
+
            case 'helpless':
+
            case 'unconscious':
+
            case 'insubstantial':
+
            case 'surprised':
+
                sendChat('ERROR', '/w ' + msg.who + ' The ' + args[1]
+
                                + ' status is not implemented for the !mark command.');
+
                return;
+
                break;
+
            default:
+
                mark = args[1]; // allows for direct status setting
+
                break;
+
        }
+
    }
+
   
+
    var target = getObj('graphic', args[0]);
+
    if (!target) {
+
        sendChat('ERROR', '/w ' + msg.who + ' Please specify a token to mark with @{target|token_id}.');
+
        return;
+
    }
+
   
+
    switch (command)
+
    {
+
        default:
+
        case 'mark':
+
            target.set('status_'+mark, true);
+
            break;
+
        case 'unmark':
+
            target.set('status_'+mark, false);
+
            break;
+
        case 'clearmark':
+
            target.set('statusmarkers', '');
+
            break;
+
    }
+
});
+
</pre>
+
  
==== Examples ====
+
{| class="wikitable"
'''!mark @{target|token_id} brown'''
+
|-
<blockquote>This will set the brown marker on the target token.</blockquote>
+
! Condition
 
+
! Aliases
'''!mark @{target|token_id} immob'''
+
! Condition
<blockquote>This will set the 'immobilize' icon to the target token.</blockquote>
+
! Aliases
 
+
|- style="vertical-align:top"
'''!mark @{selected|token_id} ongoing fire'''
+
| style="width:100px" | '''Blinded'''
<blockquote>This will mark the selected token with ongoing fire damage.</blockquote>
+
| style="width:200px" | blinded<br>blind
 
+
| style="width:100px" | '''Prone'''
'''!unmark @{selected|token_id}'''
+
| style="width:200px" | prone
<blockquote>This will remove the purple (default) statusmarker from the selected token.</blockquote>
+
|- style="vertical-align:top"
 
+
|| '''Dazed'''
'''!clearmark @{selected|token_id}'''
+
|| dazed<br>daze
<blockquote>This will remove all markers from the selected token.</blockquote>
+
|| '''Restrained'''
 +
|| restrained
 +
|- style="vertical-align:top"
 +
|| '''Deafened'''
 +
|| deafened<br>deaf
 +
|| '''Slowed'''
 +
|| slowed<br>slow
 +
|- style="vertical-align:top"
 +
|| '''Dominated'''
 +
|| dominated<br>dominate
 +
|| '''Stunned'''
 +
|| stunned<br>stun
 +
|- style="vertical-align:top"
 +
|| '''Immobilized'''
 +
|| immobilized<br>immobile<br>immob
 +
|| '''Weakened'''
 +
|| weakened<br>weak
 +
|- style="vertical-align:top"
 +
|| '''Marked'''
 +
|| marked<br>mark
 +
|| '''Ongoing Damage'''
 +
|| ongoing<br>damage<br>dam
 +
|- style="vertical-align:top"
 +
|| '''Petrified'''
 +
|| petrified<br>petrify<br>stone
 +
|| '''Dying<br>Helpless<br>Unconscious<br>Insubstantial<br>Surprised'''
 +
| style="width:200px" | '''''Marking Conditions''' explicitly does not handle these statuses, and will generate an error message if you try to use one.''
 +
|}
  
[[Category:User API Scripts|Marking Conditions]]
+
=== Changelog ===
[[Category:API Commands|Marking Conditions]]
+
{{changelog version|3.3|2015-03-26|* [bugfix] fixed bugs reported by {{user profile|376031|Ron}}}}
 +
{{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-09|* Release}}

Latest revision as of 13:49, 11 October 2021

Main Page: API:Script Index


API ScriptAuthor: Brian
Version: 3.3
Last Modified: 2015-03-26
Code: Marking Conditions
Dependencies: splitArgs
Conflicts: None

Marking Conditions creates the API commands !mark, !unmark, and !clearmark

[edit] Syntax

!mark <tokenid> [status [type]]
!unmark <tokenid> [status [type]]
!clearmark <tokenid>
Formally:

S

→ !mark tokenid
status


S

→ !unmark tokenid
status


S

→ !clearmark tokenid


tokenid

string

status

→ ε

status

stringdamage


damage

→ ε

damage

→ acid

damage

→ cold

damage

→ fire

damage

→ force

damage

→ lightning

damage

→ necrotic

damage

→ poison

damage

→ psychic

damage

→ radiant

damage

→ thunder
Parameter Values
tokenid ID of a token object. This can be obtained with @{target|token_id} or @{selected|token_id}.
status Optional. Either the name of a statusmarker icon, or else one of many aliases to D&D 4e conditions.


If status is not specified, the purple statusmarker will be used.

type Optional. A D&D 4e damage type. Only used if status is "ongoing", "damage", or "dam". If supplied, should be one of:
  • acid
  • cold
  • fire
  • force
  • lightning
  • necrotic
  • poison
  • psychic
  • radiant
  • thunder

If type is not specified, a statusmarker to represent untyped damage will be used.

The !mark command will set a marker, while the !unmark command will clear it. !clearmark will clear all markers from the token.

[edit] Conditions and Aliases

The available status aliases and the D&D 4e conditions they map to are listed below.

Condition Aliases Condition Aliases
Blinded blinded
blind
Prone prone
Dazed dazed
daze
Restrained restrained
Deafened deafened
deaf
Slowed slowed
slow
Dominated dominated
dominate
Stunned stunned
stun
Immobilized immobilized
immobile
immob
Weakened weakened
weak
Marked marked
mark
Ongoing Damage ongoing
damage
dam
Petrified petrified
petrify
stone
Dying
Helpless
Unconscious
Insubstantial
Surprised
Marking Conditions explicitly does not handle these statuses, and will generate an error message if you try to use one.

[edit] Changelog

v3.3 (2015-03-26)

  • [bugfix] fixed bugs reported by Ron


v3.2 (2015-01-24)

  • [bugfix] no-arg crash


v3.1 (2015-01-22)

  • Fixed transcription error


v3.0 (2015-01-09)

  • Release