Roll20’s API Scripts

Continuing from my previous post about Roll20, I wanted to talk about how script writing for Roll20 works and the particulars of the script I’m writing.

Roll20 has something called an API (Application Programming Interface) a term that the programmers reading this are already aware of, but one which I had to look up while writing this.

Behind all the fancy jargon I read, an API is a way to write and test programming code.

The simplest “API” is something like Notepad. You can design a program in it, but Notepad won’t run your program or tell you where you messed up.

There are more complicated APIs track syntax errors in your code, color the different key words, point out where you messed up, and even let you test run your code.

Roll20’s API tracks syntax and color codes. It tells you IF you messed up, but not WHERE. So when there is inevitably a problem you get to play hide and seek until you find it.

Every API is designed for a specific programming language. Roll20 uses Javascript.

I didn’t know any Javascript going into this.

I’m familiar with the basics of programming. I’ve taught myself a little bit of Python, I took a course on C in college, and I know a little about Perl and HTML* from various places.
*Not exactly a programming language but I’ll bet that nobody really cares.

To learn the particulars of Javascript I started taking a course on CodeAcademy.

The CodeAcademy course is pretty cool! Nice assisting prompts. A little poor on alternative ways of solving the problems, but that’s actually a good thing for programming courses.

I learned a little about Javascript from that, enough to write the program I wanted to for Roll20.

And what program is that? Something to automatically spit out the results of a critical hit in Hackmaster!

Hackmaster is a game like D&D that I play with my friends sometimes. Hackmaster has a ton of cool rules that make the game quite a bit more fun and shocking than D&D.

One of those rules is what happens when you hit your opponent real good. Depending on your height advantage over your opponent, the weapon you used, and how hard you hit, a special event occurs.

Why do I want a program for that? Well… Take a look.

Critical hit chart comes with lion and everything else you see here.
Critical hit chart comes with lion and everything else you see here.

There are about twenty pages like this that just go on and on.

It’s a bit much to flip through all those pages, cross reference with the different numbers you need, and then trail your finger down the chart to see what happens.

Instead, why not have a program do the work for you?

The program is started when a player uses the Critical Hit macro. Remember how macros can ask for values? That’s all the Critical Hit macro does. No dice are rolled.

The Critical Hit macro asks for seven different values: your size, your opponent’s size, your attack roll, your opponent’s defense roll, your damage roll, your opponent’s armor strength, and the type of weapon you’re using (Crushing, Hacking, or Piercing).

Next comes the script. The script is triggered when the Critical Hit macro is entered.

Nowhere near Matrix levels of code yet.
Nowhere near Matrix levels of code yet.

I looked around on Roll20’s forums and found the skeletons of some other scripts to use for the script to take information out of the Critical Hit macro and use it in the program.

From there, the script rolls a several thousand sided die that represents the location hit by the critical with different sized dice depending on the difference between the attacker’s and the defender’s sizes.

After getting that roll, the script enters a gigantic ~3,000 line long if/else tree that serves in place of the twenty page table. This comes up with a different results based on the location of the blow, how hard the target was hit, and what type of weapon was used.

Finally, the program spits out the result into Roll20’s chat along with some background information to make sure that it worked correctly.

Does the code work? Well, I don’t know yet. I’ve been typing away at it for about a week now and have transferred roughly one fifth of that giant table in the book to the programming script.

Due to how I structured the code, I can’t tell if it works correctly until I finish the whole thing.

Unfortunate, but what can I do at this point?

So here’s hoping that when I’m done in a few weeks and I press that Critical Hit macro button, it runs as smooth as melted chocolate.

If not, then I’ll probably have a blog post to make about code debugging…

-GoCorral

P.S. If you play Hackmaster and are interested in this code I will be posting the completed version of it on the Roll20 forums and the Hackmaster forums once I’ve finished. I’m also planning on doing a similar thing for the Fumble charts for Hackmaster so stay tuned for those as well.

Heroic Thaddius

The DREAM!
Misdirection. The DREAM!

Continuing in the series of posts about how to beat the Heroic bosses in Hearthstone’s Naxxramas adventure, here’s Thaddius!

Heroic Thaddius has two advantages over Normal Thaddius.

First, he’s got 15 more health than the Normal version.

Second, on his first turn he automatically summons his own Feugen and Stalagg.

While he may start with two immense monsters, the good news is that they can’t attack on the turn he summons them and they don’t trigger their own deathrattles.

Even better, Thaddius’ Feugen and Stalagg will trigger your own versions of those minions. So if his Feugen has died and your Stalagg dies, then Thaddius is summoned to your side of the field.

Thaddius starts with a big advantage and this is the deck I came up with to remove that advantage as quickly as possible:
Hunter’s Mark x2
Arcane Shot x2
Tracking x2
Webspinner x2
Explosive Trap x2
Freezing Trap x2
Misdirection x2
Mad Scientist x2
Nerubian Egg x2
Eaglehorn Bow
Animal Companion x2
Deadly Shot x2
Unleash the Hounds x2
Multishot x2
Feugen
Stalagg
Kel’Thuzad

The ideal hand includes a Misdirection or a Tracking. You go first and play the Tracking if you need to find a Misdirection.

Thaddius goes second and summons Feugen and Stalagg.

Your turn comes around again and you play Misdirection.

Thaddius goes. He plays a minion and then attacks with Feugen and Stalagg. The Misdirection triggers and you pray that the two beasties kill each other. It’s a 1/3 chance that they will.

And that’s it. The deck has a few other methods for removing Feugen and Stalagg. Then it stalls the game out with secrets until you can gain complete control with a big Unleash the Hounds combo or by playing your own Feugen and Stalagg and getting a huge Thaddius on your side.

Really once you’ve got a Thaddius on the board you’ve probably won.

Other things that work really well against Heroic Thaddius are Nerubian Egg, Dire Wolf Alpha, Raid Leader, and Stormwind Champion.

Thaddius’ Polarity Shift hero power will always trigger Nerubian Egg, making it a cheap 4/4.

The Polarity Shift also interacts strangely with buffs that the other three cards have. The buffed attack (or attack and defense for Stormwind) is switched to defense, creating a permanent gain in stats. Then the buff is applied to the attack once again. If it keeps switching then your minions keep getting more stats. Leokk from the Animal Companion spell also takes advantage of this effect.

Cards to avoid against Thaddius are ones with zero attack. The Shaman is pretty bad because his hero power will be close to useless. Flametongue Totem will have the same swapping power that Dire Wolf Alpha does, but it dies in the process.

Regardless, the Hunter deck works and isn’t too expensive to craft. Plus, secrets are always fun!

-Mister Ed

The True Colors: Chapter Two

Chapter Two: Swift Troubles

“Back from the dead?” exclaimed Hornblower, “Dammit Bush! What is this nonsense you’re spouting? Explain yourself!”

Bush drummed his left hand on the table while with his right he took a sip from a beer stein that Hornblower had previously missed. “There’s little time to explain right now. I have a strong suspicion that I was followed here. I’ll only be able to explain once we get back to the others.”

“The others? What others?”

Bush leaned forward out of the booth and swept his eyes across the room before answering. “You never know who may be watching… or listening.”

Hornblower struggled not to shout. He elected to use a harsh whisper instead, “Bush! If you don’t tell me where you’ve been for the last ten years or what is going on right now then I shall count this as a strange dream and go back home in my carriage to sleep it off!” By the end of the short squall Hornblower unleashed he was on his feet instead of sitting in the booth.

Bush’s eyes flicked to Hornblower’s, to the bar, and then back to Hornblower. “We’ve been friends a long time haven’t we?”

“Not for the last ten years we haven’t. And I thin-”

“Shush! We’ve been friends a long time. I’m asking you to trust me right now. I promise I’ll explain everything soon, but right now we need to get to a safe place. Now how did you say you got here?”

“In a carriage. I left it at the middle of the port with the driver.”

“Let’s go there. Everything will be made clear soon.”

Bush hefted himself up out of the booth and made his way to the door. Hornblower sighed and pulled his coat tighter around him as they headed out into the cold night air. He thought to himself, At least it smells better outside of this place.

They walked in silence with Bush leading the way. Hornblower attempted to collect some of the dignity and poise appropriate for a man of his position as they walked. The same questions flew through his mind. Where had Bush gone? How did he survive the explosion? Where had he been all these years? And what the Devil was that poppycock about Napoleon coming back from the dead? If it was true, which it wasn’t, was it the Second Coming or something altogether different? Hornblower decided it was best not to think of such things now. He’d wanted his old friend back for so long and he feared that any excessive questioning on his part might drive the new cagey Bush away.

Still, some old rules should continue to be observed. Hornblower wouldn’t have Bush leading him to the carriage. He walked a slightly quicker pace and easily passed the Captain on his wooden leg. “It’s this way,” Hornblower said. Bush grunted and followed.

They soon reached the carriage. In the dim light, Hornblower could see the driver on the seat with his hands folded in his lap holding the reins. Hornblower waved at him, but got no response in turn. Annoyed, Hornblower opened the door to the carriage himself. He turned back to Bush and asked, “Where are we going?”

“I need to check something first. Did you bring my letter with you?”

“Yes, I did.”

“Where is it?”

“Right here on the seat where I left it.” Hornblower glanced to the seat, but saw the letter had fallen onto the floor.

“On the seat?” asked Bush. He looked at the letter on the cabin floor, then at the driver, who continued to stare straight ahead with his hands in his lap.

Over the constant sound of the sea, Hornblower heard a creak behind him of a roof tile moving slightly in the wind. Bush turned to look at the sound and then instantly lunged at Hornblower, tackling him to the ground. A gunshot blasted into the side of the carriage sending a spray of wood chips onto the ground around the two sailors.

Hornblower picked himself up onto his elbows and drew the pistol from inside his coat. Bush shouted, “Take cover! They’re on the roofs!” Hornblower rolled under the carriage just as another bullet hit the cobblestones where he was before.

Bush joined Hornblower under the carriage. As he crawled under, Hornblower saw the body of the driver fallen on the ground. He must’ve been killed by their attackers earlier and placed back on the driver’s seat as bait for Hornblower and Bush. The two horses stamped their hooves, but stayed where they were.

Between two deep breaths to keep himself calm Hornblower asked, “How many did you see?”

“Four I think.”

The gears in Hornblower’s mind turned. They attackers wouldn’t be able to get them under the carriage with pistols or rifles. If they came down he could shoot one of them easily, so they probably wouldn’t take that risk. It was also unlikely that they would keep waiting til one of them came out. If they waited til morning other people would come out and he and Bush could make their escape. If he were in the attackers’ position that left one other option.

Hornblower asked, “Do you know these people?”

“I know who they work for.”

“Are they the types to set fire to the carriage?”

“Yes.”

“Did you bring a pistol with you?”

“I brought two,” Bush replied.

“You watch the left and the rear side and I’ll watch the right and through the horses’ legs. If you see them lighting a fire, then fire back at them.”

“Aye-aye.”

Hornblower and Bush waited. Soon, Hornblower saw two boots approaching from the right side of the carriage close to the horses. In the darkness he propped himself up on his elbows. He laid the pistol barrel in the palm of his left hand and aimed three feet above one of the pairs of boots, hoping that the blind shot would hit. Hornblower heard the sound of flint on steel and fired. A split second later he heard Bush fire as well. The horses spooked with the gunfire so close to them. They ran, taking the carriage away with them. Hornblower heard a pistol fire from one of the pairs of boots while person in the other pair fell to the ground bleeding.

Hornblower jumped to his feet. The horses pulled the carriage past the body of the man Hornblower shot and the other man approaching from that direction. Hornblower whipped around and saw a second man fall to Bush’s pistols. All that remained was the one man who had wasted his shot when the horses spooked. The man fumbled for something in his coat and Hornblower rushed him.

Without a weapon of his own, Hornblower simply tackled the man to the ground. He doubted he could overpower him, but perhaps he could buy time for Bush to get up from the ground. Hornblower and the man fell. Another gunshot resonated through the dockyard. The man went limp. Hornblower felt a pistol shaped lump in the man’s coat and then the warm wet feeling of blood pouring out of the man’s chest. He had shot himself with an extra pistol when Hornblower tackled him to the ground.

Hornblower rolled off the man and stared at the clouds over the harbor as he recovered his breath. He saw the wind blowing the clouds away for a bit of starlight to shine through. Bush appeared in his vision next to the star. “We’ve got to get to your estate. They’ll have figured out who you are and will try to use Lady Barbara and your son against you. We don’t have time to wait for the constables to sort this out. We must leave quickly.”

Hornblower picked himself up, “For God’s sake, Bush! What is going on?”

“I promise I’ll explain on the way, Admiral, but we must hurry. Your family’s lives are at stake.”

“Fine. Now where’s that blasted carriage gotten to?”