Difference between revisions of "Script:Marking Conditions"
From Roll20 Wiki
(→Code) |
(updated to use @target/@selected instead of poorly-implemented descriptors, and added means to remove singular markers) |
||
Line 1: | Line 1: | ||
− | The following script creates the API | + | The following script creates the API commands <code>!mark</code>, <code>!unmark</code>, and <code>!clearmark</code> |
==== Syntax ==== | ==== Syntax ==== | ||
− | <blockquote style="border:1px #0088ee solid;background:#eee;padding:0.5em">!mark '' | + | <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" | {| class="wikitable" | ||
Line 9: | Line 11: | ||
! Values | ! Values | ||
|- | |- | ||
− | | '' | + | | ''tokenid'' |
− | | | + | | 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. |
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
| ''status'' | | ''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. | | (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. | ||
− | If ''status'' is not specified, the purple statusmarker will be used | + | If ''status'' is not specified, the purple statusmarker will be used. |
|- | |- | ||
| ''type'' | | ''type'' | ||
Line 35: | Line 34: | ||
|} | |} | ||
− | + | 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 ==== | ==== Code ==== | ||
<pre data-language="javascript"> | <pre data-language="javascript"> | ||
− | + | on('chat:message', function(msg) { | |
− | + | if(msg.type != 'api') return; | |
− | + | ||
− | + | ||
− | + | ||
− | on( | + | |
− | if(msg.type != 'api' | + | |
− | var args = msg.content | + | var args = msg.content.split(' '); |
− | args.shift(); | + | var command = args.shift().toLowerCase().substring(1); |
− | + | if (!(command == 'mark' || command == 'clearmark' || command == 'unmark')) return; | |
− | if( | + | if (args.length == 0) { |
− | + | sendChat('ERROR', '/w ' + msg.who + ' Please supply a token target with @{target|token_id}'); | |
− | + | return; | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
− | var | + | 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; | 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 ' | + | 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]) | ||
{ | { | ||
− | sendChat('ERROR', '/w ' + who + ' | + | 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 | + | 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 ==== | |
− | + | '''!mark @{target|token_id} brown''' | |
− | + | <blockquote>This will set the brown marker on the target token.</blockquote> | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | '''!mark @{target|token_id} immob''' | |
− | + | <blockquote>This will set the 'immobilize' icon to the target token.</blockquote> | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | </ | + | |
− | + | '''!mark @{selected|token_id} ongoing fire''' | |
− | '''!mark | + | <blockquote>This will mark the selected token with ongoing fire damage.</blockquote> |
− | <blockquote>This will | + | |
− | '''! | + | '''!unmark @{selected|token_id}''' |
− | <blockquote>This will | + | <blockquote>This will remove the purple (default) statusmarker from the selected token.</blockquote> |
− | '''! | + | '''!clearmark @{selected|token_id}''' |
− | <blockquote>This will remove all | + | <blockquote>This will remove all markers from the selected token.</blockquote> |
[[Category:User API Scripts|Marking Conditions]] | [[Category:User API Scripts|Marking Conditions]] | ||
[[Category:API Commands|Marking Conditions]] | [[Category:API Commands|Marking Conditions]] |
Revision as of 10:43, 15 June 2014
The following script creates the API commands !mark
, !unmark
, and !clearmark
Syntax
!mark tokenid [status [type]]
!unmark tokenid [status [type]]
!clearmark tokenid
Parameter | Values |
---|---|
tokenid | The ID of the token to mark. Use @{target|token_id} or @{selected|token_id} to get this value.
|
status | (Optional) A D&D 4e status (except for dying, helpless, unconscious, insubstantial, or surprised) or the name of a statusmarker icon. The script has several aliases for the statuses. For example, immobilized, immobile, and immob all correspond to the same marker.
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. One of:
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.
Code
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; } });
Examples
!mark @{target|token_id} brown
This will set the brown marker on the target token.
!mark @{target|token_id} immob
This will set the 'immobilize' icon to the target token.
!mark @{selected|token_id} ongoing fire
This will mark the selected token with ongoing fire damage.
!unmark @{selected|token_id}
This will remove the purple (default) statusmarker from the selected token.
!clearmark @{selected|token_id}
This will remove all markers from the selected token.