diff --git a/src/client/Character/Client/Actions.lua b/src/client/Character/Client/Actions.lua index fc7bc0e..fbb1499 100644 --- a/src/client/Character/Client/Actions.lua +++ b/src/client/Character/Client/Actions.lua @@ -21,14 +21,15 @@ Actions.CrouchSpeed = .2 Actions.FlashlightEnabled = false local CharacterShared = _G.include(script, "CharacterShared") -local FlashlightRemote = CharacterShared:WaitForChild("Flashlight") +local FlashlightRemote: UnreliableRemoteEvent = CharacterShared:WaitForChild("Flashlight") -local Storage = game:GetService("ReplicatedStorage") -local RS = game:GetService("RunService") +local Storage: ReplicatedStorage = game:GetService("ReplicatedStorage") local Tween = require(Storage:WaitForChild("Tween")) local Delta = require(Storage:WaitForChild("Delta")) +local CrouchTween = Tween.constructor() + type inherented = any function Actions.constructor(HumanoidSettings: inherented, Humanoid: Humanoid, CurrentCamera: Camera) @@ -51,8 +52,6 @@ function Actions:DisableSneak() self.HumanoidSettings:SetWalkSpeed(Actions.Walk) end -local CrouchTween = Tween.constructor() - function Actions:EnableCrouch(StandingWalkSpeed: number) Actions.DoingAction = true Actions.Crouching = true @@ -82,7 +81,7 @@ function Actions:EnableFlashlight() task.spawn(function() while Actions.FlashlightEnabled do - + FlashlightRemote:FireServer() Delta:time() end end) diff --git a/src/client/Character/Client/init.client.lua b/src/client/Character/Client/init.client.lua index a387716..9987de7 100644 --- a/src/client/Character/Client/init.client.lua +++ b/src/client/Character/Client/init.client.lua @@ -2,13 +2,14 @@ --!native --!strict -local Character = script.Parent.Parent +local Dir = script.Parent +local Character = Dir.Parent local preprocessor = {} type CharacterSharedFolder = Folder function preprocessor.CharacterShared(): CharacterSharedFolder - return Character:WaitForChild("shared") + return Dir:WaitForChild("shared") end _G.include = function(this: LuaSourceContainer, FunName: string, ...) @@ -21,8 +22,8 @@ _G.include = function(this: LuaSourceContainer, FunName: string, ...) end end -local Storage = game:GetService("ReplicatedStorage") -local RS = game:GetService("RunService") :: RunService +local Storage: ReplicatedStorage = game:GetService("ReplicatedStorage") +local RS: RunService = game:GetService("RunService") local ClientStorage = Storage:WaitForChild("Client") local LoadCompleted = ClientStorage:WaitForChild("LoadingComplete") diff --git a/src/client/Character/Server/Actions.lua b/src/client/Character/Server/Actions.lua new file mode 100644 index 0000000..999b88e --- /dev/null +++ b/src/client/Character/Server/Actions.lua @@ -0,0 +1,59 @@ +--!optimize 2 +--!native +--!strict + +local Actions = {} +Actions.__index = Actions + +type EventFunction = (...any) -> () +type ActionsTCP = RBXScriptConnection + +local CharacterShared = _G.include(script, "CharacterShared") + +local Remote = Instance.new("RemoteEvent") :: RemoteEvent +Remote.Name = "ActionsBind" +Remote.Parent = CharacterShared + +local ActionsTCP_Event: ActionsTCP? + +function Actions.constructor(LocalPlayer: Player) + local Events: { + [Enum.KeyCode]: EventFunction + } = {} + + if ActionsTCP_Event then + warn("[Server Actions]: TCP event was already created, duplicating...", debug.traceback()) + end + ActionsTCP_Event = Remote.OnServerEvent:Connect(function(Messenger: Player, Key: Enum.KeyCode) + if Messenger.UserId == LocalPlayer.UserId then + if typeof(Key) == "EnumItem" then + local switch = Events[Key] + if switch then + switch() + end + else + warn(`[Server Actions]: Got an unknown type, Key="{typeof(Key)}" Value="{Key}" from: "{Messenger.Name}"`) + end + end + end) + + return setmetatable({ + Events = Events, + CurrentActionsTCP_Event = ActionsTCP_Event + }, Actions) +end + +function Actions:Add(Key: Enum.KeyCode, f: EventFunction) + self.Events[Key] = f +end + +function Actions:Remove(Key: Enum.KeyCode) + self.Events[Key] = nil + + if not next(self.Events) then + (self.CurrentActionsTCP_Event :: ActionsTCP):Disconnect() + print("[Server Actions]: ") + end +end + +return Actions \ No newline at end of file diff --git a/src/client/Character/Server/Flashlight.lua b/src/client/Character/Server/Flashlight.lua index 513abcb..233e2b3 100644 --- a/src/client/Character/Server/Flashlight.lua +++ b/src/client/Character/Server/Flashlight.lua @@ -5,68 +5,66 @@ local Flashlight = {} Flashlight.__index = Flashlight -local Remote = Instance.new("UnreliableRemoteEvent") :: UnreliableRemoteEvent -Remote.Name = "Flashlight" -Remote.Parent = _G.include(script, "CharacterShared") +Flashlight.Enabled = false -function Flashlight.constructor(Head: BasePart) +function Flashlight.constructor(HumanoidRootPart: BasePart) local FlashlightPart = Instance.new("Part") :: Part FlashlightPart.Size = Vector3.new(.1,.1,.1) - FlashlightPart.CFrame = Head.CFrame+Vector3.yAxis + FlashlightPart.CFrame = HumanoidRootPart.CFrame FlashlightPart.CanCollide = false FlashlightPart.CastShadow = false + FlashlightPart.Anchored = true FlashlightPart.Transparency = 1 local SpotLight = Instance.new("SpotLight") :: SpotLight SpotLight.Color = Color3.new(1,1,1) - SpotLight.Angle = 80 + SpotLight.Angle = 90 SpotLight.Range = 30 SpotLight.Brightness = 1 SpotLight.Shadows = true SpotLight.Enabled = false SpotLight.Parent = FlashlightPart - local Weld = Instance.new("WeldConstraint") :: WeldConstraint - Weld.Part0 = Head - Weld.Part1 = FlashlightPart - Weld.Parent = FlashlightPart - FlashlightPart.Anchored = false - FlashlightPart.Parent = Head + FlashlightPart.Parent = HumanoidRootPart local ToggleSound = Instance.new("Sound") :: Sound ToggleSound.SoundId = "rbxassetid://16454678462" ToggleSound.Volume = .5 - ToggleSound.Parent = Head + ToggleSound.Parent = HumanoidRootPart return setmetatable({ - SpotLight = SpotLight, - ToggleSound = ToggleSound, - Remote = Remote + FlashlightPart = FlashlightPart, + SpotLight = SpotLight, + ToggleSound = ToggleSound }, Flashlight) end -local FlashlightEnabled = false +function Flashlight:On(CameraCFrame: CFrame) + Flashlight.Enabled = true -function Flashlight:On() - FlashlightEnabled = true - self.ToggleSound:Play() - self.SpotLight.Enabled = FlashlightEnabled + (self.FlashlightPart :: Part).CFrame *= CameraCFrame; + (self.ToggleSound :: Sound):Play(); + (self.SpotLight :: SpotLight).Enabled = Flashlight.Enabled end function Flashlight:Off() - FlashlightEnabled = false - self.ToggleSound:Play() - self.SpotLight.Enabled = FlashlightEnabled + Flashlight.Enabled = false + + (self.ToggleSound :: Sound):Play(); + (self.SpotLight :: SpotLight).Enabled = Flashlight.Enabled end -function Flashlight:Toggle() - -- FlashlightEnabled = not FlashlightEnabled - if FlashlightEnabled then +function Flashlight:Toggle(CameraCFrame: CFrame?) + if Flashlight.Enabled then self:Off() else - self:On() + self:On(CameraCFrame :: CFrame) end end +function Flashlight:SetCFrame(CameraCFrame: CFrame) + +end + return Flashlight \ No newline at end of file diff --git a/src/client/Character/Server/SpineKinematics.lua b/src/client/Character/Server/SpineKinematics.lua index bfd9bf7..a771a4e 100644 --- a/src/client/Character/Server/SpineKinematics.lua +++ b/src/client/Character/Server/SpineKinematics.lua @@ -11,6 +11,7 @@ Spine.__index = Spine type Head = BasePart type UpperTorso = BasePart type Neck = Motor6D +type Waist = Motor6D type NeckC0 = CFrame type WaistC0 = CFrame @@ -20,6 +21,7 @@ type struct_Spine = { Head: Head, UpperTorso: UpperTorso, Neck: Neck, + Waist: Waist, NeckC0: NeckC0, WaistC0: WaistC0 } @@ -32,9 +34,9 @@ function Spine.constructor(Head: Head, UpperTorso: UpperTorso) local self = {} :: struct_Spine self.Head = Head self.UpperTorso = UpperTorso - self.Neck = Head:WaitForChild("Neck") - self.Waist = UpperTorso:WaitForChild("Waist") - self.Remote = Remote + self.Neck = Head:WaitForChild("Neck") :: Neck + self.Waist = UpperTorso:WaitForChild("Waist") :: Waist + self.Remote = Remote :: UnreliableRemoteEvent 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 1ab409f..44131bc 100644 --- a/src/client/Character/Server/init.server.lua +++ b/src/client/Character/Server/init.server.lua @@ -2,17 +2,22 @@ --!native --!strict -local Character = script.Parent.Parent +local Dir = script.Parent +local Character = Dir.Parent local preprocessor = {} +local FlashlightCooldown = .10 + +local Players = game:GetService("Players") + --Create the character shared directory here local CharacterShared = Instance.new("Folder") CharacterShared.Name = "shared" -CharacterShared.Parent = Character +CharacterShared.Parent = Dir type CharacterSharedFolder = Folder -function preprocessor.CharacterShared(): CharacterSharedFolder - return CharacterShared +function preprocessor.CharacterShared(): Instance + return CharacterShared :: CharacterSharedFolder end _G.include = function(this: LuaSourceContainer, FunName: string, ...) @@ -26,11 +31,10 @@ _G.include = function(this: LuaSourceContainer, FunName: string, ...) end end -local Players = game:GetService("Players") - local Shadows = require(script:WaitForChild("Shadows")) 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") @@ -40,6 +44,9 @@ 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 FlashlightDebounce = false CharacterShadows:off() --I plan having 2 player support and characters block a ton of light @@ -48,6 +55,16 @@ Character.DescendantAdded:Connect(function(Instance) CharacterShadows:PartToggle(Instance, false) end) +Actions:Add(Enum.KeyCode.F, function() + if not FlashlightDebounce then + Flashlight:Toggle() + + FlashlightDebounce = true + task.wait(FlashlightCooldown) + FlashlightDebounce = false + end +end) + Spine.Remote.OnServerEvent:Connect(function(Messenger: Player, CameraPosition: CFrame, IsFirstPerson: boolean) if Messenger.UserId == LocalPlayer.UserId then if Spine.Enabled then @@ -59,16 +76,4 @@ Spine.Remote.OnServerEvent:Connect(function(Messenger: Player, CameraPosition: C end end) -local FlashlightDebounce = false - -Flashlight.Remote.OnServerEvent:Connect(function(Messenger: Player) - if Messenger.UserId == LocalPlayer.UserId then - if not FlashlightDebounce then - Flashlight:Toggle() - - FlashlightDebounce = true - task.wait(.10) - FlashlightDebounce = false - end - end -end) \ No newline at end of file +_G.include = nil \ No newline at end of file