Hey Guys! OrkAndHat's question about multiple weapons having dice attack values like in tabletop roleplaying games, stored in object variables, Inspired me to check out how this could be handled.

For our starting example: in D&D/Pathfinder a longsword does 1d8+(player's Strength Modifier) damage each successful attack. Which basically means you roll one eight-sided die, for a random total of 1-8, then add the player's attack score.

Weapon Setup:

In ORK Framework tab: Inventory => Weapons I took my Long Sword (from the tutorial) and added two new Equipment Variables.

Variable 0:
Variable Key, Value = "diceNumber"
Type = float
Operator = Set
Value = 1

This variable tells the formula how many dice we are rolling, because some weapons might be 2d6 (two six-sided dice) or 5d4 (five four-sided dice)

Variable 1: Copy Variable 0 and change the following
Variable Key, Value = "diceValue"
Value = 8

This variable tells the formula which die we want it to roll, or rather, what the range of the random number should be. The formula will be set up to generate a number between and including 1 and this number.

That's it for Weapon Setup, lets move on to our formula.

Formula Setup:

In tab Game => Formulas, Add a new formula.

Name it "Damage Modifier", with a Type of "other"
The Start Value I am leaving as a value, so when the formula is called, a number can tell the formula which weapon we are looking for here, so people can have more than one or two weapons if they have more than one or two arms as in OrkAndHat's example.

1) Add a Store Formula Value Node to the start node (add > Variable > Store Formula Value) Set the Variable Origin to Local and the Key Value to 'weaponLocation', with Operator = Set.

2) Add a Game Variable Fork (Add > Check > Game Variable Fork)
Variable Origin = local
Value = 'weaponLocation'

Now a new condition.

Variable Condition 0:
Type = Float
Check Type = Is Equal
Value = 1

Duplicate this condition as many times as you have weapon slots on your most armable character, changing the value each time to one higher.

3) from Condition 0 of the Game Variable Fork, add a Select Equipment Node (Add > Selected Data > Select Equipment)
Selected Key, Value = "weapon"
Change Type = set

Equipment Part = 'Right Hand'

Then Copy this Select Equipment Node and Change the Equipment Part on Each one to the next weapon holding equipment start, and ling the Conditions of the Variable Fork to them.

4) You might be staring at a lot of Equipment Nodes, but that's okay because they all lead to the same exit node. We will create a Change Game Variables node. We will actually create a new variable here to attach to the weapon, and initialize it to 0, for keeping track of how many times the formula has "rolled" the die of set value.
Variable Origin = Global
Add Game Variable
Variable 0:
Variable Key, value = "timesRolled"
Type = Float
Operator = Set

Float Value, Value = 0

5) Now to calculate our “dice roll”. From the Change Game Variable Add a Random Value Node (Add > Value > Random Value)

Operator = Set
As Int = Selected
Value 1, Value = 1 (you cannot roll less than a one on a die)
Value type = Game Variable
Variable Key = ‘diceValue’
Variable Origin = Selected
Selected Key, Value = ‘weapon’

6) Copy the old Change Game Variables and add the new one in after the Random Value. Change it’s value to 1, since we have now “rolled the die” one time.

7) Add a new Rounding node (Add > Base > Rounding). for Rounding, select Round. This makes our value between 1 and 8 where it was functionally 1.00001 to 7.99999 before.

8) If we knew we were only ever going to be dealing with one die, we would be done, but since it’s is possible to want a weapon that has a multiple d(x) damage modifier, we will add a Check Game Variable node. (Add > Variable > Check Game Variable)
Variable Origin = Selected
Selected Key, Value = weapon
click Add Game Variable

Variable Condition 0:
Variable Key, Value = ‘diceNumber’
Type = Float
Check Type = is Greater
Value Type = Game Variable
Variable Key = ‘timesRolled’

(I tried being clever and making ‘timesRolled’ an object variable, but it was creating an infinite loop when checking it against the diceNumber, since the ValueType of the Check Game Variable was not letting me set it to a selected Key Variable as well. Global can be reused for other rolls as well. Infinite Loops are Bad.)
If both dice number and times rolled are 1, this will fail after one roll, but if we needed two dice and only got one, it’s time to roll again! Let’s cover that first.

9) Duplicate the previous Random Value node.
This time the operator will be Add (rather than Set)

10) We are going to link the output from this new Random Value back into the second Change Game Variable which increments ‘timesRolled’. This creates a loop that will exit once ‘diceNumber’ is no longer greater than ‘timesRolled’. Now we need to set what happens when that check fails.

11) Create a new Store Formula Value node, connected to the failed output of the Check Game Variables node.
Variable Origin = Selected
Selected Key Value = ‘weapon’
Variable Key, Value = ‘damageModifier’
Operator = Set

This stores the newly calculated Damage Modifier value to a variable on the weapon itself, the value of which will be overwritten each time the function is called, so that the modifier can be added to the Attack attribute in a different event or function if needed. Alternatively, if you know your attack event is going to use the final Damage Modifier value immediately, you can just not add this last node and let the final formula value funnel right through into the calling event.

So now we can do Tabletop style Attack rolls in our game! To test the formula, I set my combatant to Blue Pants, who is equipped with the Long Sword as their starting equipment, and the starting value to 1. Hitting Calculate repeatedly should generate numbers between 1 and 8 inclusive.

Thanks for learning this with me. And special thanks to forum user UserName who Pointed me to the Value Node! I didn’t end up using it in this, but is was a really good lead. I'd like to invite you all to let me know if any of you end up trying this, and share ways you've made it more efficient or versatile.
Sign In or Register to comment.