mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-18 03:21:54 +00:00
Server character restructure
This commit is contained in:
91
src/server/main/Characters/init.lua
Normal file
91
src/server/main/Characters/init.lua
Normal file
@@ -0,0 +1,91 @@
|
||||
--!optimize 2
|
||||
--!native
|
||||
--!strict
|
||||
|
||||
type UDP = UnreliableRemoteEvent
|
||||
type CharacterSharedFolder = Folder
|
||||
|
||||
local Players = game:GetService("Players")
|
||||
|
||||
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
|
||||
|
||||
function preprocessor.CharacterShared(): Instance
|
||||
return CharacterShared :: CharacterSharedFolder
|
||||
end
|
||||
|
||||
_G.include = function(this: LuaSourceContainer, FunName: string, ...)
|
||||
--its not extremely necessary to have this security on the server-side
|
||||
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 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")
|
||||
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
|
||||
|
||||
local LocalPlayer = Players:GetPlayerFromCharacter(Character)
|
||||
|
||||
local CharacterShadows = Shadows.constructor(Character)
|
||||
local Spine = SpineModule.constructor(Head, UpperTorso)
|
||||
local Flashlight = FlashlightModule.constructor(LocalPlayer, HumanoidRootPart)
|
||||
local Actions = ActionsModule.constructor(LocalPlayer, HumanoidRootPart)
|
||||
|
||||
local FlashlightDebounce = false
|
||||
|
||||
CharacterShadows:off() --I plan having 2 player support and characters block a ton of light
|
||||
|
||||
Character.DescendantAdded:Connect(function(Instance)
|
||||
task.wait() --Wait for the instance to properly replicate?
|
||||
CharacterShadows:PartToggle(Instance, false)
|
||||
end)
|
||||
|
||||
local FlashlightCooldown = .10
|
||||
|
||||
Actions:Add(Enum.KeyCode.F, function(_KeyPressed)
|
||||
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 SpineModule.Enabled then
|
||||
Spine:Move(CameraPosition, IsFirstPerson)
|
||||
else
|
||||
--reset
|
||||
print("TODO reached -", script.Name..".lua")
|
||||
end
|
||||
else
|
||||
Messenger:Kick(`"{Messenger.Name}", {Messenger.UserId} r="{Spine.Remote.Name}", 1="{tostring(CameraPosition)}", 2="{tostring(IsFirstPerson)}"`)
|
||||
end
|
||||
end)
|
||||
|
||||
_G.include = nil
|
||||
Reference in New Issue
Block a user