Switching Player Movesets with key inputs?

So i have this planned mechanic where the player can press Q and E to change their moves

In short, player spawns with a specific set of abilities and if they press Q they can switch their abilities, pressing Q or E again will give them back their original move set

How can i achieve this simply? Im not sure how to pursue this and help would be greatly appreciated :sweat_smile:

Thank you for your time :slightly_smiling_face:

1 Like

I’m going to write this in psudo code as I’m doing homework rn but how i’d do it is
when you press Q or E, you change a value, that value determines what move set your using.
You would store what binds they have for each set, and all possible binds. This is a way you could set it up:
client-

--Client would act as normal, telling the server what keys it presses

server-

local CurrentSet = 1 --1 = default, 2 = Q, 3 = E.
local Binds = {
   [1] = {
      [Enum.KeyCode.R] = "Move1";
   };
   [2] = {
      [Enum.KeyCode.R] = "Move2";
   };
   [3] = {
      [Enum.KeyCode.R] = "Move3";
   };
}
local BindKeys = {
   [1] = Enum.KeyCode.R;
}
function InputRecieved(Input)
   if Input == Enum.KeyCode.Q then
      if CurrentSet == 2 then CurrentSet = 1 else CurrentSet = 2 end
   elseif Input == Enum.KeyCode.E then
      if CurrentSet == 3 then CurrentSet = 1 else CurrentSet = 3 end
   elseif table.find(BindKeys, Input) then --Checks to see if the input is a move bind
      ActivateMove(Binds[CurrentSet][Input]) --Gets the set of binds, then gets the name of the move from the input key.
   end
end

I hope this helps, and if you have any questions just ask. I can further explain any part of this.

1 Like

This is a little confusing. For the client what exactly are we putting?

Under this line of code do we put where the players abilities change?

And would we be using Renote Events?

Wouldnt we set the intiger values to Q instead of checking to see if its 2?

--MoveList is a table containing every move a player could use/has equipped
local MoveList = {
	[1] = "Move1";
	[2] = "Move2";
	[3] = "Move3";
}

local SelectedMove = 1 --Variable that keeps track of which move is currently selected, by default Move1 (the 1st value in the table) is selected

function ChangeMoves(InputObject)
	if InputObject.KeyCode == Enum.KeyCode.E then
		
		--If the player presses E we then add +1 to the SelectedMove, therefore, if SelectedMove was 1 it is now 2, which indicates that Move2 is now selected and so on.
		--But this can cause some issues, if SelectedMove is set to 3 and we add 1 to it, it would indicate the selected move is 4 which does not exist in our MoveList. 
		--To solve this, we first have to check if the current SelectedMove is greater than or equal to the number of values in MoveList
		--"#" is used to find how many values are inside of a table, to figure out how many values are inside MoveList, we use #MoveList (which in this case would return 3)
		--If the SelectedMove is greater than or equal to #MoveList, we then set SelectedMove back to 1 instead of adding to it, which allows us to fully cycle through the list.
		
		SelectedMove = (SelectedMove >= #MoveList) and 1 or SelectedMove + 1
		
	elseif InputObject.KeyCode == Enum.KeyCode.Q then
		
		--For the other direction, we do the same thing except instead of adding we subtract
		--We also have to instead check if the SelectedMove is less than or equal to 1, and if it is we set it to the last value of the moveList, #MoveList
		SelectedMove = (SelectedMove <= 1) and #MoveList or SelectedMove - 1
	end
	
	--Now lets print the outcome see it in action,
	if InputObject.KeyCode == Enum.KeyCode.Q or InputObject.KeyCode == Enum.KeyCode.E then
		print(MoveList[SelectedMove])
	end
end
2 Likes

First question:
was assuming you knew how to utilize user input service and remote events to transmit inputs to the server, I will explain how to work with UIS (User input service) and remotes tomorrow as it is very late for me.
Second question:
table.find(Table, Value) looks for a value within a table, I’m checking to see if the Input variable is one of the inputs listed in the BindKeys table, to find out if it’s a key relating to a move.
Third question:
Because you had said you wanted to be able to press Q or E again to set it back to the default skill set.

1 Like

I understand this! thank you

Im sorry for the late reply i was busy yesterday :sweat_smile:

So i had this idea: I can check for what move is being printed and have an event fire to the server to switch around the abilities/moves of the player. I think it would work

1 Like