Setting a status effect duration to a specific amount of rounds in combat(sugarcube2)

I have <<set $rounds += 1>>, however, I'm not quit sure how to implement status duration like burn damage, stun, confusion, or even player and ally buffs to this. Any ideas? I'd really appreciate it.

Edit: I have 2 combat passages 1 for the player and 1 for the enemy’s attack with chances of attack and missing, i just want the effects to last a few turns if the attack or cast hits its mark. so far I’m using if statements for the majority of my game btw.

I’m not familiar with the language in question, but in general I would have a counter for each status. Each turn, if the counter was greater than zero, I’d apply its effects; at the end of the turn, all positive counters would decrease by one.

For something like this, it’s best to either use a generic object or an array of generic objects to represent each creature. I’ll show you how to do it using a generic object.

First, you’ll want to create a variable to keep track of everyone in your StoryInit passage like this:

<<set $characters = {}>>

That makes the $characters variable an empty object.

You can then add characters and all of their properties to it like this:

<<set $characters.player = { name: "Steve", hp: 10, mp: 20, dmg: 2 }>>

You can add other properties to a character later on like this:

<<set $characters.player.poisoned = 2>>

So that could indicate that the player takes poison damage for the next two rounds.

If the player was healed, then you can remove that status effect by doing this:

<<set delete $characters.player.poisoned>>

and that will delete the “poisoned” property from the player.

Note that each character and property needs to be a unique identifier (such as “player”). You can’t have two creatures that both have the identifier of “orc”, so you’d need to call them “orc1” and “orc2”, or something similar. You’ll also probably want to add a property for enemies, so that your code can tell them apart. Something like:

<<set $characters.orc1 = { name: "Fat Orc", hp: 5, mp: 0, dmg: 2, enemy: true }>>

With that, in your code you could check to see if a character has a .enemy property set to true to determine if it’s an enemy or not.

Now, within your game loop, when a turn ends, you could check everyone for poison damage like this:

<<nobr>>
	<<for _char range $characters>>

		/* Check for poison damage. */
		<<if def _char.poisoned>>
			_char.name takes 1 point of poison damage!<br>
			<<set _char.hp -= 1>>
			<<set _char.poisoned -= 1>>
			<<if _char.poisoned = 0>>
				<<set delete _char.poisoned>>
				_char.name is no longer poisoned.<br>
			<</if>>
		<</if>>

	<</for>>
<</nobr>>

That checks each character, and if the .poisoned property is defined on that character, then it applies the poison effect, reduces the poison counter, and deletes the .poisoned property when it reaches 0.

You can do other effects in similar ways.

Please let me know if you have any questions on the above.

Hope that helps! :slight_smile:

I think I did something like that but a bit more simplified just using set and if statements. check it out.

\<<set $burnCounter to 3>>
\<<set $freezeCounter to 5>>
\<<set $stunCounter to 4>>
\<<set $blindCounter to 4>>
\<<set $poisonCounter to 4>>
\<<set $confusionCounter to 4>>
\<<set $gravityCounter to 3>>

\<<if $estatus is "$burn">>
	$ename is Burned!
	<<set $burnCounter -= 1>>
	<<set $ehp -= 15>>
\<<elseif $burnCounter is 0>>
	<<set $estatus to "">>
	<<set $burnCounter to 3>>
	<<set $aflicted to false>>
\<</if>>
\<<if $estatus is "$freeze">>
	$ename is Frozen!
	<<set $freezeCounter -= 1>>
	<<set $ehp -= 10>>
	<<set $eatk to 0>>
\<<elseif $freezeCounter is 0>>
	<<set $estatus to "">>
	<<set $freezeCounter to 5>>
	<<set $aflicted to false>>
\<</if>>
\<<if $estatus is "$stun">>
	$ename is Stunned!
	<<set $stunCounter -= 1>>
	<<set $eatk to 0>>
\<<elseif $stunCounter is 0>>
	<<set $estatus to "">>
	<<set $stunCounter to 4>>
	<<set $aflicted to false>>
\<</if>>
\<<if $estatus is "$blind">>
	$ename is Blinded!
	<<set $blindCounter -= 1>>
	<<set $chance to random(1, 200) + $dex>>
\<<elseif $blindCounter is 0>>
	<<set $estatus to "">>
	<<set $blindCounter to 4>>
	<<set $aflicted to false>>
\<</if>>
\<<if $estatus is "$poison">>
	$ename is Poisoned!
	<<set $poisonCounter -= 1>>
	<<set $ehp -= 5>>
\<<elseif $poisonCounter is 0>>
	<<set $estatus to "">>
	<<set $poisonCounter to 4>>
	<<set $aflicted to false>>
\<</if>>
\<<if $estatus is "$confusion">>
	$ename is Confused!
	<<set $confusionCounter -= 1>>
	<<set $ehp -= $eatk>>
\<<elseif $confusionCounter is 0>>
	<<set $estatus to "">>
	<<set $confusionCounter to 4>>
	<<set $aflicted to false>>
\<</if>>
\<<if $estatus is "$gravity">>
	$ename is under the effects of Intense Gravity!
	<<set $gravityCounter -= 1>>
	<<set $edex to 0>>
\<<elseif $gravityCounter is 0>>
	<<set $estatus to "">>
	<<set $gravityCounter to 3>>
	<<set $aflicted to false>>
	\<<if $ename is "Slime">>
		<<set $edex to 13>>
	\<<elseif $ename is "Flauna">>
	 	<<set $edex to 20>>
	\<<elseif $ename is "Wolf Pack">>
		<<set $edex to 18>>
	\<<elseif $ename is "Minotaur">>
		<<set $edex to 18>>
	\<<elseif $ename is "Centaur">>
		<<set $edex to 20>>
	\<<elseif $ename is "Amazon">>
		<<set $edex to 25>>
	\<<elseif $ename is "Alraune">>
		<<set $edex to 10>>
	\<<elseif $ename is "Mandrake">>
		<<set $edex to 15>>
	\<<elseif $ename is "Bramble">>
		<<set $edex to 20>>
	\<<elseif $ename is "Bumakui">>
		<<set $edex to 26>>
	\<<elseif $ename is "Ja'halla">>
		<<set $edex to 28>>
	\<</if>>
\<</if>>

The problem with that is that you can only have one $estatus value at a time. If you were, for example, burning, then it might be to your advantage to poison yourself, so you’re no longer burning and you’re now taking less damage.

(Also, if all of that code is together like that, then the status effects will never wear off because you’re resetting the counter each time.)

With my code you can set the countdown to whatever you want, you can stack multiple status effects, you’re not keeping track of counters that you don’t need, and it’s all set to work with each creature, so you don’t have to copy all of those values back and forth for each loop through all of the creatures.

However, if you only need to track status effects for one person and they won’t ever stack, then that’s not an issue for you, though I would still recommend not storing data which you don’t actually need. The more data you keep, the more bloated your game history gets, which means slower passage transitions, saves, and loads.