Determine turns in a custom battle system using a base stat such as speed.

  • Jpratt
  • 08/09/2022 08:24 PM
You may find this tutorial helpful if you are not using a default battle system but are using a turn based system. You should have an advanced understanding of variables and conditions before considering making your own battle system.

I'm going to show you a system designed around having only 1 player in the party and up to 3 enemies. If you understand these principles, adding more party members or enemies will not be difficult.

I recommend building the various components of your custom battle system in their own common events which will be either called or copied into the main battle common event. This will keep the main battle code clean enough to follow.

E will be used to describe an enemy.
P will be used to describe a player party member.
Characters refers to all players, party members, enemies in a battle.
SPD is the base speed statistic of the character.
ACT is a variable which will determine when the character's turn is ready.
BATTLE TURN CHECK common event will be where speed is determined.
CALL FIGHT common event is where the main programming of all battles is held.

Start a new common event called CALL FIGHT. Trigger is None.
Start a new common event called BATTLE TURN CHECK. Trigger is None.

Create these variables:

Side note 1: The numbers I'm using are arbitrary for use as an example. You'll need to change the numbers to your liking to balance your battle system.

Side note 2: You could create VAR P1-SPD, VAR P1-ACT; VAR P2-SPD, VAR P2-ACT; etcetra if you want to include more party members.

Side note 3: We are going to use 3 enemies in our example, which means in a battle the player will fight either 1, 2, or 3 enemies at most.

Side note 4: Be sure to set VAR P-SPD when a new game starts to whatever starting value you think your player should begin with. This is only necessary for characters which start in your party at the beginning of the game. All characters added to the party would have their stats set at that time. Enemy stats are determined when a fight is called based on the enemies you are fighting.

SPD will determine how fast the player can attack. Enemies have their own speed variables which determine how fast they can attack. I like to work with small numbers where each stat increase is meaningful, so let's start with a base speed of 15 for the player.

A second variable will be needed to determine when the player can act. We will call this var P-ACT.

For this example we are going to be counting up to 70 using the value stored in var P-SPD. When P-ACT is 70 or greater, the player will make their move. 75/15= 4.66, This means it will take to the count of 5 for the player to be able to make a move as you will not reach 70 by the count of 4 but will reach it by the count of 5.

This code should be entered at or near the start of your CALL FIGHT common event. It ensures the order of actions are not influenced by the last fight.

Comment: reset turns
VAR E1-ACT = 0
VAR E2-ACT = 0
VAR E3-ACT = 0

Chances are you'll still be utilizing RPG Maker 2003's core functions to some degree, including it's base statistics such as Agility. This comes in handy when you get to programming in armors, weapons, etc. However, it means we need to have our base battle stats set to these core functions.

In CALL FIGHT, using Variable Controls, add:

VAR P-SPD = Player's AGI

Labels will be used to jump to relevant code and to cycle the code until either the player or all the enemies are defeated, which is determined by HP. The + variables are used to count up to 70 to determine when a character is ready to act. The conditional branches check if a character is ready to act. Always start these checks with the player so player acts first in a tie.

start cycle until player or all enemies defeated
Label: 100

check if all enemies are defeated and check if player defeated
Conditional Branch: VAR E1 HP <= 0
Conditional Branch: VAR E2 HP <= 0
Conditional Branch: VAR E3 HP <= 0
Comment: End the fight adding the stuff that happens when player wins.
Conditional Branch: VAR P HP <= 0
Comment: End the fight adding the stuff that happens when player is defeated.
Branch End
Branch End
Branch End
Branch End

speed used to count up action for player. Will only count up enemies which are still alive
Conditional Branch: VAR E1 HP >= 1

Conditional Branch: VAR E2 HP >= 1

Conditional Branch: VAR E3 HP >= 1

if any character can act, this label cycles until no character can act
Label: 99

if actions can be made, will cycle through from player to E3, until all who can act have acted, in the correct order
Conditional Branch: VAR P-ACT >= 70
Comment: jump to player turn start label
Jump to Label: 40

Else; Conditional Branch: VAR E1-ACT >= 70
Comment: jump to Enemy 1 turn start label
Jump to Label: 50

Else; Conditional Branch: VAR E2-ACT >= 70
Comment: jump to Enemy 2 turn start label
Jump to Label: 60

Else; Conditional Branch: VAR E3-ACT >= 70
Comment: jump to Enemy 3 turn start label
Jump to Label: 70
Branch End
Branch End
Branch End
Branch End

recycle turns until player or all enemies defeated
Jump to label 100

player actions label after the player's choices and outcomes are made, -75 from P-ACT to account for some overage count.
Label: 40
Comment: call event for player action functionality
VAR P-ACT – 75
Jump to Label: 99

E1 actions label runs E1 actions from called events, -75 from E1-ACT to account for some overage count.
Label: 50
Comment: call event for E1 actions and outcomes
VAR E1-ACT – 75
Jump to Label: 99

E2 actions label runs E2 actions from called events, -75 from E2-ACT to account for some overage count.
Label: 60
Comment: call event for E2 actions and outcomes
VAR E2-ACT – 75
Jump to Label: 99

E3 actions label runs E3 actions from called events, -75 from E3-ACT to account for some overage count.
Label: 70
Comment: call event for E3 actions and outcomes
VAR E3-ACT – 75
Jump to Label: 99

Here are some results you can expect from using this system.

If player SPD = 15
If E1 SPD = 10
If E2 SPD = 15
If E3 SPD = 20

Player outcome:
15+15+15+15+15= 75
Means player can act every 5 cycles, always.

10+10+10+10+10+10+10 = 70
-75 = -5
+10+10+10+10+10+10+10+10 = 75

The first turn takes 7 cycles while the second turn takes 8 cycles. The third cycle will take 7, the fourth 8, and so on. This is a closed loop cycle.

On average E1 will take 7.5 cycles to be able to act, while the player will use 5 cycles. 5/7.6 = 0.66, or 2/3. This means E1 will only act two times for every 3 actions the player gets to take.

E2 will have the same outcome as the player, but player will get to move first, so E2 will never act before the player. The player and E2 will have 1-1 actions.

20+20+20+20 = 80
-75 = 5
+20+20+20+20 = 85
-75 = 10
+20+20+20 = 70
-75 = -5
+20+20+20+20 = 75
-75 = 0

This is still a closed loop albeit a longer one. To act it takes E3 4 cycles, 4 cycles, 3 cycles, 4 cycles and then resets. 4+4+3+4 = 15. 15/4 = 3.75.

The player average cycle is 5 and E3 average cycle is 3.75. 5/3.75 = 0.75. The player will get to act 3 times for every 4 actions E3 gets.

Too complex?

Short Form Math

P-SPD / E-SPD = turns player gets compared to enemy

If player SPD = 15
If E1 SPD = 10
If E2 SPD = 15
If E3 SPD = 20

15/10 = 1.5
15/15 = 1
15/20 = .75

Let's say you're later game and the stats have started to get a lot higher and more odd. Not to mention you could still fight some of those early game baddies.

43/10 = 4.3 Player will attack an average of 4.3 times before that easy baddie even gets to fight back.
43/20 = 2.15 Player has a noticeable advantage gained over time.
43/57 = 0.75 Still see lots of balance in speed.

Heck, let's throw in a crazy high speed boss to see what happens.

43/100 = 0.43
Boss will attack an average of 2.33 times for every 1 attack player does.

What if you tried fighting that boss right from the start?

15/100 = 0.15
Boss will attack an average of 6.67 times for every 1 attack player does.

Final Advice
Now that you've seen how numbers work in this system, you should play around with numbers you want to see in your game before building your CBS. It's a lot easier to add the numbers as you build rather than having to edit them all later.

Keep in mind your starting stats, stats gained from equipment, and any bonuses to stats you intend to provide the player along the way. In a very short game or one without a levelling system that relies on equipment, small numbers will work very well. In a massive game where you want to reward the player frequently without having a negative impact on balance, you can use larger overall numbers so those small additions don't make as much of an impact.

Consider the easiest enemy in the game and the hardest enemy in the game. Your player should be able to defeat the easiest enemy using no equipment or boosts, but it should be slightly challenging, and having to face multiple of that enemy could result in defeat. On the flip side, the final enemy of the game should not be beatable with no equipment or boosts. In fact, it may only be possible after boosting your base stats significantly through levelling and equipment, and still require a large party. If so, going back to those original enemies should be a walk in the park, but the rewards should then be so insignificant the player wouldn't feel the need.

How does the above relate to turns? Well, it's not a big deal if at the end game your player can beat the easiest bad guys without them ever getting a turn. However, it should not be the other way around.

You do not want to fight a boss that gets to hit you 8 times before you can do anything, and your players won't want that either. There are two ways to balance this - one is by keeping speed within a smaller limit, and the other is the scaling of damage and defence. If your player is not ready to face the really big boss, then the really big boss should be able to defeat them in a few hits anyway, negating the need to count out tons of turns. But if your player is immune to their damage type, you also don't want them to sit there for 8 turns in a row getting plumbed by 1 or 2 damage then do 1 or 2 damage themselves.

Also, the example system counts to 75. After some testing with my own game I found this to be a good number to keep things tight. However, the player will have limited ability to increase base stats like speed. If they were to boost it by 30 that would be considered a whole lot and require several means. So if they start at 15, that gets them to 45 on the high end.

45+45 = 90 - 75 = 15
+45 +45 = 105 - 75 = 30
+45 = 75 - 75 = 0

This still resets on a 3rd cycle. Compared to an enemy with 10 speed it's only a 4.5-1 ratio. I would cap an enemy out at 75. Theoretically I could cap my player out at 75 as well. Anything higher starts to break the system, so I would need to increase to count cap. No player or enemy speed should ever exceed the count cap.

One more thing. I've discussed this as a static system where one character acts at a time. This means an enemy can't hit a player while the player is making thier move. You could change this to a fluid system where the player and enemy moves can happen simultaneously but you would need to modify a bit: higher difference between player and enemy counting to allow player time to act, a time delay during the count cycle so enemy actions aren't instant, and a visual aid for the player to see when turns are available for more intense fights, for starters.

Thanks for reading. I'll likely put more guides together for custom battle systems. Feel free to provide feedback. Too much explanation? Use images to show the code instead? Let me know!


Pages: 1
Some custom battle skill ideas based off the above numbers:

Enemy SLOW status effect: -113 to an enemy spd var.
Cast on all enemies by slowing subtracting all the enemy speed variables.

Freeze an enemy by subtracting 200 from an enemy speed var.

Counter attack by setting player speed var to 75 when damage is blocked.

Set a double strike skill for the player that adds 75 speed to players speed var immediately after landing a critical hit.

If you have timed status effects you want to wear off, you could freeze time by setting all characters speed var to -200. This would be useful if you were had a status effect which increases damage taken, or an enemy had a bleed effect draining their life.

Combo streak for thr player could be created by setting player speed multiples over the 75 cap. 225 would be a 3 hit combo, 300 would be a 4 hit combo.
Pages: 1