So ive made a simple system for my game that allows me to have “movesets” that holds multiple moves. Each move would be something like firing a gun or dashing in the air. And i think ive basically got a good system going for it. However, my current issue with it is that it doesnt have a working system for anything that would be doing stuff for more than just the frame that you press a button. Not sure if this counts as Code Review or Scripting Support so i might post this there too. Heres the system though:
--StarterPlayerScripts.MoveBindings
local UserInputService = game:GetService("UserInputService")
local MoveEvent = game.ReplicatedStorage.MoveEvent
local Bindings = {
[Enum.UserInputType.MouseButton1] = "Primary",
[Enum.UserInputType.MouseButton2] = "Secondary",
[Enum.KeyCode.E] = "E Move",
[Enum.KeyCode.Q] = "Q Move",
[Enum.KeyCode.F] = "Ultimate"
}
function InputFunc(Input, Processed)
if Processed then return end
local State = (Input.UserInputState == Enum.UserInputState.Begin)
local Move = Bindings[Input.KeyCode] or Bindings[Input.UserInputType]
if not Move then return end
MoveEvent:FireServer(Move, State, workspace.CurrentCamera.CFrame)
end
UserInputService.InputBegan:Connect(InputFunc)
UserInputService.InputEnded:Connect(InputFunc)
--ServerScriptService.MoveHandling
local MoveEvent = game.ReplicatedStorage.MoveEvent
local Movesets = require(game.ServerStorage.Movesets)
MoveEvent.OnServerEvent:Connect(function(Player, Move, State, CCF)
local Cooldowns = Player:FindFirstChild("Cooldowns")
local CurrentMoveset = Player:FindFirstChild("CurrentMoveset")
local Character = Player.Character
local DataManager = Character:FindFirstChild("DataManager")
if tick() < Cooldowns:FindFirstChild(Move).Value then return end
local InfoTable = {
State = State,
Player = Player,
Character = Character,
DataManager = DataManager,
CCF = CCF
}
local Cooldown = Movesets[CurrentMoveset.Value][Move](InfoTable)
Cooldowns:FindFirstChild(Move).Value = tick() + Cooldown
end)
--ServerStorage.Movesets
local Movesets = {}
for i, Moveset in pairs(script:GetChildren()) do
local MovesetName = Moveset.Name
local Moves = require(Moveset)
Movesets[MovesetName] = Moves
end
return Movesets
--ServerStorage.Movesets.Test
local Moveset = {}
for i, Move in pairs(script:GetChildren()) do
local MoveName = Move.Name
Moveset[MoveName] = require(Move)
end
return Moveset
--ServerStorage.Movesets.Test.Primary
return function(InfoTable)
if InfoTable.State then
print("test")
return 1
end
return 0
end
I only showed one of the moves under the Test Module because currently all of the moves are the same. Another thing im having an issue with is that im not sure how im gonna handle Passive abilities, which i wanted to have in this game. Share your thoughts please!
Edit: DataManager is just a module under StarterCharacterScripts to let me save data for moves like if i want to save the amount of times i used a move or smth like that.