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

[Help] Counting Arrows

I would like to have a script that I can execute from an Ability from a Character in the journal section. I want the command to lower the value of an Attribute called "Arrows" by 1 point every time it is called. That way when I set up the Attribute, I can add an extra command into the Attribute, and it will lower the characters arrow count by one for every arrow that is fired. It's been a little frustrating so far trying to find any helpful information on how to get started working in API. I used to mod and script for games, but not in Java. It would be useful to have access to some more info to help me get started in this. Thank you to anyone who is willing to help out in this.
1392877110
Lithl
Pro
Sheet Author
API Scripter
on('chat:message', function(msg) { if (msg.type != 'api') return; var parts = msg.content.split(' '); var command = parts.shift().substring(1); var playerid = msg.playerid; var character = findObjs({ _type: 'character', name: msg.who }); if (character.length > 0) character = character[0]; else { log('Character not found'); return; } if (command == 'shootArrow') { var arrowsAttr = findObjs({ _type: 'attribute', _characterid: character.id, name: 'Arrows' })[0]; if (!arrowAttr) { log('Attribute not found'); return; } var cur = parseInt(arrowAttr.get('current')); if (cur === 0) { sendChat('SYSTEM', '/w ' + character.get('name') + ' You do not have any arrows to fire.'); return; } arrowAttr.set('current', cur - 1); } }); Code is untested.
Thanks a bunch. But what do I need to name my Attribute for it to link up, and could you please tell me what command to use in the Ability to run the script?. I really wish there was a starter resource for using API. I feel like such a novice, though I've had experience with modding other games, I'm lost here.
1392898829
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
Josh B wrote: "Thanks a bunch. But what do I need to name my Attribute for it to link up, and could you please tell me what command to use in the Ability to run the script?." if (command == ' shootArrow ') { var arrowsAttr = findObjs({ _type: 'attribute', _characterid: character.id, name: 'Arrows ' })[0]; "Arrows" would be the attribute name "shootArrow" ("!shootArrow") would be the command. (Wasn't being snarky by posting the code quote, just hopefully helping to make it a bit more clear for you.)
After a few tweaks to the code, I got it working. THANKS for the help guys, this will really help me put together some other stuff.
Josh, which tweaks did you need to make?
The arrows attribute is sometimes referred to as "arrow" instead of "arrows" which causes it not to function properly. But when they are all set to "arrows" then it works fine again.