How to create code for a battle scene?

Ok … this one is probably gonna have a complex answer that’ll be tedious to code :sweat_smile:, but what kind of commands and setup can be used to create a battle scene? I’m making a game that has fighting parts like in Hero or Villain: Genesis, where you have a choice of attacks to make, and there are variables for damage, defense, and evasion. So some attacks hit, some will do more damage, some you will evade and some won’t even phase you. But I don’t know what kinda commands can be used to truly achieve this. I’ve seen it done so I’m sure its possible, but any suggestion how? I don’t -think- rand can be used for it, since going to the stat page and going back will change it, so players would be able to cheat the results of their attacks. But I want/hope for some element of random value to this. Like you have a chance of evading an attack, but it’d rely on your evasion stat and even if its very high you might still get hit. Any ideas much appreciated.

2 Likes

There is nothing wrong with the stat page method… but if you want to block it off, why not roll the dice a page before the player sees the results?

2 Likes

It really depends on how complex you want it to be. If enemies are gonna have items, skills etc etc it will be more complicated to implement. I’m making one myself and I never finished it due to lazyness and harder work because of CS limitations.

To fix the rand bug you could just randomize the variable before the attack actually occurs, as was suggested by @sljzz.

Mine was workable until I added AP points which I haven’t finished yet and haven’t worked on it for a while, but I can send it to you if you want to take a look.

I guess the page before thing will work. Now I just need to figure out the equations and do a whole lot of balancing … ah, the joys of making a game.

1 Like

Hmmm. Are you sure there is nothing already ready to copy and paste lost here in the forums?

Anyways what are the rules?

Initiative is speed based or will be luck based?

Does strength affect damage or it will be based in firepower?

Dash/run? Block? There will be armor and action points?

Can you offer surrendering to your enemies? Or is a fight to the end.

There will be rewards to the winner?

Regarding the stat page exploit sljzz is right. Just make sure all are on the previous page.

What I do in my game is something like:

You swing your sword like a boss.
*rand WS_roll 1 100
*rand dam_roll 1 10

*page_break

*if WS_roll <= WS
    *set dam ((dam_roll + damage_modifiers) - armor_modifies)
    *if dam < 0
        *set dam 0
    *set enemy_wounds - dam
    *if enemy_wounds < 0
        *set enemy_wounds 0
    You hit.
    
    /Enemy wounds: ${enemy_wounds}/18
    *if enemy_wounds <= 0
        *goto victory_scene
    *else
        *goto round_2
*else
    you miss. scrub.
    *goto round_2
2 Likes

In answering Nahim’s questions, well nothing I found when I looked, probably something just buried deep in its recesses that’d help. Either way, rules are pretty simplistic since this is my first project. No initiative, turns are set, and it depends on the attack. For instance, higher Wisdom would help with magical attacks, while Strength would be used for physical attacks. The chance of you hitting or getting hit by your opponent depends on two stats, Combat and Speed. It is a fight to the end, and in some cases there shall be rewards.

As for what Alice said … yeah that looks way cleaner than what I was doing XD truth be told I’ll probably overall my whole current combat system later and adopt it with something like that. At this time I’m just more concerned that a combat system works. Thanks for the example!

1 Like