From a3a8720c91db21d16dbf3317f8398f21aaf3f0d2 Mon Sep 17 00:00:00 2001 From: rhpidfyre Date: Sat, 2 Mar 2024 16:35:12 -0500 Subject: [PATCH] Flashlight UDP uses EulerAngles instead now --- src/client/Character/Client/Actions.lua | 7 ++++- src/client/Character/Server/Flashlight.lua | 31 +++++++++++++++------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/client/Character/Client/Actions.lua b/src/client/Character/Client/Actions.lua index d6530fc..3c2a3d9 100644 --- a/src/client/Character/Client/Actions.lua +++ b/src/client/Character/Client/Actions.lua @@ -86,7 +86,12 @@ function Actions:EnableFlashlight(FlashlightKey: Enum.KeyCode) task.spawn(function() while Actions.FlashlightEnabled do - FlashlightRemote:FireServer(table.pack(self.CurrentCamera.CFrame:ToEulerAnglesXYZ())) + --Remotes cant transmit dictionaries + --Note: if dictionaries are more than 1 value, encode it into JSON + local c = table.pack(self.CurrentCamera.CFrame:ToEulerAnglesXYZ()) + table.insert(c, c.n) + + FlashlightRemote:FireServer(c) Delta:time() end end) diff --git a/src/client/Character/Server/Flashlight.lua b/src/client/Character/Server/Flashlight.lua index 1e5e2cc..8f14060 100644 --- a/src/client/Character/Server/Flashlight.lua +++ b/src/client/Character/Server/Flashlight.lua @@ -10,11 +10,10 @@ type FlashlightUDP = RBXScriptConnection type LocalPlayer = Player type HumanoidRootPart = BasePart -type EulerXYZ_struct = { - [number | string]: number -} +type EulerXYZ_struct = {number} Flashlight.Enabled = false +Flashlight.HeadHeight = 1 local CharacterShared = _G.include(script, "CharacterShared") @@ -24,10 +23,10 @@ Flashlight_UDP.Parent = CharacterShared local FlashlightUDP_Event: FlashlightUDP? -function Flashlight.constructor(LocalPlayer: LocalPlayer, HumanoidRootPart: HumanoidRootPart) +local function FlashlightPart(HumanoidRootPart: HumanoidRootPart): (Part, SpotLight, Sound) local FlashlightPart = Instance.new("Part") :: Part FlashlightPart.Size = Vector3.new(.1,.1,.1) - FlashlightPart.CFrame = HumanoidRootPart.CFrame + FlashlightPart.CFrame = HumanoidRootPart.CFrame+Vector3.yAxis FlashlightPart.CanCollide = false FlashlightPart.CastShadow = false FlashlightPart.Anchored = true @@ -42,21 +41,33 @@ function Flashlight.constructor(LocalPlayer: LocalPlayer, HumanoidRootPart: Huma SpotLight.Enabled = false SpotLight.Parent = FlashlightPart - FlashlightPart.Parent = HumanoidRootPart - local ToggleSound = Instance.new("Sound") :: Sound ToggleSound.Name = "Flashlight" ToggleSound.SoundId = "rbxassetid://16454678462" ToggleSound.Volume = .5 ToggleSound.Parent = HumanoidRootPart + FlashlightPart.Parent = HumanoidRootPart + + return FlashlightPart, SpotLight, ToggleSound +end + +function Flashlight.constructor(LocalPlayer: LocalPlayer, HumanoidRootPart: HumanoidRootPart) + local FlashlightPart, SpotLight, ToggleSound = FlashlightPart(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, CameraEuler: EulerXYZ_struct) - if Messenger.UserId == LocalPlayer.UserId then - -- FlashlightPart.CFrame = CameraCFrame - -- print((HumanoidRootPart.Position-CameraCFrame.Position).Magnitude) + --The compiler/optimization level should inline this + local ExtraCheck = CameraEuler[4] and CameraEuler[4] == 3 + + if Messenger.UserId == LocalPlayer.UserId and ExtraCheck then + local RootPartCFrame = HumanoidRootPart.CFrame + FlashlightPart.CFrame = CFrame.new( + RootPartCFrame.X, + RootPartCFrame.Y+Flashlight.HeadHeight, + RootPartCFrame.Z)*CFrame.Angles(CameraEuler[1],CameraEuler[2],CameraEuler[3]) end end)