Sugarcube basic combat system

There are a lot of ways to do this; here’s something simple, where we will have health points and magic points.

In a passage titled PassageFooter you will want to put the displays that show up on every page


<hr>
<<print $playerHP>>/<<print $playerHPmax>> HP
<<print $playerMP>>/<<print $playerMPmax>> MP

In a passage titled StoryInit, create some defaults


<<set $playerHPmax to 50>>
<<set $playerHP to $playerHPmax>>
<<set $playerMPmax to 30>>
<<print $playerMP to $playerMPmax>>

<<set $firstenemyHP to 60>>
<<set $secondenemyHP to 60>>

Now in your story, you can create monsters and items. Basically, write your text, then in a link tell the game what it should do. Put this in your Start passage.

You see a monster, it has <<print $firstenemyHP>> HP, <<link "attack">>

<<set $playerMP -= 2>>
<<set $firstenemyHP -= 2>>
<<set $firstenemyHP -= 10>>

<<if $firstenemyHP lte 0>> <<goto "win">>
<<else>>
<<set _currentp to passage()>>
<<goto _currentp>>
<<endif>>

<</link>> it.

Now create a passage called ‘win’ and enter your victory text

You've won

In this case it is impossible to lose, but hopefully that helps you get the idea. This part of the documentation is helpful for setting variables.

You can also import this twee source code into your game instead of copying each passage.
rpg-source.zip (486 Bytes)

1 Like