Parry System Pseudo Code Help

I’m trying to make a parry system for a combat game, I’m new to lua code and idk all the lil gimmicks and stuff it has, so I need help planning it out.

Here’s the basic pseudo code for what I’ve been trying to do:

when player1 presses E, if it connects to another player (player2),

  1. it gets player2’s name
  2. it invokes a remote function using the player2’s name, to check if that player is in the parry state (from a BoolValue in their character).
  3. then the remote function relays back that parry BoolValue to player1
  4. if that parry value is true, the parry part of the script runs (stuns player1, unable to attack, multiplies damage taken,etc)
  5. if no parry, then just damage the player

there has to be an easier way to do this, but i haven’t been able to find one

other problems:
player2 doesn’t know when their parry was successful
blocking needs to negate damage taken from attacker
player1 needs to take multiplied damage after a parry against him

2 Likes

Just make it run all the checks when the player is attacked, for instance:
A player is in the hitbox for an attack
you check their parrying boolvalue, then apply changes as neeccecary

if parrying then
-- initiate stun
-- this is unoptimal, but you can check for the next time the health is changed 
local currentHP = Humanoid.Health
Humanoid.HealthChanged:Once(function(newHealth)
    if newHealth < currentHP then
        -- They took damage! Make them take more damage based on the difference. (USE THE DIFF TO CALCULATE THE MULTIPLIER)
        local diff = currentHP - newHealth
        Humanoid:TakeDamage(diff)
    end
end
else
-- initiate damage
end

it’s all ran in one script and easy to manage
I don’t believe this is the most optimal method but itll work i guess :person_shrugging:

1 Like

Ehh, seems like a lotta steps tbh. I don’t even see the point of the RF as you are letting the client handle the parry logic. Now here’s my suggestion and for simplicity’s sake, I’ll also show the scope in which the code runs:

Client (Player 1)

  • Player 1 wants to attack Player 2
  • Player 1 clicks LMB (or whatever triggers melee hit) and that fires an RE to server (probably smth called Hit)

Client (Player 2)

  • As it turns out, Player 2 anticipates Player 1’s attack and presses E to parry, which fires another RE to server (called Parry)

Server

  • Server receives Player 2’s parry event first and after doing some sanity checks, sets ParryMap[Player 2] to be true (ParryMap’s a dictionary). It also starts a task.delay for x amount of seconds after which it sets the value to false.

  • Server then receives Player 1’s hit event checks if Player 1 is stunned or not by doing StunMap[Player 1] == true (another dictionary) and if it is false, it does the hotbox check (ClientCast is preferred) and assuming it hits Player 2, before dealing damage, it checks if ParryMap[Player 2] is true and if it is, it adds Player 1 to a StunMap and doesn’t deal damage.

5 Likes

this def sounds a lot more efficient, ill try this, thanks

Sure, any issues just reply here or DM me.

1 Like