mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-14 06:41:55 +00:00
Flashlight UDP uses EulerAngles instead now
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user