mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-14 06:41:55 +00:00
actions module
This commit is contained in:
@@ -2,25 +2,120 @@
|
||||
--!native
|
||||
--!strict
|
||||
|
||||
local Actions = {
|
||||
ActionCurrent = false,
|
||||
Walk = 10,
|
||||
Sneaking = 10/2 --10 is default
|
||||
}
|
||||
local Actions = {}
|
||||
Actions.__index = Actions
|
||||
|
||||
function Actions.constructor(HumanoidSettingsInherent, Humanoid: Humanoid)
|
||||
--Sneak static properties
|
||||
Actions.DoingAction = false
|
||||
Actions.Sneaking = false
|
||||
Actions.Crouching = false
|
||||
Actions.Walk = 10
|
||||
Actions.SneakingSpeed = 10/2 --10 is default
|
||||
--Crouch static properties
|
||||
Actions.Crouching = false
|
||||
Actions.StandHeight = 2.1
|
||||
Actions.CrouchHeight = .6
|
||||
Actions.WalkSpeedMultiplier = 6
|
||||
Actions.CrouchSpeed = .2
|
||||
--Flashlight static properties
|
||||
Actions.FlashlightEnabled = false
|
||||
|
||||
local CharacterShared = _G.include(script, "CharacterShared")
|
||||
local FlashlightRemote = CharacterShared:WaitForChild("Flashlight")
|
||||
|
||||
local Storage = game:GetService("ReplicatedStorage")
|
||||
local RS = game:GetService("RunService")
|
||||
|
||||
local Tween = require(Storage:WaitForChild("Tween"))
|
||||
local Delta = require(Storage:WaitForChild("Delta"))
|
||||
|
||||
type inherented = any
|
||||
|
||||
function Actions.constructor(HumanoidSettings: inherented, Humanoid: Humanoid, CurrentCamera: Camera)
|
||||
return setmetatable({
|
||||
Humanoid = Humanoid,
|
||||
HumanoidSettingsInherent = HumanoidSettingsInherent
|
||||
HumanoidSettings = HumanoidSettings,
|
||||
CurrentCamera = CurrentCamera
|
||||
}, Actions)
|
||||
end
|
||||
|
||||
function Actions:Enable()
|
||||
self.HumanoidSettingsInherent:SetWalkSpeed(Actions.Sneaking)
|
||||
function Actions:EnableSneak()
|
||||
Actions.DoingAction = true
|
||||
Actions.Sneaking = true
|
||||
self.HumanoidSettings:SetWalkSpeed(Actions.SneakingSpeed)
|
||||
end
|
||||
|
||||
function Actions:Disable()
|
||||
self.HumanoidSettingsInherent:SetWalkSpeed(Actions.Walk)
|
||||
function Actions:DisableSneak()
|
||||
Actions.DoingAction = false
|
||||
Actions.Sneaking = false
|
||||
self.HumanoidSettings:SetWalkSpeed(Actions.Walk)
|
||||
end
|
||||
|
||||
local CrouchTween = Tween.constructor()
|
||||
|
||||
function Actions:EnableCrouch(StandingWalkSpeed: number)
|
||||
Actions.DoingAction = true
|
||||
Actions.Crouching = true
|
||||
|
||||
local Easing = TweenInfo.new(Actions.CrouchSpeed, Enum.EasingStyle.Linear)
|
||||
|
||||
CrouchTween:Start(self.Humanoid, {
|
||||
HipHeight = Actions.CrouchHeight,
|
||||
WalkSpeed = math.max(1, StandingWalkSpeed-Actions.WalkSpeedMultiplier)
|
||||
}, Easing)
|
||||
end
|
||||
|
||||
function Actions:DisableCrouch(CrouchingWalkSpeed: number)
|
||||
Actions.DoingAction = false
|
||||
Actions.Crouching = false
|
||||
|
||||
local Easing = TweenInfo.new(Actions.CrouchSpeed, Enum.EasingStyle.Linear)
|
||||
|
||||
CrouchTween:Start(self.Humanoid, {
|
||||
HipHeight = Actions.StandHeight,
|
||||
WalkSpeed = math.max(1, CrouchingWalkSpeed+Actions.WalkSpeedMultiplier)
|
||||
}, Easing)
|
||||
end
|
||||
|
||||
function Actions:EnableFlashlight()
|
||||
Actions.FlashlightEnabled = true
|
||||
|
||||
task.spawn(function()
|
||||
while Actions.FlashlightEnabled do
|
||||
|
||||
Delta:time()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function Actions:DisableFlashlight()
|
||||
Actions.FlashlightEnabled = false
|
||||
end
|
||||
|
||||
function Actions:EnableFlashlight()
|
||||
if Actions.FlashlightEnabled then
|
||||
|
||||
else
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
function Actions:ToggleCrouch()
|
||||
if not Actions.DoingAction then
|
||||
if Actions.Crouching then
|
||||
self:DisableCrouch()
|
||||
else
|
||||
self:EnableCrouch()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Actions:ToggleSneak()
|
||||
if not Actions.DoingAction then
|
||||
if Actions.Sneaking then
|
||||
self:DisableSneak()
|
||||
else
|
||||
self:EnableSneak()
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,3 +1,7 @@
|
||||
--!optimize 2
|
||||
--!native
|
||||
--!strict
|
||||
|
||||
local Bobbing = {}
|
||||
Bobbing.__index = Bobbing
|
||||
|
||||
@@ -84,8 +88,7 @@ local function CameraAnimation(self, dt: deltatime)
|
||||
|
||||
--go go boolean algebra
|
||||
local MaxMinY: boolean = Camera_YArc(self.CurrentCamera)>Bobbing.MaxGimbalLockY --TODO: instead, make this an equation so it will just subtract from the existing animation radians
|
||||
local ForceStop: boolean = Bobbing.ForceStop and "Stop"
|
||||
local AnimationType: string = ForceStop or RootMagnitude>1 and "Walk" or (not MaxMinY and "Idle" or "Stop")
|
||||
local AnimationType: string = Bobbing.ForceStop and "Stop" or RootMagnitude>1 and "Walk" or (not MaxMinY and "Idle" or "Stop")
|
||||
local CurrentAnimation: CFrame = Animations[AnimationType](Bobbing.Tick, dt)
|
||||
|
||||
--"Lerp" so the transitions between walking and idling are smoothed instead of instant
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
--!optimize 2
|
||||
--!native
|
||||
--!strict
|
||||
|
||||
local Camera = {}
|
||||
local FakeCamera = {}
|
||||
Camera.__index = Camera
|
||||
@@ -35,7 +39,7 @@ function Camera:DisableBobbing()
|
||||
else
|
||||
print("Character Camera: DisableBobbing was called before EnableBobbing", debug.traceback())
|
||||
end
|
||||
self.CurrentCamera.CFrame *= CFrame.Angles(0,0,0)
|
||||
(self.CurrentCamera :: Camera).CFrame *= CFrame.Angles(0,0,0)
|
||||
end
|
||||
|
||||
return Camera
|
||||
@@ -1,44 +0,0 @@
|
||||
--!optimize 2
|
||||
--!native
|
||||
--!strict
|
||||
|
||||
local CrouchModule = {
|
||||
IsCrouching = false,
|
||||
StandHeight = 2.1,
|
||||
CrouchHeight = .6,
|
||||
WalkSpeedMultiplier = 6,
|
||||
CrouchSpeed = .2
|
||||
}
|
||||
CrouchModule.__index = CrouchModule
|
||||
|
||||
local Tween = require(game:GetService("ReplicatedStorage"):WaitForChild("Tween"))
|
||||
|
||||
function CrouchModule.constructor(Humanoid: Humanoid)
|
||||
return setmetatable({
|
||||
Humanoid = Humanoid
|
||||
}, CrouchModule)
|
||||
end
|
||||
|
||||
local CrouchTween = Tween.constructor()
|
||||
|
||||
function CrouchModule:Crouch(StandingWalkSpeed: number)
|
||||
local Easing = TweenInfo.new(CrouchModule.CrouchSpeed, Enum.EasingStyle.Linear)
|
||||
|
||||
CrouchTween:Start(self.Humanoid, {
|
||||
HipHeight = CrouchModule.CrouchHeight,
|
||||
WalkSpeed = math.max(1, StandingWalkSpeed-CrouchModule.WalkSpeedMultiplier)
|
||||
}, Easing)
|
||||
CrouchModule.IsCrouching = true
|
||||
end
|
||||
|
||||
function CrouchModule:Stand(CrouchingWalkSpeed: number)
|
||||
local Easing = TweenInfo.new(CrouchModule.CrouchSpeed, Enum.EasingStyle.Linear)
|
||||
|
||||
CrouchTween:Start(self.Humanoid, {
|
||||
HipHeight = CrouchModule.StandHeight,
|
||||
WalkSpeed = math.max(1, CrouchingWalkSpeed+CrouchModule.WalkSpeedMultiplier)
|
||||
}, Easing)
|
||||
CrouchModule.IsCrouching = false
|
||||
end
|
||||
|
||||
return CrouchModule
|
||||
@@ -1,19 +0,0 @@
|
||||
--!optimize 2
|
||||
--!native
|
||||
--!strict
|
||||
|
||||
local Flashlight = {}
|
||||
Flashlight.__index = Flashlight
|
||||
|
||||
local CharacterShared = _G.include(script, "CharacterShared")
|
||||
local FlashlightRemote = CharacterShared:WaitForChild("Flashlight")
|
||||
|
||||
function Flashlight.constructor()
|
||||
return setmetatable({}, Flashlight)
|
||||
end
|
||||
|
||||
function Flashlight:Toggle()
|
||||
FlashlightRemote:FireServer()
|
||||
end
|
||||
|
||||
return Flashlight
|
||||
@@ -21,14 +21,13 @@ type struct_Spine = {
|
||||
Remote: UnreliableRemoteEvent,
|
||||
CurrentCamera: CurrentCamera
|
||||
}
|
||||
|
||||
type CharacterSharedFolder = Folder
|
||||
|
||||
function Spine.constructor(CurrentCamera: CurrentCamera)
|
||||
local self = {} :: struct_Spine
|
||||
self.Remote = CharacterShared:WaitForChild("SpineStream")
|
||||
self.CurrentCamera = CurrentCamera
|
||||
return setmetatable(self, Spine)
|
||||
return setmetatable({
|
||||
Remote = CharacterShared:WaitForChild("SpineStream"),
|
||||
CurrentCamera = CurrentCamera
|
||||
}, Spine)
|
||||
end
|
||||
|
||||
function Spine:Enable()
|
||||
|
||||
@@ -49,7 +49,6 @@ local HRPSettings = HumanoidRPSettings.constructor(HumanoidRootPart)
|
||||
local CameraConsturctor = CameraModule.constructor(CurrentCamera, HumanoidRootPart, Humanoid)
|
||||
local HumanoidSettings = HumanoidModule.constructor(Humanoid)
|
||||
local SpineMovement = SpineModule.constructor(CurrentCamera)
|
||||
local Flashlight = FlashlightModule.constructor()
|
||||
|
||||
local ClientBindMap = BindModule.constructor(false)
|
||||
|
||||
@@ -105,4 +104,6 @@ SpineMovement:Enable()
|
||||
|
||||
ClientCharacterBinds()
|
||||
Crosshair3DVelocity_Effect()
|
||||
FlashlightToggle()
|
||||
FlashlightToggle()
|
||||
|
||||
_G.include = nil
|
||||
@@ -5,7 +5,7 @@
|
||||
local Flashlight = {}
|
||||
Flashlight.__index = Flashlight
|
||||
|
||||
local Remote = Instance.new("RemoteEvent") :: RemoteEvent
|
||||
local Remote = Instance.new("UnreliableRemoteEvent") :: UnreliableRemoteEvent
|
||||
Remote.Name = "Flashlight"
|
||||
Remote.Parent = _G.include(script, "CharacterShared")
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ _G.include = function(this: LuaSourceContainer, FunName: string, ...)
|
||||
return type(switch) == "function" and switch(...) or switch
|
||||
else
|
||||
warn(`Preprocessor append failed "{FunName}"`, debug.traceback())
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -48,4 +48,4 @@ end
|
||||
|
||||
LoadedBind()
|
||||
|
||||
ReplicatedFirst:RemoveDefaultLoadingScreen()
|
||||
ReplicatedFirst:RemoveDefaultLoadingScreen()
|
||||
|
||||
Reference in New Issue
Block a user