How to create a damage over time mechanic?

I’ve been trying to come up with a way to create some sort of ‘bleeding’ system. Say the PC uses a special skill to poison or cause someone to bleed, how would I code it in a way that has ‘ticks’ of damage happen every turn?

I thought about having something like this at the start of every combat turn:

*if (poison = true)
    *set enemyhp %- 5
    The enemy is heavily poisoned! They are losing HP every turn!

The only thing I’m not sure of if this is the optimal way to do it. Is there a better, more efficient way for this?

1 Like

You’ll need an event where the trigger will take place. You can have it at the start or the end (or anywhere you think it fits).

Btw, why the %-? Percent-op, or as CS described it as fairmath, will not reduce the [enemyhp] variable to zero. I don’t think not being able to kill the opponent with DoT is something intentional, no?

1 Like

Oops, me no read well. I thought fairmath prevented things from going below zero, not stopping it BEFORE zero. Whoops. Thanks for the heads up.

I think I can have some sort of ‘check’ in the beginning of each combat turn, I’m just not sure how to code it optimally so it isn’t completely spaghetti’d.

1 Like

Here’s a rudimentary way of going with it. It would be better to separate mechanics and stats to their own text file for the sake of organization.

*create player_health 10
*create player_poisoned false

*create enemy_health 10
*create enemy_poisoned false

*comment This is a turn computation
*label next_turn
*gosub player_turn
*gosub enemy_turn

*if player_health <= 0
    Oh no, you lost?
*elseif enemy_health <= 0
    Huh, you won.
    The fight is still going!
    *goto next_turn

*label player_turn
*gosub apply_poison "player"
*comment Put player actions here.

*label enemy_turn
*gosub apply_poison "enemy"
*comment Put enemy actions here.

*label apply_poison
*params to_apply

*if ({to_apply}_poisoned = true)
    *set {to_apply}_health ({to_apply}_health - 5)