Dungeons and Dragons’ Skill Check

The classic skill check employed by Dungeons and Dragons has several rules, and most of them need to be broken down, espeically to script everything out. So, let’s dive right into it.

Youtube Link For Explanation

Modularity.

The first thing to keep in mind is to make everything modular. I want to make sure that this can be called almost anywhere. Level Blueprint, the player character, enemies, and just general skill checks. In the game, this can be called anywhere, making this extremely versatile.

Let’s Break it Down

Dungeons and Dragon’s skill checks are pretty complex when the full mechanic is broken down. Luckily, I’ve been obsessed with DnD since I was in high school and played as my friends’ dungeon master. Each skill check takes into account a couple things:

  1. Dice Type (D4, D6, D10, D20, D50, D100)

  2. Ability (Con, Dex, Str, Wis, Int, Cha)

  3. Skills’ Proficiency or Expertise

  4. Buffs/Debuffs (some of them stack and others do not)

Now these all come together to make what I call the “The Beuatiful Roll” and gives rise to many different ways to calculate these.

D20+Ability Modifier + Proficiency/Expertise + Buffs/Debuffs

Now, when playing in person as a Dungeon Master, a simple look through a character sheet, and I can tell if a player has expertise in something or not. This is a bit tricky in programming, so we have to take it slow and methodical.

We can break down the dice types and we can easily calculate the ability modifer. But the expertise and proficiency in skills are much harder to calculate. This is because of the way we store data, and what is the most efficient way to store it. But to do that, we can actually break down the skills. Each skill is governed by an ability, for example, Athletics is governed by Strength and Arcana is governed by Intelligence. using this, we can actually break down the skills into categories. This is, in fact, how the DnD book I used in 10th grade did it!

So, let’s actually start making this in Unreal Engine 5!

Where does it start?

In the example that I have, the skill check starts from the level blueprint and casts to the third-person character since this blueprint is always loaded. I then grab the player stats component and I call the Test Skill Check function. In this function there are three input pins (besides the target). The first is the dice type, this asks for D4, D6, D10, D20, or really any kind of dice. The second is the skill to check. This pulls from the main subset of skills that I have curated from my extensive time playing Baldur’s Gate 3, and being a dungeon master with my friends. The third input is the pass state, this is the simple skill check to compare everything against.

Set Up.

The player’s stats are set up through an Actor Component. This allows me to seperate this and put this onto any and every character allowing for ease of multiplayer or even just attaching it to an NPC. Within the Actor Component, the stats are all set up through data tables and structs. The struct tells what the information is, and the data table populates it. This is a pretty simple way to set up player class and the player stats. This also allows me to pull any and all player information directly from the Player Stats Component.

In the end, this allows me to increase the modularity so that I can mess with anything at any given time.

Skill Check Function.

The actual function calls to many different functions inside of it. But the base premise starts as follows. The player stats are called and I can pass all the relevent information as needed. In my example here, I only used the Intelligence Stat to hardcode it, but it can easily be passed in, or even a new struct can be made to hold those values. The way my variables are set can and will be massively improved upon.

The function then calls into Whole Skill Check. The purpose of this function is to calculate the sum total of all the player’s skills, adding up proficeincy, dice roll, and more. Speaking of the dice roll, the dice type goes into the first pin. The player level goes into the second, the main stat to use (Con, Dex, Str, Wis, Int, and Char), then the stat upon which the skill is being checked. Lastly, there is the proficiency check. I did not add expert to this yet. This is something I plan on improving in the near future.

After the Whole Skill Check, we check against the pass state, and we return what it was. Returning the final dice roll would also be helpful, and I will make sure to also add that in the near future. The function Whole Skill Check, there are three main functions to go through.

The first function is the Dice Skill Check. This checks for the player’s dice roll. If 1, Critial Fail state; if 20, Critical Pass state. If it is from 2-19 inclusive, then we go through the main calculations.

The proficiency bonus was a bunch of weird math, but that math is very subject to change based upon the proper rules of DnD. From my time as Dungeon Master, this was the base calculation that we did, but otherwise, it’s entirely subject to change. But this does give us the bonus. If there is a bonus, then the constant is applied. If not, then it is left alone. This function calculates not just the bonus, but the actual proficiency as well. Expertise can also be added and perhaps into this function itself or in another function, but that will have to be expanded upon at a later date.

Different Classes.

Different classes have different stats and different races grant different bonuses. While I didnt’ account for race, I tried to account for the base classes. I had a few, which I populated through data tables as shown above. I also made sure to test these out with simple inputs so that I am able to grab different classes and test them all out in real-time. With this, I was able to call the set stats function and print a simple string to showcase what happened.

Final Product.

In the end, when I pass through the trigger box that I set up, I cast to the third-person character, then pull the BPC Player Stats component, from there, I have access to the Test Skill Check. I had two skill checks: Arcana and History. From these messages, it seems that as a Rogue Class, I passed the Arcana skill check but failed the History skill check, which honestly seems pretty on brand for that class.

After rolling, the function will return the dice check and the dice roll since the function is making the roll itself. This allows me to grab a switch statement and do certain actions based upon those states. The fail and the pass will both pass their respective numbers. Fail will pass a 1 for the dice roll and the Pass will pass a 1000 which is an arbitrarily high number that I don’t think anything can get past.

The brunt of the calculations then happens afterwards where we call the Get Stat Modifier and the Get Proficiency Bonus functions. These functions hold math.

The Stat Modifier brings in one of the base abilities (Con, Dex, Str, Wis, Int, and Char) to grant the bonus. This bonus, I am very confident is right based upon the rules of DnD that I have researched. I tried to take everything into a formula to pull math instead of just doing switches or if-statments. Like I mentioned before, I am confident on this math, but it’s entirely subject to change. It returns the modifier bonus. This also goes into a negative territory, which I noticed Baldur’s Gate 3 did, so I left it alone and did not try to make a if-statment out of it. .

Previous
Previous

Curing Corruption

Next
Next

Emergence from the Grave