I’m trying to figure out how to work this blocking portion of my system, so when a player parries it’ll cancel out the move for a split second from the enemy, but would I do this all in one module or not? I’m still fairly new to Object Oriented Programming, but I’m getting the basics down, if someone can help that’d be great
local Combat = {}
Combat.__index = Combat
local Animations = game.ReplicatedStorage.Contents.Animations
local Fighting
function Combat.new(player, settings : {})
local self = setmetatable({}, Combat)
self.Player = player
self.Character = player.Character or player.CharacterAdded:Wait()
self.Damage = settings.Damage
self.CooldownTable = {}
self.Cooldown = settings.Cooldown
self.Move = nil
self.isDodging = false
self.isBlocking = false
self.isParrying = false
self.LastMove = nil
self.isBlocked = false
self.isParryed = false
self.isDodged = false
self.HitCount = 0
return self
end
function Combat:Move(Count)
if not self.isBlocked or self.isParryed or self.isDodged then
print("Punching or kicking...")
end
end
function Combat:Activate()
if not self.CooldownTable[self.Move] then
self:SetCooldown()
Fighting = task.delay(1, self:Move(self.HitCount))
end
end
function Combat:Block()
if not self.isBlocking then
self.isBlocking = true
self.Move = "Block"
if Fighting then
task.cancel(Fighting)
end
end
end
Here’s a visual of my system of what I’m asking if it helps, since It’s hard to explain:
Enemy Punching > Victim Parries > Enemy is knocked out of punch state
local module = {…}
module.__index = module
— define a class, it makes the process easier.
function module.new(Properties)
local self = setmetatable({}, module)
— …
return self
end
—- rest of your code…
return module
local Combat = {}
Combat.__index = Combat
local Animations = game.ReplicatedStorage.Contents.Animations
local Fighting
function Combat.new(player, settings : {})
local self = setmetatable({}, Combat)
self.Player = player
self.Character = player.Character or player.CharacterAdded:Wait()
self.Damage = settings.Damage
self.CooldownTable = {}
self.Cooldown = settings.Cooldown
self.Move = nil
self.isDodging = false
self.isBlocking = false
self.isParrying = false
self.LastMove = nil
self.isBlocked = false
self.isParryed = false
self.isDodged = false
self.HitCount = 0
return self
end
function Combat:SetCooldown()
if self.CooldownTable[self.Move]== nil then
self.CooldownTable[self.Move] = true
task.delay(self.Cooldown, function()
self.CooldownTable[self.Move] = nil
end)
end
end
function Combat:Move(Count)
if not self.isBlocked or self.isParryed or self.isDodged then
print("Punching or kicking...")
end
end
function Combat:Activate()
if not self.CooldownTable[self.Move] then
self:SetCooldown()
Fighting = task.delay(1, self:Move(self.HitCount))
end
end
function Combat:Block()
if not self.isBlocking then
self.isBlocking = true
self.Move = "Block"
if Fighting then
task.cancel(Fighting)
end
end
end
function Combat:Parry()
if not self.isParrying then
self.isParrying = true
self.Move = "Parry"
if Fighting then
task.cancel(Fighting)
end
end
end
function Combat:Dodging()
if not self.isDodging then
self.isDodging = true
self.Move = "Dodging"
end
end
return Combat
Block is more passive protecting the player from a damaging hit while leaving the enemy unaffected while parry stuns the enemy for a second and gives the player a opportunity to fight back
So maybe would I just make a function specifically if this was an enemy, like my block function, instead of block it would be isBlocked and write the code catering to the enemy? if that makes sense, it makes sense imo thinking about it and sounds like it’d be the best way to do it, I think I was overcomplicating it lol