mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-16 07:11:54 +00:00
Giant refactoring of how the client and server character is handled
This commit is contained in:
@@ -1,113 +0,0 @@
|
||||
--!optimize 2
|
||||
--!native
|
||||
--!strict
|
||||
|
||||
type CharacterSharedFolder = Folder
|
||||
type TCP = RemoteEvent
|
||||
|
||||
local Dir = script.Parent
|
||||
local Character = Dir.Parent
|
||||
local CharacterShared = Dir:WaitForChild("shared")
|
||||
|
||||
local preprocessor = {}
|
||||
|
||||
function preprocessor.CharacterShared(): CharacterSharedFolder
|
||||
return CharacterShared
|
||||
end
|
||||
|
||||
_G.include = function(this: LuaSourceContainer, FunName: string, ...)
|
||||
if this:IsDescendantOf(script) then --getfenv is being removed
|
||||
local switch = preprocessor[FunName]
|
||||
return type(switch) == "function" and switch(...) or switch
|
||||
else
|
||||
warn(`Preprocessor append failed "{FunName}"`, debug.traceback())
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
local Storage: ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local RS: RunService = game:GetService("RunService")
|
||||
|
||||
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 :: BindableFunction):Invoke()
|
||||
task.wait()
|
||||
until GameIsLoaded
|
||||
|
||||
local HumanoidRPSettings = require(script:WaitForChild("HumanoidRootPart"))
|
||||
local CameraModule = require(script:WaitForChild("Camera"))
|
||||
local HumanoidModule = require(script:WaitForChild("Humanoid"))
|
||||
local SpineModule = require(script:WaitForChild("SpineKinematics"))
|
||||
local ActionsModule = require(script:WaitForChild("Actions"))
|
||||
local BindModule = require(ClientStorage:WaitForChild("KeyBinds"))
|
||||
|
||||
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
|
||||
local Humanoid = Character:WaitForChild("Humanoid")
|
||||
local CurrentCamera = workspace.CurrentCamera
|
||||
|
||||
local HRPSettings = HumanoidRPSettings.constructor(HumanoidRootPart)
|
||||
local CameraConsturctor = CameraModule.constructor(CurrentCamera, HumanoidRootPart, Humanoid)
|
||||
local HumanoidSettings = HumanoidModule.constructor(Humanoid)
|
||||
local SpineMovement = SpineModule.constructor(CurrentCamera)
|
||||
|
||||
local ClientBindMap = BindModule.constructor(false)
|
||||
|
||||
local function ClientCharacterBinds()
|
||||
local Actions = ActionsModule.constructor(HumanoidSettings, CurrentCamera, ActionsTCP)
|
||||
|
||||
--Crouch
|
||||
ClientBindMap:AddInputBegan({Enum.KeyCode.RightControl, Enum.KeyCode.LeftControl}, function(_KeyPressed)
|
||||
Actions:EnableCrouch()
|
||||
end)
|
||||
ClientBindMap:AddInputEnded({Enum.KeyCode.RightControl, Enum.KeyCode.LeftControl}, function(_KeyPressed)
|
||||
Actions:DisableCrouch()
|
||||
end)
|
||||
|
||||
--Walk
|
||||
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,
|
||||
Enum.KeyCode.LeftShift,
|
||||
Enum.KeyCode.RightShift
|
||||
}, function(_KeyPressed)
|
||||
Actions:DisableSneak()
|
||||
end)
|
||||
|
||||
--Flashlight
|
||||
ClientBindMap:AddInputBegan({Enum.KeyCode.F}, function(KeyPressed: Enum.KeyCode)
|
||||
Actions:ToggleFlashlight(KeyPressed)
|
||||
end)
|
||||
end
|
||||
|
||||
--Needs to be a module maybe
|
||||
local function Crosshair3DVelocity_Effect(): RBXScriptConnection
|
||||
local RootVelocity = ClientStorage:WaitForChild("RootVelocity") :: BindableEvent
|
||||
|
||||
local RootVelocityStep = RS.Heartbeat:ConnectParallel(function(_dt)
|
||||
RootVelocity:Fire(HRPSettings:Velocity())
|
||||
end)
|
||||
return RootVelocityStep
|
||||
end
|
||||
|
||||
HumanoidSettings:SetWalkSpeed()
|
||||
HumanoidSettings:SetJumpHeight()
|
||||
HRPSettings:DisableRobloxSounds()
|
||||
CameraConsturctor:EnableBobbing()
|
||||
--SpineMovement:Enable()
|
||||
|
||||
ClientCharacterBinds()
|
||||
Crosshair3DVelocity_Effect()
|
||||
|
||||
_G.include = nil
|
||||
@@ -3,21 +3,26 @@
|
||||
--!strict
|
||||
|
||||
type UDP = UnreliableRemoteEvent
|
||||
|
||||
local Dir = script.Parent
|
||||
local Character = Dir.Parent
|
||||
local preprocessor = {}
|
||||
|
||||
local FlashlightCooldown = .10
|
||||
type CharacterSharedFolder = Folder
|
||||
|
||||
local Players = game:GetService("Players")
|
||||
|
||||
--Create the character shared directory here
|
||||
local CharacterShared = Instance.new("Folder")
|
||||
CharacterShared.Name = "shared"
|
||||
CharacterShared.Parent = Dir
|
||||
local Dir = script.Parent
|
||||
local Character = Dir.Parent
|
||||
local preprocessor = {}
|
||||
|
||||
--Production--
|
||||
--if not RS:IsStudio() then
|
||||
task.wait()
|
||||
Dir.Parent = nil
|
||||
--end
|
||||
--
|
||||
|
||||
--Create the character shared directory here
|
||||
local CharacterShared = Instance.new("Folder")
|
||||
CharacterShared.Name = "shared"
|
||||
CharacterShared.Parent = Character
|
||||
|
||||
type CharacterSharedFolder = Folder
|
||||
function preprocessor.CharacterShared(): Instance
|
||||
return CharacterShared :: CharacterSharedFolder
|
||||
end
|
||||
@@ -58,6 +63,8 @@ Character.DescendantAdded:Connect(function(Instance)
|
||||
CharacterShadows:PartToggle(Instance, false)
|
||||
end)
|
||||
|
||||
local FlashlightCooldown = .10
|
||||
|
||||
Actions:Add(Enum.KeyCode.F, function(_KeyPressed)
|
||||
if not FlashlightDebounce then
|
||||
Flashlight:Toggle()
|
||||
|
||||
125
src/client/Player/Character/init.lua
Normal file
125
src/client/Player/Character/init.lua
Normal file
@@ -0,0 +1,125 @@
|
||||
--!optimize 2
|
||||
--!native
|
||||
--!strict
|
||||
|
||||
type CharacterSharedFolder = Folder
|
||||
type TCP = RemoteEvent
|
||||
|
||||
local CharacterModule = {}
|
||||
CharacterModule.__index = CharacterModule
|
||||
|
||||
local RS = game:GetService("RunService")
|
||||
local Storage = game:GetService("ReplicatedStorage")
|
||||
|
||||
local ClientStorage = Storage:WaitForChild("Client") :: Folder
|
||||
|
||||
local preprocessor = {}
|
||||
local CharacterShared: Folder
|
||||
|
||||
function preprocessor.CharacterShared(): CharacterSharedFolder
|
||||
return CharacterShared
|
||||
end
|
||||
|
||||
_G.include = function(this: LuaSourceContainer, FunName: string, ...)
|
||||
if this:IsDescendantOf(script) then --getfenv is being removed
|
||||
local switch = preprocessor[FunName]
|
||||
return type(switch) == "function" and switch(...) or switch
|
||||
else
|
||||
warn(`Preprocessor append failed "{FunName}"`, debug.traceback())
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
function CharacterModule.constructor(Character)
|
||||
CharacterShared = Character:WaitForChild("shared")
|
||||
|
||||
local HumanoidRPSettings = require(script:WaitForChild("HumanoidRootPart"))
|
||||
local CameraModule = require(script:WaitForChild("Camera"))
|
||||
local HumanoidModule = require(script:WaitForChild("Humanoid"))
|
||||
local SpineModule = require(script:WaitForChild("SpineKinematics"))
|
||||
|
||||
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
|
||||
local Humanoid = Character:WaitForChild("Humanoid")
|
||||
|
||||
local self = {}
|
||||
self.ActionsTCP = CharacterShared:WaitForChild("Actions")
|
||||
self.ActionsModule = require(script:WaitForChild("Actions"))
|
||||
self.BindModule = require(ClientStorage:WaitForChild("KeyBinds"))
|
||||
|
||||
self.CurrentCamera = workspace.CurrentCamera
|
||||
self.HRPSettings = HumanoidRPSettings.constructor(HumanoidRootPart)
|
||||
self.CameraConsturctor = CameraModule.constructor(self.CurrentCamera, HumanoidRootPart, Humanoid)
|
||||
self.HumanoidSettings = HumanoidModule.constructor(Humanoid)
|
||||
self.SpineMovement = SpineModule.constructor(self.CurrentCamera)
|
||||
|
||||
return setmetatable(self, CharacterModule)
|
||||
end
|
||||
|
||||
function CharacterModule:CharacterKeyBinds()
|
||||
local ClientBindMap = self.BindModule.constructor(false)
|
||||
local Actions = self.ActionsModule.constructor(self.HumanoidSettings, self.CurrentCamera, self.ActionsTCP)
|
||||
|
||||
--Crouch
|
||||
ClientBindMap:AddInputBegan({Enum.KeyCode.RightControl, Enum.KeyCode.LeftControl}, function(_KeyPressed)
|
||||
Actions:EnableCrouch()
|
||||
end)
|
||||
ClientBindMap:AddInputEnded({Enum.KeyCode.RightControl, Enum.KeyCode.LeftControl}, function(_KeyPressed)
|
||||
Actions:DisableCrouch()
|
||||
end)
|
||||
|
||||
--Walk
|
||||
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,
|
||||
Enum.KeyCode.LeftShift,
|
||||
Enum.KeyCode.RightShift
|
||||
}, function(_KeyPressed)
|
||||
Actions:DisableSneak()
|
||||
end)
|
||||
|
||||
--Flashlight
|
||||
ClientBindMap:AddInputBegan({Enum.KeyCode.F}, function(KeyPressed: Enum.KeyCode)
|
||||
Actions:ToggleFlashlight(KeyPressed)
|
||||
end)
|
||||
end
|
||||
|
||||
function CharacterModule:Crosshair()
|
||||
local RootVelocity = ClientStorage:WaitForChild("RootVelocity") :: BindableEvent
|
||||
|
||||
local RootVelocityStep = RS.Heartbeat:ConnectParallel(function(_dt)
|
||||
RootVelocity:Fire(self.HRPSettings:Velocity())
|
||||
end)
|
||||
return RootVelocityStep
|
||||
end
|
||||
|
||||
function CharacterModule:SetWalkSpeed()
|
||||
self.HumanoidSettings:SetWalkSpeed()
|
||||
end
|
||||
|
||||
function CharacterModule:SetJumpHeight()
|
||||
self.HumanoidSettings:SetJumpHeight()
|
||||
end
|
||||
|
||||
function CharacterModule:DisableRobloxSounds()
|
||||
self.HRPSettings:DisableRobloxSounds()
|
||||
end
|
||||
|
||||
function CharacterModule:EnableCameraBobbing()
|
||||
self.CameraConsturctor:EnableBobbing()
|
||||
end
|
||||
|
||||
function CharacterModule:EnableSpineMovement()
|
||||
self.SpineMovement:Enable()
|
||||
end
|
||||
|
||||
_G.include = nil
|
||||
|
||||
return CharacterModule
|
||||
@@ -2,40 +2,65 @@
|
||||
--!native
|
||||
--!strict
|
||||
|
||||
type CurrentCamera = Camera
|
||||
|
||||
local Players = game:GetService("Players")
|
||||
local Storage = game:GetService("ReplicatedStorage")
|
||||
local RS = game:GetService("RunService")
|
||||
|
||||
--Production--
|
||||
--if not RS:IsStudio() then
|
||||
RS.RenderStepped:Wait()
|
||||
script.Parent.Parent = nil
|
||||
--end
|
||||
--
|
||||
|
||||
local UI = script:WaitForChild("UI")
|
||||
local CrosshairSettings = require(UI:WaitForChild("Crosshair"))
|
||||
local VignetteSettings = require(UI:WaitForChild("Vignette"))
|
||||
local HealthSettings = require(UI:WaitForChild("Health"))
|
||||
local CoreGuis = require(script:WaitForChild("CoreGuis"))
|
||||
local Mouse = require(script:WaitForChild("Mouse"))
|
||||
local Character = require(script:WaitForChild("Character"))
|
||||
|
||||
local Players: Players = game:GetService("Players")
|
||||
local Storage: ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
|
||||
local ClientStorage = Storage:WaitForChild("Client")
|
||||
local LoadCompleted = ClientStorage:WaitForChild("LoadingComplete")
|
||||
local KeyBindsModule = require(ClientStorage:WaitForChild("KeyBinds"))
|
||||
local CameraSettings = require(ClientStorage:WaitForChild("Camera"))
|
||||
|
||||
local Player = Players.LocalPlayer
|
||||
local PlayerGui = Player:WaitForChild("PlayerGui") :: PlayerGui
|
||||
local function LoadCharacter(CharacterModel)
|
||||
local CharacterConstructor = Character.constructor(CharacterModel)
|
||||
|
||||
CharacterConstructor:DisableRobloxSounds()
|
||||
CharacterConstructor:SetWalkSpeed()
|
||||
CharacterConstructor:SetJumpHeight()
|
||||
CharacterConstructor:Crosshair()
|
||||
CharacterConstructor:EnableCameraBobbing()
|
||||
CharacterConstructor:CharacterKeyBinds()
|
||||
end
|
||||
|
||||
--We need to wait for the game to load before spamming functionality
|
||||
repeat
|
||||
local GameIsLoaded = (LoadCompleted :: BindableFunction):Invoke()
|
||||
local GameIsLoaded = game:IsLoaded()
|
||||
task.wait()
|
||||
until GameIsLoaded
|
||||
|
||||
local CurrentCamera = nil
|
||||
local CurrentCamera: CurrentCamera
|
||||
repeat
|
||||
task.wait()
|
||||
CurrentCamera = workspace.CurrentCamera
|
||||
until CurrentCamera
|
||||
|
||||
local ClientStorage = Storage:WaitForChild("Client")
|
||||
local KeyBindsModule = require(ClientStorage:WaitForChild("KeyBinds"))
|
||||
local CameraSettings = require(ClientStorage:WaitForChild("Camera"))
|
||||
|
||||
local Player = Players.LocalPlayer
|
||||
local PlayerGui = Player:WaitForChild("PlayerGui") :: PlayerGui
|
||||
local PlayerCharacter = Player.Character or Player.CharacterAdded:Wait()
|
||||
|
||||
local Vignette = VignetteSettings.constructor(PlayerGui)
|
||||
local Camera = CameraSettings.constructor(CurrentCamera, Player)
|
||||
local Crosshair = CrosshairSettings.constructor(PlayerGui)
|
||||
|
||||
LoadCharacter(PlayerCharacter)
|
||||
Player.CharacterAdded:Connect(LoadCharacter)
|
||||
|
||||
--Keybinds
|
||||
local function CameraBinds()
|
||||
local CameraBindMap = KeyBindsModule.constructor(false)
|
||||
|
||||
Reference in New Issue
Block a user