Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Ammo API Script - Suppressing whispers and setting bounds on GM

As the title says, can I suppress the whispers by commenting out the calls to "sendMessage"?  I've got PowerCards reporting to the PCs how much they have remaining and such so I want no chat output from the script.   Also, is there a way to set bounds on the GM so the value won't decrement below zero?  Thanks!
Is the ammo script still actively being maintained? If not, I could look at it here in a little bit.
I'm not sure, HB.  Its one of Aaron's scripts so I thought so.  Its working beautifully still if it isn't.
1448135026

Edited 1448135052
The Aaron
Pro
API Scripter
Yeah, it's an old one, but I still look after it. =D Here's a version that doesn't send output for changes (still does for errors), and restricts the GM like the players: // Github: &nbsp; <a href="https://github.com/shdwjk/Roll20API/blob/master/Ammo/Ammo.js" rel="nofollow">https://github.com/shdwjk/Roll20API/blob/master/Ammo/Ammo.js</a> // By: &nbsp; &nbsp; &nbsp; The Aaron, Arcane Scriptomancer // Contact: &nbsp;<a href="https://app.roll20.net/users/104025/the-aaron" rel="nofollow">https://app.roll20.net/users/104025/the-aaron</a> var Ammo = Ammo || (function() { &nbsp; &nbsp; 'use strict'; &nbsp; &nbsp; var version = '0.3.0-RestrictedGM-NoMessages', &nbsp; &nbsp; &nbsp; &nbsp; lastUpdate = 1427602798, schemaVersion = 0.1, ch = function (c) { var entities = { '&lt;' : 'lt', '&gt;' : 'gt', "'" : '#39', '@' : '#64', '{' : '#123', '|' : '#124', '}' : '#125', '[' : '#91', ']' : '#93', '"' : 'quot', '-' : 'mdash', ' ' : 'nbsp' }; if(_.has(entities,c) ){ return ('&'+entities[c]+';'); } return ''; }, sendMessage = function(message, who) { sendChat('Ammo', (who ? ('/w '+who+' ') : '') + '&lt;div style="padding:1px 3px;border: 1px solid #8B4513;background: #eeffee; color: #8B4513; font-size: 80%;"&gt;' +message +'&lt;/div&gt;' ); }, adjustAmmo = function (playerid,attr,amount) { var val = parseInt(attr.get('current'),10)||0, max = parseInt(attr.get('max'),10)||10000, adj = (val+amount), chr = getObj('character',attr.get('characterid')), valid = true; if(adj &lt; 0 ) { valid = false; } else if( adj &gt; max) { valid = false; } if( valid ) { attr.set({current: adj}); } }, showHelp = function(playerid) { var who=getObj('player',playerid).get('_displayname').split(' ')[0]; &nbsp; &nbsp; &nbsp; &nbsp; sendChat('', &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '/w '+who+' ' +'&lt;div style="border: 1px solid black; background-color: white; padding: 3px 3px;"&gt;' +'&lt;div style="font-weight: bold; border-bottom: 1px solid black;font-size: 130%;"&gt;' +'Ammo v'+version +'&lt;/div&gt;' +'&lt;div style="padding-left:10px;margin-bottom:3px;"&gt;' +'&lt;p&gt;Ammo provides inventory management for ammunition stored in a character' +'attribute. &nbsp;If the adjustment would change the attribute to be below 0 or above' +'it\'s maximum value, a warning will be issued and the attribute will not be' +'changed.&lt;/p&gt;' +( (playerIsGM(playerid)) ? '&lt;p&gt;&lt;b&gt;Note:&lt;/b&gt; As the GM, bounds will not be ' +'enforced for you. &nbsp;You will be whispered the warnings, but the operation ' +'will succeed. &nbsp;You will also be told the previous and current state in case ' +'you want to revert the change.' : '') +'&lt;/div&gt;' +'&lt;b&gt;Commands&lt;/b&gt;' +'&lt;div style="padding-left:10px;"&gt;' +'&lt;b&gt;&lt;span style="font-family: serif;"&gt;!ammo '+ch('&lt;')+'id'+ch('&gt;')+' '+ch('&lt;')+'attribute'+ch('&gt;')+' '+ch('&lt;')+'amount'+ch('&gt;')+' &lt;/span&gt;&lt;/b&gt;' +'&lt;div style="padding-left: 10px;padding-right:20px"&gt;' +'This command requires 3 parameters:' +'&lt;ul&gt;' +'&lt;li style="border-top: 1px solid #ccc;border-bottom: 1px solid #ccc;"&gt;' +'&lt;b&gt;&lt;span style="font-family: serif;"&gt;id&lt;/span&gt;&lt;/b&gt; -- The id of the character which has the attribute. &nbsp;You can pass this as '+ch('@')+ch('{')+'selected|token_id'+ch('}')+' and the character id will be pulled from represents field of the token.' +'&lt;/li&gt; ' +'&lt;li style="border-top: 1px solid #ccc;border-bottom: 1px solid #ccc;"&gt;' +'&lt;b&gt;&lt;span style="font-family: serif;"&gt;attribute&lt;/span&gt;&lt;/b&gt; -- The name of the attribute representing ammunition.' +'&lt;/li&gt; ' +'&lt;li style="border-top: 1px solid #ccc;border-bottom: 1px solid #ccc;"&gt;' +'&lt;b&gt;&lt;span style="font-family: serif;"&gt;amount&lt;/span&gt;&lt;/b&gt; -- The change to apply to the current quantity of ammo. &nbsp;Use negative numbers to decrease the amount, and possitive numbers to increase it.' +'&lt;/li&gt; ' +'&lt;/ul&gt;' +'&lt;/div&gt;' +'&lt;/div&gt;' +'&lt;div style="padding-left:10px;"&gt;' +'&lt;b&gt;&lt;span style="font-family: serif;"&gt;!get-represents [token_id]&lt;/span&gt;&lt;/b&gt;' +'&lt;div style="padding-left: 10px;padding-right:20px"&gt;' +'This command will show the character id for the supplied token id, or will list the character ids for all the selected tokens.' +'&lt;ul&gt;' +'&lt;li style="border-top: 1px solid #ccc;border-bottom: 1px solid #ccc;"&gt;' +'&lt;b&gt;&lt;span style="font-family: serif;"&gt;token_id&lt;/span&gt;&lt;/b&gt; -- The id of the token to lookup, usually supplied with: '+ch('@')+ch('{')+'selected|token_id'+ch('}') +'&lt;/li&gt; ' +'&lt;/ul&gt;' +'&lt;/div&gt;' +'&lt;/div&gt;' +'&lt;/div&gt;' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ); &nbsp; &nbsp; }, HandleInput = function(msg_orig) { var msg = _.clone(msg_orig), args,attr,amount,chr,token,text=''; if (msg.type !== "api") { return; } if(_.has(msg,'inlinerolls')){ msg.content = _.chain(msg.inlinerolls) .reduce(function(m,v,k){ m['$[['+k+']]']=v.results.total || 0; return m; },{}) .reduce(function(m,v,k){ return m.replace(k,v); },msg.content) .value(); } args = msg.content.split(/\s+/); switch(args[0]) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case '!ammo': if(args.length &gt; 1) { switch(args[1]) { case 'recover': // &lt;character/token_id&gt; &lt;attribute_name&gt; // apply policy to put amounts back in case 'check': // &lt;character/token_id&gt; &lt;attribute_name&gt; // print the amount in the attribute nicely formatted case 'recovery-policy': // [character/token_id] [attribute_name] &lt;percentage&gt; // create the right entry in the state case 'name': // [character/token_id] [attribute_name] &lt;name&gt; // create the right entry in the state // configs case 'recovery-updates-maximum':&nbsp; // adjust the maximum to be whatever the current is case 'create-attributes-automatically':&nbsp; // create the requested attribute and start using it. } chr = getObj('character', args[1]); if( ! chr ) { token = getObj('graphic', args[1]); if(token) { chr = getObj('character', token.get('represents')); } } if(chr) { if(! playerIsGM(msg.playerid)&nbsp; && ! _.contains(chr.get('controlledby').split(','),msg.playerid)&nbsp; && ! _.contains(chr.get('controlledby').split(','),'all')&nbsp; ) { sendMessage( 'You do not control the specified character: '+chr.id ); sendMessage( '&lt;b&gt;'+getObj('player',msg.playerid).get('_displayname')+'&lt;/b&gt; attempted to adjust attribute &lt;b&gt;'+args[2]+'&lt;/b&gt; on character &lt;b&gt;'+chr.get('name')+'&lt;/b&gt;.', 'gm' ); return; } attr = findObjs({_type: 'attribute', _characterid: chr.id, name: args[2]})[0]; } amount=parseInt(args[3],10); if(attr && amount) { adjustAmmo(msg.playerid,attr,amount); } else { if(attr) { sendMessage( 'Amount ['+args[3]+'] is not correct. &nbsp;Please specify a positive or negative integer value like -1 or 4.', (playerIsGM(msg.playerid) ? 'gm' : false) ); } else { if(chr) { sendMessage( 'Attribute ['+args[2]+'] was not found. &nbsp;Please verify that you have the right name.', (playerIsGM(msg.playerid) ? 'gm' : false) ); } else { sendMessage( ( (undefined !== token) ? ('Token id ['+args[1]+'] does not represent a character. ') : ('Character/Token id ['+args[1]+'] is not valid. ') ) +'Please be sure you are specifying it correctly, either with '+ch('@')+ch('{')+'selected|token_id'+ch('}')+' or copying the character id from: !get-represents '+ch('@')+ch('{')+'selected|token_id'+ch('}'), (playerIsGM(msg.playerid) ? 'gm' : false) ); } } } } else { showHelp(msg.playerid); } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; case '!get-represents': if(args.length &gt; 1) { chr = getObj('character', args[1]); if( ! chr ) { token = getObj('graphic', args[1]); if(token) { sendMessage( 'The specified token represents the following character:' +'&lt;ul&gt;&lt;li&gt;'+ ( ('' !== token.get('name')) ? token.get('name') : 'BLANK' )+' -&gt; '+ ( ('' !== token.get('represents')) ? token.get('represents') : 'NOTHING' ) + '&lt;/li&gt;&lt;/ul&gt;', (playerIsGM(msg.playerid) ? 'gm' : false) ); } else { sendMessage( ' Token id ['+args[1]+'] is not valid.', (playerIsGM(msg.playerid) ? 'gm' : false) ); } } } else if (msg.selected && msg.selected.length) { _.each(msg.selected, function(s) { token = getObj('graphic', s._id); if(token) { text += '&lt;li&gt;'+ ( ('' !== token.get('name')) ? token.get('name') : 'BLANK' )+' -&gt; '+ ( ('' !== token.get('represents')) ? token.get('represents') : 'NOTHING' ) + '&lt;/li&gt;'; } }); sendMessage( 'The selected tokens represent the following characters:'+'&lt;ul&gt;' + text + '&lt;/ul&gt;', (playerIsGM(msg.playerid) ? 'gm' : false) ); } else { showHelp(msg.playerid); } break; } }, &nbsp; &nbsp; checkInstall = function() { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; log('-=&gt; Ammo v'+version+' &lt;=- &nbsp;['+(new Date(lastUpdate*1000))+']'); &nbsp; &nbsp; &nbsp; &nbsp; if( ! _.has(state,'Ammo') || state.Ammo.version !== schemaVersion) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; log(' &nbsp;&gt; Updating Schema to v'+schemaVersion+' &lt;'); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; state.Ammo = { version: schemaVersion, config: { }, policies: { global: { recoveryUpdatesMaximum: false }, byAttribute: { }, byCharacter: { } } }; } }, RegisterEventHandlers = function() { on('chat:message', HandleInput); }; return { &nbsp; &nbsp; &nbsp; &nbsp; CheckInstall: checkInstall, RegisterEventHandlers: RegisterEventHandlers }; }()); on("ready",function(){ 'use strict'; Ammo.CheckInstall(); Ammo.RegisterEventHandlers(); });
Woot!&nbsp; Perfect, thank you sir!