mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-15 23:01:55 +00:00
Server character restructure
This commit is contained in:
125
src/client/Character/init.lua
Normal file
125
src/client/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
|
||||
Reference in New Issue
Block a user