Sugarcube basic combat system

If you are requesting technical assistance with Twine, please specify:
Twine Version:2.3.14
Story Format: Sugarcube 2.34.1

Ok so I am new to this whole thing been using RPG maker for ages now, but I hate mapping more then I care to admit, so it normaly is pretty text heavy. So I decided to try out twine I came across some amazing twine based games but sadly I can’t seem to open them up and pick at them to help me understand basics of combat.

I found some great guides but for halow not sugar cube and since I am newb I tried to transfer the syntax over to work and yeah that is just not working. I sorted out basic varibles and stuff like that from youtube tutorials. Even how to add place holders on uibar to track HP, and what not there. But what I haven’t sorted out is how to actually use variable system to make a just bare bones combat system so I can get a feel for it.

Like I know there is a million ways to do it and I can spruce it up and make it look amazing. But I am the stage where I drawing straws on how to even sort out the basics I see I should have passages for each part, but that is far as I know. Not looking for advance just a basic idea I can evolve from as needed, because so far I keep googling and for sugar cube I just keep seeing “the sky is the limit, just start making it yourself build it backwards!” Its like um That requires me to know how to build its like handing a toddler a bunch of nails, and screwdriver, and some boards with a butter knife. Its like what I don’t know how to make anything out of this…

1 Like

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)

Welcome Robert.

First you can see many possibilities and examples of how to use them at https://www.motoslave.net/sugarcube/2/docs/.
For what it’s worth I think there’s four most important things to understand:

  • How to send the reader from a passage to another one.

  • How to manage variables

  • The <<if>> macro.

  • How to manage random results

The easiest way to send the reader to another passage is with a

[[Flavour text|Link to the next page]]

Example:

What do you want to do?
[[You charge head first to the big burly hobgoblin.|Fight the Hobgoblin]]
[[Better to bribe your way out of this mess.|Bribe the Hobgoblin]]

Note that Twine will automatically create the Fight the Hobgoblin and Bribe the Hobgoblin passages.
Of course there are more about links between passages, but these are the basics.

The second important thing is variables. They store information. Numeric variables can easily be modified. Variables are declared with a <<set>> macro. https://www.motoslave.net/sugarcube/2/docs/#macros-macro-set

Examples:

<<set $Character_melee to 4>>
<<set $Character_HP to -=5>>

The first line creates (or overwrites) the variable $Character_melee and gives it the value 4. The second one substract five from current HP total. Variables can be caught at any times after they are set.
It is possible to set a temporary variables, temporary variables starts with an ‘_’, example _HPloss is a temporary variable, while $HPloss isn’t (it’s called a story variable, as story variables follow the reader through the story, temporary disappear as soon as the passage is over).

The <<if>> macro https://www.motoslave.net/sugarcube/2/docs/#macros-macro-if is probably the most powerful tool of all. It allows to determine effects based on variables and/or random results. The macro needs a logical test and a <</if>> closure. It allows for alternate possibilities with <<elseif>>, and <<else>>, the former calls for another logical test, the later happens if no logical test returns a true.

<<if $Character_sexe is "female">>The blond paladin looks at you as a defenseless creature it's he's duty to keep out of harm. Though you can't shake the impression you could drown yourself in his hazel eyes you fell safer than a few minutes ago.
<<else>>The paladin smiles at you. Your plea seems to have a considerable appeal to him. Soon he draws his sword, points it to the sky, and vows to help you fulfill your destiny for as long as you need his help.<</if>>

How to use random? There’s two main ways to use random. If all outcomes should have the same chance to happen you’ll like to use either() https://www.motoslave.net/sugarcube/2/docs/#functions-function-either.

<<set _round_result to either("Win","Loss")>>
<<if _round_result is "Win">>You thrust your sword deep in the flesh of the Hobgoblin.<<set $Hobgoblin_HP -=5>>
<<else>>The Hobgoblin 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 leaved your comfortable house.<<set $Character_HP -=3>>
<</if>>

However, you might sometimes want to have outcomes more likely than others. Then you’ll probably like the random() fonction SugarCube v2 Documentation.
Example;

<<set _combined_melee to $Hobgoblin_melee + $Character_melee>>
<<set _round_result to random(1,_combined_melee)>>
<<if _round_result lte $Character_melee>>You thrust your sword deep in the flesh of the Hobgoblin.<<set $Hobgoblin_HP -=5>>
<<else>>The Hobgoblin 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 lived your comfortable house.<<set $Character_HP -=3>><</if>>

In this second case, the more skilled the character, the more chances he’ll have to hit the Hobgoblin.

Honestly, there’s the basics. When you’re comfortable with these you can play with other things.

2 Likes

Sorry been super busy with real life stuff, had to deep clean an old couch, a closet, and a few other things. And got little distracted rendering a few images to use for twine project.

Man thing that confuses me is a combat log, Like I can set up what happens if you hit attack, run away etc. But having it say “you hit for 3 damage, enemy attack misses” Like that is part that confuses me the most Having a static battle scene with variables like hp and what not only issue is making it look ok, and that is something I can work on. Its whole how do I make it so its mostly static like the passage for the enemy is there, with the attack, run etc options, but it updates after each combat turn with the new info and lets player know if they miss or hit, same with enemy.

Sorry I wasn’t more clear I felt like amazing after doing a variable tutorial and doing hp stat on sugarcube uibar, as well as char name, was like yeah I am on a roll, then I just got super confused on how to put all the things I just learned into a combat system.

Oh and still busy at home right now trying to skim through, but mostly respond I got some more super belated spring cleaning to do. Plus start a slow cook meal still thawing meat for that bit. But thank you for all the responses. I was kind of scared I hit a dead end why I got carried away with side stuff like rendering my own images with daz. Use to do that for RPGM for cg scenes, but all the good twine games i played used googled images some not bad, just felt like it would seem more fluid if I just rendered each image myself, way more time consuming but since I lack pretty skills with twine it sure does help :stuck_out_tongue:

Ok so yeah this was what I was looking for more or less. Now I just got sort out how to have enemy have a turn… And then make it a seperate passag for both so I can just call it for each enemy type, and then tweak it latter with extra varibles

For the enemy turn put its actions in this area

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

For example, if you want it to take away 10 of your hp

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

Both your actions and the enemy actions happen all at once, as soon as you click, so there are technically no “turns.” Still, the player should notice their hp being drained on each click.

You can also add a status bar section that explains the turn. In the ??? area we used above, put

<<set $msg to "You did something; the enemy did something">>

Then in PassageFooter put
<br> <<if $msg neq null>><<print $msg>><<endif>> <<forget $msg>>

Basically what we are doing here is adding a message below the hp bar, which will print after each link click, but refresh immediately after it is printed

1 Like

Since this kind of goes with this topic. You got any pointers on tweaking this just a touch. I found an inventory system I am setting up. I am got a few weapon and armor ideas, was gonna try for a basic wear this armor get +1 added to hp when enemy attack happens so instead of 2 damage in your example it does 1. Same with attack was gonna add attack power to tools/weapons so using stone axe, gives you a bonus 2 to your damage.

Never done multiple variables in one line of code…

In that case, you can add a passage called axe. In that passage write something like “There is an axe here; it strengthens your attack power”

Then in your ??? area in combat add

<<if hasVisited("axe")>> <<set $enemyHP to -= 1>><<endif>>

(I have not tested that one, tweak it if necessary)

It is up to you to figure out the ordering in a logical way…for example, don’t put the armor at the end of the turn or your character could die before it protects him.

It is much easier to do permanent items that can be continually upgraded (as opposed to items that can be toggled)…that way you can just keep adding lines to the attack sequence.

Eventually you will want to start using widgets, which will save you from copying and pasting code for each enemy.

Nice I was gonna try somehting more complicated like if you equip axe your get a speacail variable for +1 damage. I mean could still do it, but I kind of like doing it per fight. As I do got some skele assets I never freaking use yet paid for the damn comercial license ages ago, I could use them and use this system instead where say stone club should get you the bonus damage for attacking a skelly.

1 Like