I don’t think im using the right words to explain what I actually wan’t to know, All of the things you mention are already done.
I only process inputs and nothing else, a separate function sees these inputs and does whatever they are meant to do, You can see this here on the client and server
Client:
function Melee:ProcessCommand(command)
local playerRecord = ClientPlayerRecord:GetPlayerRecord(LocalPlayer)
if command.CTID and command.MAI then
local EquippedMelee = Melee.ParentClass.CToolRecords[command.CTID]
if command.MAI == Enums.MeleeData.Block then
EquippedMelee:Block()
elseif command.MAI == Enums.MeleeData.Unblock then
EquippedMelee:Unblock()
elseif command.MAI == Enums.MeleeData.Shove and command.SC then
if command.SC > playerRecord.Commands.SC then
EquippedMelee:Shove()
playerRecord.Commands.SC = command.SC
end
elseif command.MAI == Enums.MeleeData.Charge then
EquippedMelee:Charge()
elseif command.MAI == Enums.MeleeData.Hit and command.HC then
if command.HC > playerRecord.Commands.HC then
EquippedMelee:Hit()
playerRecord.Commands.HC = command.HC
end
end
end
end
Server:
function Melee:ProcessCommand(command,playerRecord,CTool)
-- Sanitize data
if command.MAI and CTool.IsEquipped == true then
if typeof(command.MAI) ~= "number" then
Firewall:Kick(playerRecord, Enums.FirewallKickType.InvalidDataType)
return
end
else
return
end
if command.MAI == Enums.MeleeData.Shove then
-- Sanitize data
if command.SC then
if typeof(command.SC) ~= "number" then
Firewall:Kick(playerRecord, Enums.FirewallKickType.InvalidDataType)
return
end
else
return
end
if command.SC > playerRecord.Commands.SC then
CTool:Shove()
playerRecord.Commands.SC = command.SC
end
elseif command.MAI == Enums.MeleeData.Hit then
-- Sanitize data
if command.HC then
if typeof(command.HC) ~= "number" then
Firewall:Kick(playerRecord, Enums.FirewallKickType.InvalidDataType)
return
end
else
return
end
if command.HC > playerRecord.Commands.HC then
CTool:Hit()
playerRecord.Commands.HC = command.HC
end
elseif command.MAI == Enums.MeleeData.Charge then
CTool:Charge()
elseif command.MAI == Enums.MeleeData.Block then
CTool:Block()
elseif command.MAI == Enums.MeleeData.Unblock then
CTool:Unblock()
end
end
I just use a counter to let the :ProcessCommand() function know when an user presses the same key again, so that way it doesnt thinks we are just holding it, since packets are sent every tick.
Also cooldowns are checked like you said from both sides:
Client:
This code just steps all cooldowns using delta time so they are actively simulated and can be rewinded or fowarded with no problem, same for the charge mechanic.
function Melee:Step(client,_deltaTime)
local playerRecord = ClientPlayerRecord:GetPlayerRecord(LocalPlayer)
local States = playerRecord.States
-- Step the charge state
if States.IsCharging == true then
-- step it according to equipped melee stats
local EquippedMelee = playerRecord.Inventory.Hand
if EquippedMelee then
local CalculatedCharge = States.Charge
local ChargeSpeed = EquippedMelee.MaxDamage / EquippedMelee.ChargeLength
CalculatedCharge += ChargeSpeed * _deltaTime
if CalculatedCharge >= EquippedMelee.MaxDamage then
States.Charge = EquippedMelee.MaxDamage
playerRecord.GUI.HUD.ChargeBarOutline.Charge.Size = UDim2.new(1,0,1,0)
else
States.Charge = CalculatedCharge
playerRecord.GUI.HUD.ChargeBarOutline.Charge.Size = UDim2.new((1/EquippedMelee.MaxDamage) * States.Charge,0,1,0)
end
end
else
States.Charge = 0
end
-- Step cooldowns
if States.SwingRecovery > 0 then
States.IsSwingRecovering = true
local CalculatedSwingRecovery = States.SwingRecovery
CalculatedSwingRecovery -= _deltaTime
if CalculatedSwingRecovery <= 0 then
States.SwingRecovery = 0
States.IsSwingRecovering = false
else
States.SwingRecovery = CalculatedSwingRecovery
end
end
if States.BlockRecovery > 0 then
States.IsBlockRecovering = true
local CalculatedBlockRecovery = States.BlockRecovery
CalculatedBlockRecovery -= _deltaTime
if CalculatedBlockRecovery <= 0 then
States.BlockRecovery = 0
States.IsBlockRecovering = false
else
States.BlockRecovery = CalculatedBlockRecovery
end
end
-- Step LMB charge delay thing
if playerRecord.Input.IsHoldingLMB == true then
local CalculatedLMBChargeDelay = playerRecord.Input.LMBChargeDelay
CalculatedLMBChargeDelay -= _deltaTime
if CalculatedLMBChargeDelay <= 0 then
playerRecord.Input.LMBChargeDelay = 0
ClientCommands:SetCommand("MAI",Enums.MeleeData.Charge)
else
playerRecord.Input.LMBChargeDelay = CalculatedLMBChargeDelay
end
else
playerRecord.Input.LMBChargeDelay = playerRecord.Input.LMBChargeDelayDuration
end
end
Server:
Same for server side as client side.
function Melee:Step(server, _deltaTime)
for UserId,playerRecord in pairs(server.playerRecords) do
local States = playerRecord.States
-- Step the charge state
if States.IsCharging == true then
-- step it according to equipped melee stats
local EquippedMelee = playerRecord.Inventory.Hand
if EquippedMelee then
local CalculatedCharge = States.Charge
local ChargeSpeed = EquippedMelee.MaxDamage / EquippedMelee.ChargeLength
CalculatedCharge += ChargeSpeed * _deltaTime
if CalculatedCharge >= EquippedMelee.MaxDamage then
States.Charge = EquippedMelee.MaxDamage
else
States.Charge = CalculatedCharge
end
end
else
States.Charge = 0
end
-- Step cooldowns
if States.SwingRecovery > 0 then
States.IsSwingRecovering = true
local CalculatedSwingRecovery = States.SwingRecovery
CalculatedSwingRecovery -= _deltaTime
if CalculatedSwingRecovery <= 0 then
States.SwingRecovery = 0
States.IsSwingRecovering = false
else
States.SwingRecovery = CalculatedSwingRecovery
end
end
if States.BlockRecovery > 0 then
States.IsBlockRecovering = true
local CalculatedBlockRecovery = States.BlockRecovery
CalculatedBlockRecovery -= _deltaTime
if CalculatedBlockRecovery <= 0 then
States.BlockRecovery = 0
States.IsBlockRecovering = false
else
States.BlockRecovery = CalculatedBlockRecovery
end
end
end
end
What I actually wan’t to understand is how to deal with these going out of sync with the server, since from what I understood. Clients and server can get out of sync due to ping fluctuation, if ping was always the same for a client we wouldn’t have to worry about this.
Please I just want to know this, its the last piece of knowledge im missing on how to properly do server authority.