Issues with negative numbers in combat system

Evenening ladies and gentleman,

I have encountered some bemusing issues when trying to create a combat system for my own choice game that being 2 things:

  1. Damage can be avoided through a block function. Currently the code goes “*set damage - block” So the amount of damage taken is reduced based on the blocking value. Problem: When the block role is higher than the damage role it creates a negative damage number and the palyer ends up GAINING extra HP. I more or less accidently created a regenaration function it seems. While this hasnt caused severe issues in testing it can result into fights never ending if both the player and the opponent fight defensefly.
  2. The Second point was discovered due to issue number one: The Player can heal past his max HP. Meaning you can literally have more HP than what the max was supposed to be through blocking.

Since this is my very first project im very inexperienced in coding.
However since its a medieval action adventure (cause im very creative like that) I view some form of combat as neccesary to keep things intresting so im refusing to abondan the idea entirely.
I am however open to suggestion of alternative systems.

*if wounded = "False"
	*set HP max_HP
*if wounded = "Wounded"
	*set HP max_HP /2
*label your_turn
*if opponent_HP <1
	*set fight "won"
	*return
*if HP <1
	*set fight "lost"
	*return

${opponent}
*line_break
${opponent_HP} / ${opponent_maxHP}
	

${name}
*line_break
${HP} /${max_HP}
	
*choice
	#Defensive
		*rand damage 1 3
		*set damage + Strength
		*set opponent_hp - damage
		*rand block 5 8
		*set block + Dexterity
		You Strike ${opponent} dealing  ${damage} points worth of damage
		*goto opponents_turn


	#Neutral
		*rand damage 3 6 
		*set damage + Strength
		*set opponent_hp - damage
		*rand block 3 6
		*set block + Dexterity
		You Strike ${opponent} dealing  ${damage} points worth of damage
		*goto opponents_turn

		
	#Offensive
		*rand damage 5 8
		*set damage + Strength
		*set opponent_hp - damage
		*rand block 1 3
		*set block + Dexterity
		You Strike ${opponent}  dealing  ${damage} points worth of damage
		*goto opponents_turn

*label opponents_turn
*rand damage 1 8
*set damage + opponent_Strength
*set damage - block
*set HP - damage
${opponent} strikes you, dealing ${damage} points worth of damage
*goto your_turn
2 Likes

You can test if the block is greater than the damage. If it is, you can set it equal to the damage. That should prevent damage healing someone:

*if (block > damage)
–*set block damage

In your opponents_turn label, just add a condition statement to prevent variable overflows based on your maximum/minimum values.

*label opponents_turn
*rand damage 1 8
*set damage + opponent_Strength
*set damage - block

*if (damage < 0)
  *set damage 0

*set HP - damage

Also, note that in this code block will result in the player always winning and could have 0 or negative health, IF both the player and the opponent reaches 0 health in the same turn. So you might run into some issues that the player has ≤0 health post-battles despite winning against enemies.

3 Likes

OF COURSE!
Why didnt I come up with this myself?
The solution to almost every problem is just another *if statement.

If I decide to implement a healing mechanic I can also follow the same system to avoid players healing over max hp.

Thank you kindly for your reply and the example.
Thank you also for pointing out the victory thing.
Probably have to figure out a way around that as well.

Currently I have a “wounded” mechanic were, once a healthy player reaches 0 HP most fights will end but the player will survive with theyr max HP being halfed for the rest of the Chapter/scene.
A second chance.

Probably gone use this as a work around for these scenarios.

1 Like

This topic was automatically closed 24 hours after the last reply. If you want to reopen your WiP, contact the moderators.