How to "Autouse" Abilities?

I’ve been working on a combat game and the main problem I have with my game is the weapon and abilities, I was wondering if anyone knew how autouse tools worked in games like “Deepwoken” and the trending battleground games like the most popular “Strongest Battlegrounds” have a autouse type of system for their abiltiies, for example whenever you’re using your melee in either game you’re unable to do the action of switching your abilities till the melee is over, and in some cases if you do attempt to use a ability during a melee attack it goes into a type of a queue and waits for the melee attack to be over to automatically use. So basically i’m looking for help on how I could make a autouse/queue ability system like those games I listed and gave examples from.

1 Like

something like this maybe

local abilityQueue = {}
local currentlyAttacking = false

userInputService.inputBegan:Connect(function(input, processed)
   if processed then return end
   if input.keycode == enum.keycode.e then
      if currentlyAttacking then
         --make sure the queue isnt too long
         if #abilityQueue > 3 then return end
         abilityQueue[#abilityQueue + 1] = "e"
         return
      end
      currentlyAttacking = true
      attack("e")
      --wait until attack is done
      currentlyAttacking = false
      for _, ability in ipairs(abilityQueue) do
         currentlyAttacking = true
         attack(ability)
         currentlyAttacking = false
      end
   end
end)

obviously this code wont work, for 1 the loop that uses the abilities in the queue is in the wrong spot, but it should provide you a good base to work off of. One thing that I think works incredibly well is “when in doubt, use tables”. tables are incredibly robust and make your code so much more expandable.

alright, this helps drastically, I always forget about the usefulness in tables so thanks for helping me see how useful they could be towards my current project and I’ll surely learn more about tables to improve my coding.

1 Like

yeah. once you understand tables, i would HIGHLY recommend learning module scripts and object oriented programming. it is hard, but it is so so SO worth it. I am starting to understand the strict typechecker (basically just avoids type errors in making code, its all up to personal preference when it comes to that). Now, instead of spending more time testing than coding, i am spending much more time coding and 5 to 10 minutes of testing. if you need any help just let me know!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.