Twine Version: 2.3.16
Story Format: 2.36.1
I have built several things already into my game, such as time/date and using it to set events (https://intfiction.org/t/using-time-and-date-to-set-events), managing stats so they don’t exceed a maximum or fall below a minimum (https://intfiction.org/t/minimum-and-maximum-stats-settings), assigning a name to stats (https://intfiction.org/t/giving-stats-a-name-as-well-as-a-value), adding a passage header only to specified passages (https://intfiction.org/t/passageheader-in-sugarcube) and so forth.
But now I want to implement a combat system, hopefully without having to change any of these things.
In my StoryInit, for the main character, I have (among others)
<<set $Strength to 50>>
<<set $Strength_max to 200>>
<<set $Strength_min to 0>>
with the equivalent stats for Health, Stamina, Speed, and Melee. Plus I have this:
/* CHARACTERS */
<<character "you" "$name" "img/people/you/' + $Gender + ' avatar.png">>
/* OLEG */
<<character "oleg" "$Oleg" "img/people/military/oleg/oleg_avatar.png.png">>
<<set $olegStrength to 75>>
<<set $olegSpeed to 30>>
<<set $olegMelee to 4>>
<<set $olegHP to 150>>
<<set $olegHP_max to 200>>
<<set $olegHP_min to 0>>
In widgets, I have this:
<<widget "strength_change">>
<<set $Strength to $Strength += $args[0]>>
<<if $Strength gte $Strength_max>><<set $Strength to $Strength_max>>
<<elseif $Strength lte $Strength_min>><<set $Strength to $Strength_min>>
<<endif>>
<</widget>>
including one for each of the stats set up in the previous code. And this for the character Oleg:
<<widget "olegHP_change">>
<<set $olegHP to $olegHP += $args[0]>>
<<if $olegHP gte $olegHP_max>><<set $olegHP to $olegHP_max>>
<<elseif $olegHP lte $olegHP_min>><<set $olegHP to $olegHP_min>>
<<endif>>
<</widget>>
Oleg is a character that I want to use to train my main character. In a real fight, if health goes to 0 death occurs, but in training with Oleg, 0 simply means defeat, but with whatever bonus was gotten from the training.
I want different training to increase a different stat: Strengtth, Speed or Stamina, plus I would like to have different types of training: Unarmed, Knife, Sword etc.
Plus, I want to have training for Attack and also for Defence.
I want the training to look exactly like real combat.
I want all of this, so that in a fight, I can use some formula to establish the strength, speed, stamina and health (HP) of my character versus the strength, speed, stamina and health (HP) of the opponent, also taking into account what weapon is being used, and whether they are attacking or defending. (I have not yet implemented an inventory system to my liking, nor do I yet have the relative strengths of different weapons.)
I hope to have a list of options during the fight like this (maybe even more options):
<<button "<<scicon caret-right>> Fight">><<stat_change -10>><<goto "Test Combat">><</button>><br>
<<button "<<scicon caret-right>> Talk">><<stat_change -10>><<goto "Test Combat">><</button>><br>
<<button "<<scicon caret-right>> Flee">><<stat_change -10>><<goto "Test Combat">><</button>><br>
<<button "<<scicon caret-right>> Bribe">><<stat_change -10>><<goto "Test Combat">><</button>><br>
<<button "<<scicon caret-right>> Beg">><<stat_change -10>><<goto "Test Combat">><</button>><br>
<<button "<<scicon caret-right>> Surrender">><<stat_change -10>><<goto "Test Combat">><</button>><br>
I have just left the possible changes to stats as stat_change to try and keep this post as small as possible. It links back to itself (Test Combat) only for testing purposes. For the real combat, it will be whatever passage I need to create for it.
I did copy this from a combat post, but it doesn’t work for me. I changed the names, but that was all.
<<set _combined_melee to $oleg_melee + $Melee>>
<<set _round_result to random(1,_combined_melee)>>
<<if _round_result lte $Melee>>You successfully swing your sword through Oleg's defences.<<olegHP_change -5>><<melee_change +1>><br>
<<else>>Oleg wields his mortal hammer too powerfully for you to stop it. You're hit, you're bruised, and you start to regret to have ever left your comfortable house.<<health_change -3>><<melee_change +1>><</if>>
I get this: Error: << set>>: bad evaluation: random max parameter must be an integer
That is beyond my comprehension at this stage. I’ve messed up somewhere, but don’t know where or what.
Possibly I am trying to reinvent the wheel here, but some combat systems I did find confused me, and my current coding skills are not up to that job. Doing it the way I have outlined above at least makes some sort of sense to me, even if it isn’t elegant or concise.
Any and all assistance is welcome, even if it is only on some elements of this monster.