Basically, I want to know how I would start to make a queue system for attacks.
i.e Player does a move. While the move is still attacking, player does another move. Player finishes first move, does the second move right after the next.
Another example would be Black Magic. After you attack once, your character would attack again if you pressed an attack key during an attack.
I’ve tried to find this sort of stuff around dev forum but couldn’t, so any help is well appreciated.
1 Like
This really depends on the implementation you have, but essentially it comes down to using a simple queue data structure. This can be pretty simply implemented with:
local queue = {}
function add_attack_to_queue(attack)
table.insert(queue, attack)
end
function get_next_attack()
return table.remove(queue, 1)
end
You can always add your attack to the queue, even if no other attacks are queued, then when you finish an attack you can call your get_next_attack()
function and that will always return the next attack if one exists, otherwise it will return nil
. It’s important to only call that function one time after an attack finishes and store the result in a variable since it pops the first item from the queue each time.
Should I make dedicated functions for the attacks? Right now I have functions connected to UIS inputs.
That’s up to you. If I were doing this I would probably have separate functions for each attack and call those during some centralized attack function. That could be done however you like. If you don’t want to change up your current implementation too much you could just add the user input to your queue
game:GetService('UserInputService').InputBegan:Connect(function(input, game_processed)
if (not game_processed) then
add_attack_to_queue(input)
end
end)
Then when your current attack ends, you could call your get_next_attack()
function, see if it isn’t nil
and then check if it’s valid attack input.
2 Likes
Thank you so much! I’ve been overthinking it so much lol
1 Like
hey can this be used for a table i just wanted to know because i wanted to delay the animations on the table sorry if this is late
The queuing concept should work on pretty much anything where it makes sense. What you’re wanting to do should be fine.
i guess i see but what should i put if im doing an animation ill show you the code
local tableAnim = {
script.Slash1,
script.Slash2,
script.Slash3
}
for i,v in pairs(tableAnim) do
print (i,v)
end
if anyCombo then
add_attack_to_queue(Anim)
local Anim = tableAnim[combo]
local playAnim = Char.Humanoid:LoadAnimation(Anim)
playAnim:Play()
get_next_attack(Anim)
combo +=1
end
```
i just wanted to just play the animations but then use the other animation when theres an input queued
update: i figured it out
1 Like