I want to be able to store keys in a table that have data of the speed the player should move at.
local function GetHighestPriorityState(states)
local highestPriorityState = nil
local highestPriority = 0
for stateName, data in pairs(states) do
if data.Priority and data.Priority > highestPriority then
highestPriority = data.Priority
highestPriorityState = data
end
end
return highestPriorityState
end
ActiveStates = {
SlowNumber1 = {Speed = 5, JumpPower = 30, Priority = 4}
SlowNumber2 = {Speed = 1, JumpPower = 60, Priority = 5}
}
Along with that I would want to add the player’s currently used moves, added Stun Effects which would return true if a table is indexed with something:
AddedStunEffects = {
StunNumber1 = {Speed = 5, JumpPower = 30, Priority = 4}
SlowNumber5 = {Speed = 1, JumpPower = 60, Priority = 5}
}
-- Returns true if it finds anything in that table, immobilizing the player to do any more moves
and this is the current structure I’m stuck with:
function StatusEffects.Initialize(player: Player)
local character = player.Character or player.CharacterAdded:Wait()
if not CharacterStates[character] then
CharacterStates[character] = {
Humanoid = character:WaitForChild("Humanoid"),
ActiveStates = {},
CurrentSpeed = Config.BaseSpeed,
CurrentJump = Config.BaseJump
}
if IsServer then
Transmit:FireTo(player, "Initialize")
end
end
end
I need help with structuring this in a manner that will allow me to add states, check for indexed tables and returning booleans.
function StatusEffects.AddState(character: Model, stateName: string, data: {any})
local stateInfo = CharacterStates[character]
if not stateInfo then return end
stateInfo.ActiveStates[stateName] = data
StatusEffects.Update(character)
if data.Dura and data.Dura > 0 then
task.delay(data.Dura, StatusEffects.RemoveState, character, stateName)
end
end
But right now I can’t seem to figure it out.