I’m needing help with code for fight scenes.
*if (strength > 99)
You win!
*else
You die.
*ending
In all seriousness you need to be about two hundred and fifty quadrillion times more specific in order to receive any useful advice on this.
Ok understood. Still new to this stuff haha
How would code look for a battle between 150 medieval soldiers vs 75 medieval soldiers. How do you figure how many people die or are wounded each round of fighting. That sort of thing. Does this help?
Not really!
If you don’t really give a shit about combat and it’s just numbers to you, why make it complicated?
*if (soldiers > enemy_soldiers)
*set soldiers (soldiers - enemy_soldiers)
You win. You have ${soldiers} guys remaining!
*goto war_crime_trial
*else
*set soldiers 0
You lose. All your guys are dead.
*ending
Or, you could do no fight scene calculations whatsoever and just run the scene narratively. Give the player choices on how to handle individual events and mini-scenes within the battle. For each one, you can increment the battle_success meter by 1, and they only win if they successfully make the right choice 6 or more out of 10 times.
Or you could really gamify it with a turn-based battle system. My turn-based battle system, zoomed out, is over 700 lines and looks like this:
The very first thing you need to answer is what do you want this to feel like for the player? What is your intention? Nothing of what you’ve written tells me anything about what you actually want.
My fight scenes are built from moments. Failure ups the stakes. Success gets the MC closer to their goal. I tend to have concrete things that can be lost or harmed. Like someone the MC cares about almost dying. Etc. Stats come into play, but is basically just narrative.
(Though I do have a social conflict over cards that is turn by turn and can be lost.)
My point is to affirm the above post: you have decide on the overall vibe and desired player experience.
you can Google something like
ttrpg light rules for army combat
or some such. Once you have a starting point, you can think about codifying the rules of combat.
If you are not sure how your battle system will look like in game, you might want to play a few choicescript games first and to come up with some ideas on how your battle system will work, before we give you code suggestions.
For a 150 vs 75 soldier battle system, there are plenty of ways to do it, even before getting into ‘how to code this?’. Do you want to have a single calculation determining the outcome of the battle? Or do you want to be a commander managing the battle over multiple turns, deciding when to charge or retreat? As the writer, you need to figure out what the battle looks like first before we can even advise you on code.
If you’re on a budget, I recommend taking a look at Swamp Castle, The Great Tournament and Life of a Mercenary for ideas on how a battle system could work. These are free. If you’re willing to pay, you can take a look at War for the West, Daria: A Kingdom Simulator, An Unexpectedly Green Journey or my game, Dragon of Steelthorne, for ideas. If you’re unsure how your battle system will look like, playing other games and seeing how other writers did it is a good starting point.
Ok I have pretty much all those games and I love the battle systems in them but since new to all this I didn’t want to get in trouble for using a similar combat system.
Ok thank you for that information
I don’t think you’ll get in trouble for doing something similar to anyone of the great works here.
It’s doing the exact same that would even start to get you in trouble, but even then it’s unlikely that anyone would mind. They’re good games for a reason. There’s HP in almost every game(Not CoG, but also a lot here too.) because it works and everyone can understand it.
Like everyone else has said, you need to know what you want the fight to be, or maybe the why. Is every single enemy supposed to die? Then you need something where you can kill them all. Are you doing the killing, or asking it? Decide whether you need a fight-to-fight combat system, or a command like event.
First you have to ask questions, then you answer them. Only then can we actually help you code what you want, when you know what you want.
Ok thanks for the feedback it helps a lot I’ll keep working on it!


