diff --git a/src/client/Character/Client/Actions.lua b/src/client/Character/Client/Actions.lua index fbb1499..14e7966 100644 --- a/src/client/Character/Client/Actions.lua +++ b/src/client/Character/Client/Actions.lua @@ -5,6 +5,10 @@ local Actions = {} Actions.__index = Actions +type UDP = UnreliableRemoteEvent +type TCP = RemoteEvent +type inherented = any + --Sneak static properties Actions.DoingAction = false Actions.Sneaking = false @@ -21,7 +25,7 @@ Actions.CrouchSpeed = .2 Actions.FlashlightEnabled = false local CharacterShared = _G.include(script, "CharacterShared") -local FlashlightRemote: UnreliableRemoteEvent = CharacterShared:WaitForChild("Flashlight") +local FlashlightRemote: UDP = CharacterShared:WaitForChild("Flashlight") local Storage: ReplicatedStorage = game:GetService("ReplicatedStorage") @@ -30,13 +34,12 @@ local Delta = require(Storage:WaitForChild("Delta")) local CrouchTween = Tween.constructor() -type inherented = any - -function Actions.constructor(HumanoidSettings: inherented, Humanoid: Humanoid, CurrentCamera: Camera) +function Actions.constructor(HumanoidSettings: inherented, CurrentCamera: Camera, ActionsTCP: TCP) return setmetatable({ - Humanoid = Humanoid, + Humanoid = HumanoidSettings.Humanoid, HumanoidSettings = HumanoidSettings, - CurrentCamera = CurrentCamera + CurrentCamera = CurrentCamera, + ActionsTCP = ActionsTCP }, Actions) end @@ -52,69 +55,55 @@ function Actions:DisableSneak() self.HumanoidSettings:SetWalkSpeed(Actions.Walk) end -function Actions:EnableCrouch(StandingWalkSpeed: number) +function Actions:EnableCrouch() Actions.DoingAction = true Actions.Crouching = true local Easing = TweenInfo.new(Actions.CrouchSpeed, Enum.EasingStyle.Linear) + local WalkSpeed = (self.Humanoid :: Humanoid).WalkSpeed CrouchTween:Start(self.Humanoid, { HipHeight = Actions.CrouchHeight, - WalkSpeed = math.max(1, StandingWalkSpeed-Actions.WalkSpeedMultiplier) + WalkSpeed = math.max(1, WalkSpeed-Actions.WalkSpeedMultiplier) }, Easing) end -function Actions:DisableCrouch(CrouchingWalkSpeed: number) +function Actions:DisableCrouch() Actions.DoingAction = false Actions.Crouching = false local Easing = TweenInfo.new(Actions.CrouchSpeed, Enum.EasingStyle.Linear) + local WalkSpeed = (self.Humanoid :: Humanoid).WalkSpeed CrouchTween:Start(self.Humanoid, { HipHeight = Actions.StandHeight, - WalkSpeed = math.max(1, CrouchingWalkSpeed+Actions.WalkSpeedMultiplier) + WalkSpeed = math.max(1, WalkSpeed+Actions.WalkSpeedMultiplier) }, Easing) end -function Actions:EnableFlashlight() +function Actions:EnableFlashlight(FlashlightKey: Enum.KeyCode) Actions.FlashlightEnabled = true task.spawn(function() while Actions.FlashlightEnabled do - FlashlightRemote:FireServer() + FlashlightRemote:FireServer(self.CurrentCamera.CFrame) Delta:time() end end) + self.ActionsTCP:FireServer(FlashlightKey) end -function Actions:DisableFlashlight() +function Actions:DisableFlashlight(FlashlightKey: Enum.KeyCode) + self.ActionsTCP:FireServer(FlashlightKey) Actions.FlashlightEnabled = false end -function Actions:EnableFlashlight() +function Actions:ToggleFlashlight(FlashlightKey: Enum.KeyCode) if Actions.FlashlightEnabled then - + self:DisableFlashlight(FlashlightKey) else - + self:EnableFlashlight(FlashlightKey) end end -function Actions:ToggleCrouch() - if not Actions.DoingAction then - if Actions.Crouching then - self:DisableCrouch() - else - self:EnableCrouch() - end - end -end - -function Actions:ToggleSneak() - if not Actions.DoingAction then - if Actions.Sneaking then - self:DisableSneak() - else - self:EnableSneak() - end - end -end \ No newline at end of file +return Actions \ No newline at end of file diff --git a/src/client/Character/Client/Camera/init.lua b/src/client/Character/Client/Camera/init.lua index ef49012..f19345b 100644 --- a/src/client/Character/Client/Camera/init.lua +++ b/src/client/Character/Client/Camera/init.lua @@ -11,9 +11,18 @@ local RS = game:GetService("RunService") local Bobbing = require(script:WaitForChild("Bobbing")) type FakeCamera = BasePart +type CurrentCamera = Camera +type HumanoidRootPart = BasePart -function Camera.constructor(CurrentCamera: Camera, HumanoidRootPart: BasePart, Humanoid: Humanoid) - local self = {} +type Camera_struct = { + CameraFPS: boolean, + CurrentCamera: CurrentCamera, + HumanoidRootPart: HumanoidRootPart, + BobbingCamera: any +} + +function Camera.constructor(CurrentCamera: CurrentCamera, HumanoidRootPart: HumanoidRootPart, Humanoid: Humanoid) + local self = {} :: Camera_struct self.CameraFPS = false self.CurrentCamera = CurrentCamera self.HumanoidRootPart = HumanoidRootPart diff --git a/src/client/Character/Client/HumanoidRootPart.lua b/src/client/Character/Client/HumanoidRootPart.lua index 14a4814..8fb152d 100644 --- a/src/client/Character/Client/HumanoidRootPart.lua +++ b/src/client/Character/Client/HumanoidRootPart.lua @@ -17,7 +17,7 @@ function HumanoidRPSettings:DisableRobloxSounds() local Object = HRP_objects[i] if Object:IsA("Sound") then - Object.Volume = 0 + (Object :: Sound).Volume = 0 end end end diff --git a/src/client/Character/Client/SpineKinematics.lua b/src/client/Character/Client/SpineKinematics.lua index 3bd2521..28164ac 100644 --- a/src/client/Character/Client/SpineKinematics.lua +++ b/src/client/Character/Client/SpineKinematics.lua @@ -7,6 +7,15 @@ local Spine = { } Spine.__index = Spine +type UDP = UnreliableRemoteEvent +type CurrentCamera = Camera + +type struct_Spine = { + Remote: UDP, + CurrentCamera: CurrentCamera +} +type CharacterSharedFolder = Folder + local Storage = game:GetService("ReplicatedStorage") local Players = game:GetService("Players") @@ -15,14 +24,6 @@ local Delta = require(Storage:WaitForChild("Delta")) local Player = Players.LocalPlayer local CharacterShared = _G.include(script, "CharacterShared") -type CurrentCamera = Camera - -type struct_Spine = { - Remote: UnreliableRemoteEvent, - CurrentCamera: CurrentCamera -} -type CharacterSharedFolder = Folder - function Spine.constructor(CurrentCamera: CurrentCamera) return setmetatable({ Remote = CharacterShared:WaitForChild("SpineStream"), diff --git a/src/client/Character/Client/init.client.lua b/src/client/Character/Client/init.client.lua index 9987de7..cedf364 100644 --- a/src/client/Character/Client/init.client.lua +++ b/src/client/Character/Client/init.client.lua @@ -2,14 +2,17 @@ --!native --!strict +type CharacterSharedFolder = Folder +type TCP = RemoteEvent + local Dir = script.Parent local Character = Dir.Parent +local CharacterShared = Dir:WaitForChild("shared") + local preprocessor = {} -type CharacterSharedFolder = Folder - function preprocessor.CharacterShared(): CharacterSharedFolder - return Dir:WaitForChild("shared") + return CharacterShared end _G.include = function(this: LuaSourceContainer, FunName: string, ...) @@ -23,23 +26,23 @@ _G.include = function(this: LuaSourceContainer, FunName: string, ...) end local Storage: ReplicatedStorage = game:GetService("ReplicatedStorage") -local RS: RunService = game:GetService("RunService") +local RS: RunService = game:GetService("RunService") -local ClientStorage = Storage:WaitForChild("Client") -local LoadCompleted = ClientStorage:WaitForChild("LoadingComplete") +local ClientStorage: Instance = Storage:WaitForChild("Client") :: Folder +local LoadCompleted: Instance = ClientStorage:WaitForChild("LoadingComplete") :: BindableFunction +local ActionsTCP: TCP = CharacterShared:WaitForChild("Actions") --We need to wait for the game to load before spamming functionality repeat - local GameIsLoaded = LoadCompleted:Invoke() + local GameIsLoaded = (LoadCompleted :: BindableFunction):Invoke() task.wait() until GameIsLoaded local HumanoidRPSettings = require(script:WaitForChild("HumanoidRootPart")) local CameraModule = require(script:WaitForChild("Camera")) -local CrouchModule = require(script:WaitForChild("Crouch")) local HumanoidModule = require(script:WaitForChild("Humanoid")) local SpineModule = require(script:WaitForChild("SpineKinematics")) -local FlashlightModule = require(script:WaitForChild("Flashlight")) +local ActionsModule = require(script:WaitForChild("Actions")) local BindModule = require(ClientStorage:WaitForChild("KeyBinds")) local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart") @@ -54,47 +57,48 @@ local SpineMovement = SpineModule.constructor(CurrentCamera) local ClientBindMap = BindModule.constructor(false) local function ClientCharacterBinds() - local CrouchConstructor = CrouchModule.constructor(Humanoid) + local Actions = ActionsModule.constructor(HumanoidSettings, CurrentCamera, ActionsTCP) + --Crouch - ClientBindMap:AddInputBegan({Enum.KeyCode.RightControl, Enum.KeyCode.LeftControl}, function() - CrouchConstructor:Crouch(10) + ClientBindMap:AddInputBegan({Enum.KeyCode.RightControl, Enum.KeyCode.LeftControl}, function(_KeyPressed) + Actions:EnableCrouch() end) - ClientBindMap:AddInputEnded({Enum.KeyCode.RightControl, Enum.KeyCode.LeftControl}, function() - CrouchConstructor:Stand(5) + ClientBindMap:AddInputEnded({Enum.KeyCode.RightControl, Enum.KeyCode.LeftControl}, function(_KeyPressed) + Actions:DisableCrouch() end) + --Walk - ClientBindMap:AddInputBegan({Enum.KeyCode.LeftAlt, Enum.KeyCode.RightAlt}, function() - HumanoidSettings:SetWalkSpeed(Walking) + ClientBindMap:AddInputBegan({ + Enum.KeyCode.LeftAlt, + Enum.KeyCode.RightAlt, + Enum.KeyCode.LeftShift, + Enum.KeyCode.RightShift + }, function(_KeyPressed) + Actions:EnableSneak() end) - ClientBindMap:AddInputEnded({Enum.KeyCode.LeftAlt, Enum.KeyCode.RightAlt}, function() - HumanoidSettings:SetWalkSpeed(10) + ClientBindMap:AddInputEnded({ + Enum.KeyCode.LeftAlt, + Enum.KeyCode.RightAlt, + Enum.KeyCode.LeftShift, + Enum.KeyCode.RightShift + }, function(_KeyPressed) + Actions:DisableSneak() end) - --Sprint - ClientBindMap:AddInputBegan({Enum.KeyCode.LeftShift, Enum.KeyCode.RightShift}, function() - - end) - ClientBindMap:AddInputEnded({Enum.KeyCode.LeftShift, Enum.KeyCode.RightShift}, function() - + + --Flashlight + ClientBindMap:AddInputBegan({Enum.KeyCode.F}, function(KeyPressed: Enum.KeyCode) + Actions:ToggleFlashlight(KeyPressed) end) end -local function Crosshair3DVelocity_Effect(): RBXScriptSignal +--Needs to be a module maybe +local function Crosshair3DVelocity_Effect(): RBXScriptConnection local RootVelocity = ClientStorage:WaitForChild("RootVelocity") :: BindableEvent - local RootVelocitySteps = RS.Heartbeat:ConnectParallel(function(_dt) + local RootVelocityStep = RS.Heartbeat:ConnectParallel(function(_dt) RootVelocity:Fire(HRPSettings:Velocity()) end) - return RootVelocitySteps -end - -local function FlashlightToggle() - ClientBindMap:AddInputBegan({Enum.KeyCode.F}, function() - Flashlight:Toggle() - end) -end - -local function HealthChangeBind() - + return RootVelocityStep end HumanoidSettings:SetWalkSpeed() @@ -105,6 +109,5 @@ SpineMovement:Enable() ClientCharacterBinds() Crosshair3DVelocity_Effect() -FlashlightToggle() _G.include = nil \ No newline at end of file diff --git a/src/client/Character/Server/Actions.lua b/src/client/Character/Server/Actions.lua index 999b88e..ced5945 100644 --- a/src/client/Character/Server/Actions.lua +++ b/src/client/Character/Server/Actions.lua @@ -5,18 +5,20 @@ local Actions = {} Actions.__index = Actions -type EventFunction = (...any) -> () +type EventFunction = (KeyPressed: Enum.KeyCode) -> () type ActionsTCP = RBXScriptConnection +type LocalPlayer = Player +type TCP = RemoteEvent local CharacterShared = _G.include(script, "CharacterShared") -local Remote = Instance.new("RemoteEvent") :: RemoteEvent -Remote.Name = "ActionsBind" +local Remote = Instance.new("RemoteEvent") :: TCP +Remote.Name = "Actions" Remote.Parent = CharacterShared local ActionsTCP_Event: ActionsTCP? -function Actions.constructor(LocalPlayer: Player) +function Actions.constructor(LocalPlayer: LocalPlayer) local Events: { [Enum.KeyCode]: EventFunction } = {} @@ -29,7 +31,7 @@ function Actions.constructor(LocalPlayer: Player) if typeof(Key) == "EnumItem" then local switch = Events[Key] if switch then - switch() + switch(Key) end else warn(`[Server Actions]: Got an unknown type, Key="{typeof(Key)}" Value="{Key}" from: "{Messenger.Name}"`) diff --git a/src/client/Character/Server/Flashlight.lua b/src/client/Character/Server/Flashlight.lua index 233e2b3..311f16c 100644 --- a/src/client/Character/Server/Flashlight.lua +++ b/src/client/Character/Server/Flashlight.lua @@ -5,9 +5,22 @@ local Flashlight = {} Flashlight.__index = Flashlight +type UDP = UnreliableRemoteEvent +type FlashlightUDP = RBXScriptConnection +type LocalPlayer = Player +type HumanoidRootPart = BasePart + Flashlight.Enabled = false -function Flashlight.constructor(HumanoidRootPart: BasePart) +local CharacterShared = _G.include(script, "CharacterShared") + +local Flashlight_UDP = Instance.new("UnreliableRemoteEvent") :: UDP +Flashlight_UDP.Name = "Flashlight" +Flashlight_UDP.Parent = CharacterShared + +local FlashlightUDP_Event: FlashlightUDP? + +function Flashlight.constructor(LocalPlayer: LocalPlayer, HumanoidRootPart: HumanoidRootPart) local FlashlightPart = Instance.new("Part") :: Part FlashlightPart.Size = Vector3.new(.1,.1,.1) FlashlightPart.CFrame = HumanoidRootPart.CFrame @@ -18,21 +31,30 @@ function Flashlight.constructor(HumanoidRootPart: BasePart) local SpotLight = Instance.new("SpotLight") :: SpotLight SpotLight.Color = Color3.new(1,1,1) - SpotLight.Angle = 90 + SpotLight.Angle = 80 SpotLight.Range = 30 - SpotLight.Brightness = 1 + SpotLight.Brightness = 2 SpotLight.Shadows = true SpotLight.Enabled = false SpotLight.Parent = FlashlightPart - FlashlightPart.Anchored = false FlashlightPart.Parent = HumanoidRootPart local ToggleSound = Instance.new("Sound") :: Sound + ToggleSound.Name = "Flashlight" ToggleSound.SoundId = "rbxassetid://16454678462" ToggleSound.Volume = .5 ToggleSound.Parent = HumanoidRootPart + if FlashlightUDP_Event then + warn("[Server Flashlight]: UDP event was already created, duplicating...", debug.traceback()) + end + FlashlightUDP_Event = Flashlight_UDP.OnServerEvent:Connect(function(Messenger: Player, CameraCFrame: CFrame) + if Messenger.UserId == LocalPlayer.UserId then + FlashlightPart.CFrame = CameraCFrame + end + end) + return setmetatable({ FlashlightPart = FlashlightPart, SpotLight = SpotLight, @@ -40,10 +62,9 @@ function Flashlight.constructor(HumanoidRootPart: BasePart) }, Flashlight) end -function Flashlight:On(CameraCFrame: CFrame) +function Flashlight:On() Flashlight.Enabled = true - (self.FlashlightPart :: Part).CFrame *= CameraCFrame; (self.ToggleSound :: Sound):Play(); (self.SpotLight :: SpotLight).Enabled = Flashlight.Enabled end @@ -55,11 +76,11 @@ function Flashlight:Off() (self.SpotLight :: SpotLight).Enabled = Flashlight.Enabled end -function Flashlight:Toggle(CameraCFrame: CFrame?) +function Flashlight:Toggle() if Flashlight.Enabled then self:Off() else - self:On(CameraCFrame :: CFrame) + self:On() end end diff --git a/src/client/Character/Server/SpineKinematics.lua b/src/client/Character/Server/SpineKinematics.lua index a771a4e..a35912a 100644 --- a/src/client/Character/Server/SpineKinematics.lua +++ b/src/client/Character/Server/SpineKinematics.lua @@ -16,8 +16,10 @@ type Waist = Motor6D type NeckC0 = CFrame type WaistC0 = CFrame +type UDP = UnreliableRemoteEvent + type struct_Spine = { - Remote: UnreliableRemoteEvent, + Remote: UDP, Head: Head, UpperTorso: UpperTorso, Neck: Neck, @@ -36,7 +38,7 @@ function Spine.constructor(Head: Head, UpperTorso: UpperTorso) self.UpperTorso = UpperTorso self.Neck = Head:WaitForChild("Neck") :: Neck self.Waist = UpperTorso:WaitForChild("Waist") :: Waist - self.Remote = Remote :: UnreliableRemoteEvent + self.Remote = Remote :: UDP self.NeckC0 = self.Neck.C0 self.WaistC0 = self.Waist.C0 diff --git a/src/client/Character/Server/init.server.lua b/src/client/Character/Server/init.server.lua index 44131bc..9bbc807 100644 --- a/src/client/Character/Server/init.server.lua +++ b/src/client/Character/Server/init.server.lua @@ -2,6 +2,8 @@ --!native --!strict +type UDP = UnreliableRemoteEvent + local Dir = script.Parent local Character = Dir.Parent local preprocessor = {} @@ -36,15 +38,16 @@ local SpineModule = require(script:WaitForChild("SpineKinematics")) local FlashlightModule = require(script:WaitForChild("Flashlight")) local ActionsModule = require(script:WaitForChild("Actions")) -local Head = Character:WaitForChild("Head") -local UpperTorso = Character:WaitForChild("UpperTorso") +local Head = Character:WaitForChild("Head") +local UpperTorso = Character:WaitForChild("UpperTorso") +local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart") local LocalPlayer = Players:GetPlayerFromCharacter(Character) local CharacterShadows = Shadows.constructor(Character) local Spine = SpineModule.constructor(Head, UpperTorso) -local Flashlight = FlashlightModule.constructor(Head) -local Actions = ActionsModule.constructor(LocalPlayer) +local Flashlight = FlashlightModule.constructor(LocalPlayer, HumanoidRootPart) +local Actions = ActionsModule.constructor(LocalPlayer, HumanoidRootPart) local FlashlightDebounce = false @@ -55,7 +58,7 @@ Character.DescendantAdded:Connect(function(Instance) CharacterShadows:PartToggle(Instance, false) end) -Actions:Add(Enum.KeyCode.F, function() +Actions:Add(Enum.KeyCode.F, function(_KeyPressed) if not FlashlightDebounce then Flashlight:Toggle() @@ -63,9 +66,9 @@ Actions:Add(Enum.KeyCode.F, function() task.wait(FlashlightCooldown) FlashlightDebounce = false end -end) +end); -Spine.Remote.OnServerEvent:Connect(function(Messenger: Player, CameraPosition: CFrame, IsFirstPerson: boolean) +(Spine.Remote :: UDP).OnServerEvent:Connect(function(Messenger: Player, CameraPosition: CFrame, IsFirstPerson: boolean) if Messenger.UserId == LocalPlayer.UserId then if Spine.Enabled then Spine:Move(CameraPosition, IsFirstPerson) diff --git a/src/client/Player/init.client.lua b/src/client/Player/init.client.lua index f60a4fe..fecc2d2 100644 --- a/src/client/Player/init.client.lua +++ b/src/client/Player/init.client.lua @@ -9,9 +9,9 @@ local HealthSettings = require(UI:WaitForChild("Health")) local CoreGuis = require(script:WaitForChild("CoreGuis")) local Mouse = require(script:WaitForChild("Mouse")) -local Players = game:GetService("Players") -local Storage = game:GetService("ReplicatedStorage") -local RS = game:GetService("RunService") :: RunService +local Players: Players = game:GetService("Players") +local Storage: ReplicatedStorage = game:GetService("ReplicatedStorage") +local RS: RunService = game:GetService("RunService") local ClientStorage = Storage:WaitForChild("Client") local LoadCompleted = ClientStorage:WaitForChild("LoadingComplete") @@ -19,11 +19,11 @@ local KeyBindsModule = require(ClientStorage:WaitForChild("KeyBinds")) local CameraSettings = require(ClientStorage:WaitForChild("Camera")) local Player = Players.LocalPlayer -local PlayerGui = Player:WaitForChild("PlayerGui") +local PlayerGui = Player:WaitForChild("PlayerGui") :: PlayerGui --We need to wait for the game to load before spamming functionality repeat - local GameIsLoaded = LoadCompleted:Invoke() + local GameIsLoaded = (LoadCompleted :: BindableFunction):Invoke() task.wait() until GameIsLoaded @@ -41,10 +41,10 @@ local Crosshair = CrosshairSettings.constructor(PlayerGui) local function CameraBinds() local CameraBindMap = KeyBindsModule.constructor(false) - CameraBindMap:AddInputBegan({Enum.KeyCode.C, Enum.KeyCode.Z}, function() + CameraBindMap:AddInputBegan({Enum.KeyCode.C, Enum.KeyCode.Z}, function(_KeyPressed) Camera:ZoomIn(Vignette, Crosshair) end) - CameraBindMap:AddInputEnded({Enum.KeyCode.C, Enum.KeyCode.Z}, function() + CameraBindMap:AddInputEnded({Enum.KeyCode.C, Enum.KeyCode.Z}, function(_KeyPressed) Camera:ZoomOut(Vignette, Crosshair) end) end diff --git a/src/server/Studio/EditorEntities.lua b/src/server/Studio/EditorEntities.lua index e08e16d..4fa7bb7 100644 --- a/src/server/Studio/EditorEntities.lua +++ b/src/server/Studio/EditorEntities.lua @@ -54,6 +54,7 @@ local EditorEntities = { } type HideEditor = (a1: BasePart | Folder, a2: boolean) -> () +type LuaChangeableContainer = Script | LocalScript function StudioEntities.indexAll(enabled: boolean): Entities if #StudioEntities.IndexedEntities == 0 then @@ -88,7 +89,7 @@ function StudioEntities.indexAll(enabled: boolean): Entities if not Players:GetPlayerFromCharacter(Model) then pcall(function() - Item.Enabled = false + (Item :: LuaChangeableContainer).Enabled = false end) Item:Destroy() warn(`Script: "{Item.Name}" ({Item.ClassName}) was removed because it was outside of the rhpid-framework boundries,`, Item:GetFullName()) diff --git a/src/server/Studio/Lighting/Sky.lua b/src/server/Studio/Lighting/Sky.lua index ce86000..21ed0ab 100644 --- a/src/server/Studio/Lighting/Sky.lua +++ b/src/server/Studio/Lighting/Sky.lua @@ -39,9 +39,9 @@ local function Clouds(): Clouds end export type exports = { - Sky: Sky, - Atmosphere: Atmosphere, - Clouds: Clouds, + Sky: () -> Sky, + Atmosphere: () -> Atmosphere, + Clouds: () -> Clouds, } local export: exports = { diff --git a/src/shared/Client/KeyBinds.lua b/src/shared/Client/KeyBinds.lua index b02ce02..1251512 100644 --- a/src/shared/Client/KeyBinds.lua +++ b/src/shared/Client/KeyBinds.lua @@ -7,37 +7,34 @@ local BindLink = {} BindLink.__index = BindLink -local UIS = game:GetService("UserInputService") - export type KeyBindMap = { [string]: { - [Enum.KeyCode]: () -> () + [Enum.KeyCode]: (KeyPressed: Enum.KeyCode) -> () } } export type InputBegan = RBXScriptConnection export type InputEnded = RBXScriptConnection - type CallbackFunction = () -> () +type BindConstructor = { + BindMap: KeyBindMap, + InputBegan: InputBegan, + InputEnded: InputEnded +} + +local UIS = game:GetService("UserInputService") function BindLink.constructor(gameProcessing: boolean) --Allow multiple bindings of the same keys, no overwrites - type BindConstructor = { - BindMap: KeyBindMap, - InputBegan: InputBegan, - InputEnded: InputEnded - } - local self = {} :: BindConstructor self.BindMap = { Began = {}, Ended = {} } - --Return these for convenience self.InputBegan = UIS.InputBegan:Connect(function(input, gameProcessedEvent) if gameProcessing and gameProcessedEvent or not gameProcessedEvent then local switch = self.BindMap.Began[input.KeyCode] if switch then - switch() + switch(input.KeyCode) else --switch.default() end @@ -47,7 +44,7 @@ function BindLink.constructor(gameProcessing: boolean) --Allow multiple bindings if gameProcessing and gameProcessedEvent or not gameProcessedEvent then local switch = self.BindMap.Ended[input.KeyCode] if switch then - switch() + switch(input.KeyCode) else --switch.default() end @@ -60,7 +57,6 @@ end function BindLink:AddInputBegan(Keys: {Enum.KeyCode}, Callback: CallbackFunction) for i = 1, #Keys do local Key = Keys[i] - if self.BindMap.Began[Key] then warn(`Key >began< "{Key.Name}" is already binded on this KeyBind map`, debug.traceback()) end @@ -71,7 +67,6 @@ end function BindLink:AddInputEnded(Keys: {Enum.KeyCode}, Callback: CallbackFunction) for i = 1, #Keys do local Key = Keys[i] - if self.BindMap.Ended[Key] then warn(`Key >ended< "{Key.Name}" is already binded on this KeyBind map`, debug.traceback()) end