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

Is this possible to script, or is it out of the scope of the API?

Hello roll20 community, Though I'm not unfamiliar with programming languages, I haven't had the chance to test the limits of the API on roll20. I'm currently running a GURPS game while ignoring a lot of the rules to keep things moving. If I could automate the crunch in the system I'd be able to run a real gurps game. To be clear, I'm not asking other people to do this for me, I just want to know if it's possible - if I can help someone out by making these scripts I'd be happy to re-learn javascript. I would love to hear from those of you who know its limits to tell me if this is possible In GURPS combat, one attack is: Roll 3d6 to see if you hit. Call this AttackerRoll Roll 3d6 to see if the target dodges/parries. Call this DefenderRoll. If Defender succeeds, drop all further calculations. If Defender fails, continue: For the Attacker, if using rapid fire, calculate the success rate compared to recoil value. This would track how many shots hit the target. Report the # of hits to the chat for the players to roll damage on. Next, roll 3d6 for HIt Location Table. Send hit location result to the chat. Next, calculate damage to hit location. This will tell the GM/players the maximum possible damage for the target to suffer on the targeted limb (so you can't kill someone by shooting them in the foot). For simplicity, just have a marker for players when they roll damage, like /r 5d6+2 WD where WD would indicate the script to interpret as a damage roll. Divide the Defender's DR by the weapon's Armor Divisor Multiply the Defender's DR by number of hits. For the Defender, after the damage is done, roll 3d6 for Shock. As you can see, the amount of rolls and number crunching at a glance can slow things down a lot. I've avoided running the game with all of this stuff to keep things fun - we all like simulationism but simulations are best done with a computer to do the numbers for you. Thank you roll20 community, and have a wonderful day
yes, it is all possible. In fact, I have attempted to make such scripts, as I DM gurps on here myself for a few friends but i am not a programmer, so i only have bits chopped from other peoples code and made to fit.
You can use the sendChat() command to make rolls, and get the results of those rolls, then deciding further action to take based upon the results. You can program the Hit Location Table as an object in your API script to reference. You can issue commands to the API via "bangs" (e.g. !WD 4d6+2), and you can set up macros on the player side so all they do is a press a button to execute that command. So yes, I think all of that should be possible to do currently. If you wanted to get really fancy, you could even set up Attributes on your Characters (which the API can then reference to automatically know what to add/roll for damage rolls for PCs, enemies, etc.)
Awesome! Thanks a lot for your replies. I'll be getting down to work on this script after a quick refresher on JS.
Keep us updated. I have a GM who loves GURPS that I'm trying to get into Roll20. Neither of us code, but if I could set him up with an API that handles alot of crunch for us I'd bag him as a subscriber for sure. Then I could get my GURPS on without having to drive 20minutes.
Will do - I have a draft in pseudocode already, hoping to have a functional draft by the end of next week. Life, schoolwork, & the campaign I'm GMing will take priority, but it shouldn't be too difficult.
Update: I've been learning javascript, but some stuff is beyond what I remember when I took C++/Java in high school. The learning curve is, sadly, larger than I expected. Part of it I think is my approach to the documentation. I keep hoping I can just leap into a working script so I can iterate upon it, but I'm still stuck on recording input/output. It's the only thing stopping me from putting a working script to the test with my players. I have all of the calculations to be done with the rolls typed up, all I need is for the player rolls to be recorded to variables. I'm sure it's really obvious, but the code examples I've seen on the wiki and here just leave me baffled. Everything I've tried thus far ends with an Unexpected token error. Here's the small bit of code I did to test the functionality: var DefenderRoll; on("chat:message", function(msg) { log(msg); if(msg.type=="api" && msg.content=="!dr") { var buffer = JSON.parse(sendChat(msg.who, "/roll 3d6 (Defense roll)")); DefenderRoll = buffer.rollresult; sendChat(msg.who, DefenderRoll); log(content); } }); What I need to get this functional: 1. Record chat messages, parsing for certain key terms, such as !dr for a defense roll. In the case of something more complex, i.e. !ar which would include multiple variables being recorded. 2. Record roll results. 3. Display results to players. This is just an update - I'll eventually figure it out! If anyone knows any helpful links to answer this problem, please enlighten me :]
Real quick, I think you're using the API inline roll parsing incorrectly. You need to pass the sendChat a function that will capture the roll results and parse them there. For instance, in the documentation there is the following example . In this case you'll want to do the JSON.parse on rollresult . sendChat("Riley", "/roll 1d20+4", function(ops) { // ops will be an ARRAY of command results. var rollresult = ops[0]; //Now do something with rollresult, just like you would during a chat:message event... }); Going forward, you may not need to do an inline roll in the first place. The message you send in an inline roll through the API like that never actually appears in the players' chat windows. You could just call the randomInteger function provided by the API. This is the same RNG used for dice rolls and can give you your desired rolls. Then format those into a nice message to the players.
John M. said: Real quick, I think you're using the API inline roll parsing incorrectly. You need to pass the sendChat a function that will capture the roll results and parse them there. For instance, in the documentation there is the following example . In this case you'll want to do the JSON.parse on rollresult . sendChat("Riley", "/roll 1d20+4", function(ops) { // ops will be an ARRAY of command results. var rollresult = ops[0]; //Now do something with rollresult, just like you would during a chat:message event... }); Going forward, you may not need to do an inline roll in the first place. The message you send in an inline roll through the API like that never actually appears in the players' chat windows. You could just call the randomInteger function provided by the API. This is the same RNG used for dice rolls and can give you your desired rolls. Then format those into a nice message to the players. What if I want the players to see the roll, I am working on an attack api script and I would like them to be able to see their d20s as they are being rolled by the api.
1387715312
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
Stephen H. said: John M. said: Real quick, I think you're using the API inline roll parsing incorrectly. You need to pass the sendChat a function that will capture the roll results and parse them there. For instance, in the documentation there is the following example . In this case you'll want to do the JSON.parse on rollresult . sendChat("Riley", "/roll 1d20+4", function(ops) { // ops will be an ARRAY of command results. var rollresult = ops[0]; //Now do something with rollresult, just like you would during a chat:message event... }); Going forward, you may not need to do an inline roll in the first place. The message you send in an inline roll through the API like that never actually appears in the players' chat windows. You could just call the randomInteger function provided by the API. This is the same RNG used for dice rolls and can give you your desired rolls. Then format those into a nice message to the players. What if I want the players to see the roll, I am working on an attack api script and I would like them to be able to see their d20s as they are being rolled by the api. You can't fake dice rolls.... you can share the data... but you can't fake out a dice roll.
1387759760

Edited 1387760374
I strongly disagree... *edit* I was thinking somethign completely different, I'm reading this on a computer now, and I realized that you seem to be going for a the 3d dice effects?
Yes I use a api to handle attack/damage rolls but the players miss seeing the actual dice hit the table, I do sendchat to calculate the rolls but there doesnt seem to be a way to hook into the actual dice interface