Parry and riposte?

This is probably going to be a long one.

My project is based on SAS - Sapphire Action System. However, it uses a custom system made by me that modify some aspects of gameplay. For instance, the player has a stamina bar and is only able to attack if their stamina is positive. There's also a custom dodging and running system, and some "ai" attack patterns for the enemies, among other things.
One of the core systems that affect gameplay is the parrying system. Where the player presses a button and, if an enemy hits them in a small timeframe, they negate incoming damage and, for a tiny timeframe, is able to counterattack for critical damage.
It works like this (click to enlarge):
1593107816106.png

This is a parallel process common event that starts running at the start of the game. "DAMAGE condition" is a switch that activates the "graphical-hurt" state system and is turned off to make sure the player is standing up when parrying. "char_effect" has to do with a gfx script for characters. The event checks if the player has received any damage during the "parry" animation, if yes, they'll recover the lost hp, then enter the "parrying" state where they'll be invulnerable and having 120% of the regular attack stat.
Then, it will turn on a switch that activates another common event, which will last 12 frames (the duration of the opening to riposte):
1593107401394.png

This common event is a parallel process that checks if the player has pressed the attack button, then if the player is currently able to attack (i.e not in a "pain" animation, or have enough stamina), and if he's buffed with the "parrying" state (which grants them additional damage). Then it modifies a variable to later make sure the riposte was executed and some SEs play/ the screen shakes to indicate that the player has succesfully executed a riposte. Then the event is deactivated. You can ignore the first condition, i recently removed it and it makes no difference.
After that's done, we continue to the first event:
1593107904473.png

The first thing it does is checking if the player has actually riposted, by evaluating the number of the variable that is defined before the opening and updated if the player ripostes during the opening. If yes, the game waits a bit before removing the buff (to make sure the buff lasts just enough to fit with the player's attack speed). If no, it just removes it with no waiting.
What happens next is the player receives a mana point and recovers his lost health. Then the game deactivates the switches that indicate the player being in a parrying state and things return to normal.

THE ISSUE:

For some reason, this doesn't work all the time. As you can check in the timestamps in the video below... and please try to not mind the annoying bell sound, it's used for debugging and is supposed to be like that so it's very obvious when the game understands that a riposte is executed - that way i can more easily identify when something goes wrong with the system:



You can see the bug at around 00:17 where it hits for regular damage (7) instead of critical damage (27), 00:24 where it hits for 7 then 0 damage (the attack doesn't connect), at around 00:57, 00:59, 01:21 and 01:24 where the player deals 7 damage when they should deal 27.

I'm trying hard to make sure the player meets all criteria to riposte successfully. I only very recently added a lot of the conditions you see that "guarantee" the player will be able to deal the proper amount of damage. But somehow, it is not 100% consistent. And i don't like the idea of having an inconsistent mechanic in the game (even if i come up with an excuse saying something like "parrying only works 90% of the time because it's an op mechanic"). There's also the issue of the game identifying the criteria being met, playing the SEs and shaking the camera as if the riposte was executed, but the attack simply isn't executed - though this is more rare.

I'd deeply appreciate any directions, suggestions and any help of any kind. I'm no coder but i was also thinking if this is solvable via script, i could get some directions and start working on a workaround - maybe even improve the system.

I'd appreciate any help.
So, I think the issue is at 0:18 in the video, right? Like when Heiwa is taking the damage that goes from what looks like 1.5 little health segments to 2.5 little health segments, while they are right in the center of the island? She flashes yellow, which I believe means parry was successfully executed. Then, she takes damage while yellow, then she strikes back and the screen doesn't flash yellow - meaning for some reason the Parry didn't happen. Right?

Looking at the code, I feel like you'd need one of two things to have happened:
1) Someone stopped the event from executing (I do not think this is easy without fairly advanced scripting or the event itself calling Exit Event or whatevz)
2) The game thinks that Heiwa's health didn't change.

For #1, maybe if you pasted in a shot of the entire event something would become clear? But... presuming it's just the two shots you pasted stitched together... not so much.

For #2, all I can think of is that you're using an animation to show when the effect is active. Animations are not particularly well time synced (for frame debugging), in my experience. If it were me, I'd make an image in your pictures directory that's like a little red box. Show that picture in (like) the bottom left while she's parrying and hide when she's done. That should make it more or less frame accurate and unambiguous when she's in the parry state.

Another way I often do frame debugging is to print a string that's not in a message box. The essential code I use is below. But, the point is that you can then write a script line like Graphics.setDebugString("foo") right in your event. So, every time you get to the condition branch

Variable[0008:/ P HP NOW /] < Variable [0007:/ P HP THEN /]

Just before the conditional, you could just write out the two values. In this case, that script would look like:

Graphics.setDebugString("HP Now: #{$game_variables[8]}, HP Then: #{$game_variables[7]}")

I think... just wrote that here, so fix obvious errors if I fat fingered syntax 😉 But, the point being, every time you get to the conditional, you'll get a print out (which won't stop battle) that shows you precisely what the event thought the state was. I've found that incredibly helpful for debugging real time battles.

Here's the code for setDebugString. You can just paste it into a new script 'file' anywhere below the in-box RPG maker stuff. If none of this helps, maybe can you send me the game? I could attempt to debug it directly.

Ruby:
module Graphics
  @@debugString = nil

  def self.setDebugString(str)
    @@debugString = str
  end

  def self.getDebugString
    return @@debugString
  end

  def self.getDebugText
    return @@debugString
  end

  class << self
    alias debug_str_update update
    def update
      debug_str_update

      if (@lastDisplayedString != Graphics.getDebugString())
        @stringSprite.dispose if @stringSprite != nil
        @stringSprite = Sprite.new
        @stringSprite.bitmap = Bitmap.new(Graphics.width, 18)
        @stringSprite.bitmap.font.name = "Arial"
        @stringSprite.bitmap.font.size = 16
        @stringSprite.bitmap.font.color.set(255, 255, 255)
        @stringSprite.bitmap.draw_text(0, 0, Graphics.width, 24, Graphics.getDebugString())
        @stringSprite.x = 14
        @stringSprite.y = Graphics.height - @stringSprite.height - 10
        @stringSprite.z = 5000
        @lastDisplayedString = Graphics.getDebugString()
      end

      if (@stringSprite != nil && [email protected]?)
        @stringSprite.update
      end
    end
  end

end
Thank you very much!
So because this thread was revived, i started messing around with the issue and a simple addition made an incredible difference to the general feel of the game. Turns out the main issue was that the player was running out of stamina and the game didn't processed it well enough/maybe some desync issue? Nevertheless, i was able to partially solve the problem simply by adding a small amount of stamina to the player right after they succesfully parry an attack. The end result goes like this:


Notice at 00:39, 00:55, 01:00 that a problem occurs: the player doesn't attack but the game understands that a riposte was executed. I still don't know why that happens. And i'm not minding it very much since i solved the greater part of the problem, this happens maybe once in like 50 parries.
If none of this helps, maybe can you send me the game? I could attempt to debug it directly.

Do you still want that even though it's kind of a minor problem now? I would happily upload it for you.
Hurray 🙂 I am really glad that you managed to solve it! I'm happy to try and help with the attack issue, although I think I'd need more information on that since I believe the stuff you pasted above is focused on executing parry. If you want to send me a copy, that's awesome, or you can just send me the details as in the above post.

What I can say is that the stamina bar seems to be broken right around the issue at :39. Like, normally, there's a white plus on the bar, and when I think the attack is failing to execute, that white plus has vanished. Maybe that's indicative that something around the stamina system is borked, which is what's causing the attack not to execute?

As a design issue for your consideration: I originally had a stamina and mana system in my game, but eventually removed them because they added complexity that I didn't strictly need to build the experience I needed. They also created problems where users would think they should attack, but it wouldn't work b/c they were out of stamina or mana. In my case, I was able to replicate all the 'cost of attacks' mechanics I wanted with simple cooldowns, which turned out to be easier for users to wrap their heads around. There may be specifics in your case that preclude this, but at some point you may start running into situations where players 'perceive' a feature (i.e. stamina being gone) as a bug (i.e. the attack system is broken). So, I would advise you to be really ruthless about which player attack systems you absolutely need to achieve your gameplay.

Another thing I specifically noticed about cooldown UI in my game: having it present _on_ the character sprite (or near them) made a HUGE difference to how well players could read game state. My game isn't nearly as action oriented as yours, but even in mine, people's eyes are glued to the character. Like so much that most players wouldn't even see stuff I was rendering in the HUD up top (like those cooldown bars near the char portrait). It was more work to get the cooldowns to render on the character, but when I did it, it essentially eliminated a whole class of user frustration around 'why aren't my attacks working'. So, food for thought as you design your UI 🙂
Hurray 🙂 I am really glad that you managed to solve it! I'm happy to try and help with the attack issue, although I think I'd need more information on that since I believe the stuff you pasted above is focused on executing parry. If you want to send me a copy, that's awesome, or you can just send me the details as in the above post.

What I can say is that the stamina bar seems to be broken right around the issue at :39. Like, normally, there's a white plus on the bar, and when I think the attack is failing to execute, that white plus has vanished. Maybe that's indicative that something around the stamina system is borked, which is what's causing the attack not to execute?

After a lot of work and spending the whole day playtesting and debugging it, i managed to fix 99% of the issue. No need to send it anymore. Turns out the culprit wasn't the stamina bar, it was how the game was processing the button presses, sometimes the player would keep holding the key after attacking and this "holding" state made the game think the player was actually pressing the button to attack again. I managed to solve it with a quick tutorial i saw on youtube regarding button press-and-release.

As a design issue for your consideration: I originally had a stamina and mana system in my game, but eventually removed them because they added complexity that I didn't strictly need to build the experience I needed. They also created problems where users would think they should attack, but it wouldn't work b/c they were out of stamina or mana. In my case, I was able to replicate all the 'cost of attacks' mechanics I wanted with simple cooldowns, which turned out to be easier for users to wrap their heads around. There may be specifics in your case that preclude this, but at some point you may start running into situations where players 'perceive' a feature (i.e. stamina being gone) as a bug (i.e. the attack system is broken). So, I would advise you to be really ruthless about which player attack systems you absolutely need to achieve your gameplay.

This statement regarding player perception is very much true. Originally, i didn't knew how to deactivate the player ability of attacking, so what i did was a small system where, if the stamina was below minimum, the player would deal 0 damage. In playtesting, this resulted in a confusing mash of the attack button while the stamina resided at minimum and no damage was being dealt.
Then, after tinkering with the ABS script a bit i figured out a way to integrate a switch condition to the attack action, the player then would simply be unable to attack when at low stamina. I didn't playtest it, but i know this is already present in the last version of the demo i put out (which is already outdated).
Then... because of your comment, i pieced together the contents of your post and the experience i had with playtesting and came to the conclusion i don't need the attacks to cost stamina, after all. Removing the stamina requirement to attack meant the player DPS got considerably higher. This coupled with a tweak in enemy AI cutting their "waiting times" after attacks in half made the combat much more intense and fast paced. This led to the parry being a bit too overpowered, since it used to need quite the high amount of stamina - now it can be used almost always. Then, to encourage players to move around and actually use the other combat and movement mechanics, i made a system where the player gain "points" by dodging, attacking while dashing, backstepping and charging: after a certain amount of points is acquired, the player receives 1 point of mana, which they can use to shoot a spell that's (against most enemies) high damage. This is the end result (as of now):



Thank you very much! Because of your suggestion i was able to drastically improve my game.

Another thing I specifically noticed about cooldown UI in my game: having it present _on_ the character sprite (or near them) made a HUGE difference to how well players could read game state. My game isn't nearly as action oriented as yours, but even in mine, people's eyes are glued to the character. Like so much that most players wouldn't even see stuff I was rendering in the HUD up top (like those cooldown bars near the char portrait). It was more work to get the cooldowns to render on the character, but when I did it, it essentially eliminated a whole class of user frustration around 'why aren't my attacks working'. So, food for thought as you design your UI 🙂

Yeah, the next thing i'll probably start focusing on is a way to indicate near the player character that they currently have mana to spend.

Thanks a lot for your help. Really.
Input processing is a pain in the butt; I had a bunch of problems around that in mine too. I think I'm using a modified version of Zale's Keyboard Manager to do my stuff, although most of the true input handling routines are now custom code I wrote. Zale's essentially provides an abstraction for which buttons map to which keys, so I could remap things and\or support controller (with Wolfpad, which I'd also recommend) fairly easily.

I am really glad that the stamina comments helped. I think what you're describing does sound like it will work a lot better. Action predictability is one of the most critical components of a solid feeling game, and it sounds like what you've come up with will be significantly crisper on that axis. I also like the notion of building up power points. Giving players moments when they 'get' something from the game can be a fantastic way to enhance fun (loot boxes being the manipulative version, but the concept isn't manipulative; it's just how humans work). And, adding variance to a player's power at any given time is nice. Big hits that you build up to make different parts of the battle feel different, rather than just repeating the same core attack loop over and over. That meta-loop can give the system a lot more staying power, and can be a great place to add in mechanical embellishments without messing with the super tight, sub second tuning your core battle loop will require 🙂

For on-player indicators: you have a fairly cool animation system for your character. I didn't have the art (or tech 😉 for that, so my chars are pretty static (which is why I just used little progress bars :} ). But, if you can use the actual character (rather than UI overlays) to indicate stuff, that is way cooler. As with the above, I think the main goal of that UX is that it's very obvious to the player when they can Do The Thing. So, if mana builds up to 'full' then you can cast any spell, you could just (say) make the character glow. But, if spell costs are, like, 20% of your mana pool, then you probably want essentially two indicators. One tells the player 'you can cast a spell now' and the other gives them an idea of their total remaining mana pool (i.e. you have 3 spells left before you're empty). The latter might even be fine in the HUD, as long as the 'can I cast a spell now' one is in the player's locus of attention (which is gonna be either the character or the enemy 99% of the time).

Anyway, I'm really glad you smashed through more of your problems. I love the part where you get through the last few design issues in a system and can really experience it as you intended it. It feels so awesome! 🙂

Original thread: https://forums.rpgmakerweb.com/threads/parry-and-riposte.123293/