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

Script to decrement stat on character sheet?

I'm looking for a script that will decrement the value of a current stat on a character sheet by an amount specified in the command. (Specifically, I'm intending it to reduce the current END level on Hero System characters, but it could also be used in other games for reducing hit points by a specific amount, or for marking ammo usage.) For example, let's say the syntax is !burn N. !burn 10 would reduce the level of the stat by 10, !burn 20 by 20, etc. Any thoughts? Does such a script exist already?
1384212696

Edited 1384212793
Short answer: that is really basic functionality in a script. Longer answer: That barely even constitutes a script. Using the API, you'll spend more effort capturing the call from chat and identifying the character ( charObj in the code below) to which to apply the modification ( modValue in the code below). Once those parts are done, changing the value would be as simple as: // find the relevant attribute to modify (attribName is a string containing the attribute name ie. 'END') attribObj = findObjs({type:'attribute', characterid: charObj, name:attribName})[0]; attribObj.set('current', (attribObj.get('current') - modValue)); I dare say there are many scripts that do similar things to what you are requesting. You'll just need to find one that does something similar enough and fit it to your needs.
1384217045

Edited 1384221107
Lithl
Pro
Sheet Author
API Scripter
Just so that it's easily accessible, here's a skeleton script for capturing an API command: on('chat:message', function(msg) { if(msg.type != 'api') return; // we short-circuit all of the logic if the message wasn't even a !command var parts = msg.content.split(' '); // spaces are generally used to separate commands and arguments // `parts` is an array of each "word" in the message var command = parts.shift() // removes the first element from `parts` and returns its value .substring(1) // removes the "!", which I find makes the code look cleaner -- not truly necessary .toLowerCase(); // lets the user enter !command, !COMMAND, !cOmMaNd, etc. if(command == 'burn') { // assuming "!burn" is your API command // put business logic for !burn here, such as John's post; for example: var charObj = findObjs({ type: 'character', controlledby: msg.playerid })[0]; var attribName = 'END'; var attribObj = findObjs({ type: 'attribute', characterid: charObj.id, name: attribName })[0]; if(attribObj) attribObj.set('current', attribObj.get('current') - parseInt(parts[0])); // the above code assumes each player is controlling at most one character, and // NPC characters have no controller } // you can add additional commands to the same script file by adding additional if blocks });
I see how it works. Thanks Brian and John!