Actor support

This commit is contained in:
2024-02-21 13:23:23 -05:00
parent ff16d8ceb3
commit e5f1a546b1
21 changed files with 284 additions and 73 deletions

View File

@@ -0,0 +1,15 @@
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

View File

@@ -18,4 +18,8 @@ function HumanoidRPSettings:DisableRobloxSounds()
end
end
function HumanoidRPSettings:Velocity()
return self.HumanoidRootPart:GetVelocityAtPosition(self.HumanoidRootPart.Position)
end
return HumanoidRPSettings

View File

@@ -21,7 +21,7 @@ type struct_Spine = {
type CharacterSharedFolder = Folder
function Spine.constructor(CurrentCamera: CurrentCamera)
local self: struct_Spine = {}
local self = {} :: struct_Spine
self.Remote = CharacterShared:WaitForChild("SpineStream")
self.CurrentCamera = CurrentCamera
return setmetatable(self, Spine)

View File

@@ -1,10 +1,10 @@
local Character = script.Parent
local Character = script.Parent.Parent
local preprocessor = {}
type CharacterSharedFolder = Folder
function preprocessor.CharacterShared(): CharacterSharedFolder
return script.Parent:WaitForChild("shared")
return Character:WaitForChild("shared")
end
_G.include = function(this: LuaSourceContainer, FunName: string, ...)
@@ -17,6 +17,8 @@ _G.include = function(this: LuaSourceContainer, FunName: string, ...)
end
local Storage = game:GetService("ReplicatedStorage")
local RS = game:GetService("RunService") :: RunService
local ClientStorage = Storage:WaitForChild("Client")
local LoadCompleted = ClientStorage:WaitForChild("LoadingComplete")
@@ -31,6 +33,7 @@ local CameraModule = require(script:WaitForChild("Camera"))
local CrouchModule = require(script:WaitForChild("Crouch"))
local HumanoidModule = require(script:WaitForChild("Humanoid"))
local SpineModule = require(script:WaitForChild("SpineKinematics"))
local FlashlightModule = require(script:WaitForChild("Flashlight"))
local BindModule = require(ClientStorage:WaitForChild("KeyBinds"))
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
@@ -41,33 +44,54 @@ 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 Walking = 10/2 --10 is default
local ClientBindMap = BindModule.constructor(false)
local function ClientCharacterBinds()
local CrouchConstructor = CrouchModule.constructor(Humanoid)
local BindMap = BindModule.constructor()
--Crouch
BindMap:AddInputBegan({Enum.KeyCode.RightControl, Enum.KeyCode.LeftControl}, function()
ClientBindMap:AddInputBegan({Enum.KeyCode.RightControl, Enum.KeyCode.LeftControl}, function()
CrouchConstructor:Crouch(10)
end)
BindMap:AddInputEnded({Enum.KeyCode.RightControl, Enum.KeyCode.LeftControl}, function()
ClientBindMap:AddInputEnded({Enum.KeyCode.RightControl, Enum.KeyCode.LeftControl}, function()
CrouchConstructor:Stand(5)
end)
--Walk
BindMap:AddInputBegan({Enum.KeyCode.LeftShift, Enum.KeyCode.RightShift}, function()
ClientBindMap:AddInputBegan({Enum.KeyCode.LeftShift, Enum.KeyCode.RightShift}, function()
HumanoidSettings:SetWalkSpeed(Walking)
end)
BindMap:AddInputEnded({Enum.KeyCode.LeftShift, Enum.KeyCode.RightShift}, function()
ClientBindMap:AddInputEnded({Enum.KeyCode.LeftShift, Enum.KeyCode.RightShift}, function()
HumanoidSettings:SetWalkSpeed(10)
end)
end
local function Crosshair3DVelocity_Effect(): RBXScriptSignal
local RootVelocity = ClientStorage:WaitForChild("RootVelocity") :: BindableEvent
local RootVelocitySteps = RS.Heartbeat:ConnectParallel(function(_dt)
RootVelocity:Fire(HRPSettings:Velocity())
end)
return RootVelocitySteps
end
local function FlashlightToggle()
ClientBindMap:AddInputBegan({Enum.KeyCode.F}, function()
Flashlight:Toggle()
end)
end
local function HealthChangeBind()
end
HumanoidSettings:SetWalkSpeed()
HumanoidSettings:SetJumpHeight()
HRPSettings:DisableRobloxSounds()
CameraConsturctor:EnableBobbing()
SpineMovement:Enable()
ClientCharacterBinds()
ClientCharacterBinds()
Crosshair3DVelocity_Effect()
FlashlightToggle()

View File

@@ -0,0 +1,68 @@
local Flashlight = {}
Flashlight.__index = Flashlight
local Remote = Instance.new("RemoteEvent") :: RemoteEvent
Remote.Name = "Flashlight"
Remote.Parent = _G.include(script, "CharacterShared")
function Flashlight.constructor(Head: BasePart)
local FlashlightPart = Instance.new("Part") :: Part
FlashlightPart.Size = Vector3.new(.1,.1,.1)
FlashlightPart.CFrame = Head.CFrame+Vector3.yAxis
FlashlightPart.CanCollide = false
FlashlightPart.CastShadow = false
FlashlightPart.Transparency = 1
local SpotLight = Instance.new("SpotLight") :: SpotLight
SpotLight.Color = Color3.new(1,1,1)
SpotLight.Angle = 80
SpotLight.Range = 30
SpotLight.Brightness = 1
SpotLight.Shadows = true
SpotLight.Enabled = false
SpotLight.Parent = FlashlightPart
local Weld = Instance.new("WeldConstraint") :: WeldConstraint
Weld.Part0 = Head
Weld.Part1 = FlashlightPart
Weld.Parent = FlashlightPart
FlashlightPart.Anchored = false
FlashlightPart.Parent = Head
local ToggleSound = Instance.new("Sound") :: Sound
ToggleSound.SoundId = "rbxassetid://16454678462"
ToggleSound.Volume = .5
ToggleSound.Parent = Head
return setmetatable({
SpotLight = SpotLight,
ToggleSound = ToggleSound,
Remote = Remote
}, Flashlight)
end
local FlashlightEnabled = false
function Flashlight:On()
FlashlightEnabled = true
self.ToggleSound:Play()
self.SpotLight.Enabled = FlashlightEnabled
end
function Flashlight:Off()
FlashlightEnabled = false
self.ToggleSound:Play()
self.SpotLight.Enabled = FlashlightEnabled
end
function Flashlight:Toggle()
-- FlashlightEnabled = not FlashlightEnabled
if FlashlightEnabled then
self:Off()
else
self:On()
end
end
return Flashlight

View File

@@ -25,7 +25,7 @@ Remote.Name = "SpineStream"
Remote.Parent = _G.include(script, "CharacterShared")
function Spine.constructor(Head: Head, UpperTorso: UpperTorso)
local self: struct_Spine = {}
local self = {} :: struct_Spine
self.Head = Head
self.UpperTorso = UpperTorso
self.Neck = Head:WaitForChild("Neck")

View File

@@ -1,4 +1,4 @@
local Character = script.Parent
local Character = script.Parent.Parent
local preprocessor = {}
--Create the character shared directory here
@@ -12,7 +12,7 @@ function preprocessor.CharacterShared(): CharacterSharedFolder
end
_G.include = function(this: LuaSourceContainer, FunName: string, ...)
--its not extremely necessary to have security for the server-side
--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
@@ -23,8 +23,9 @@ end
local Players = game:GetService("Players")
local Shadows = require(script:WaitForChild("Shadows"))
local SpineModule = require(script:WaitForChild("SpineKinematics"))
local Shadows = require(script:WaitForChild("Shadows"))
local SpineModule = require(script:WaitForChild("SpineKinematics"))
local FlashlightModule = require(script:WaitForChild("Flashlight"))
local Head = Character:WaitForChild("Head")
local UpperTorso = Character:WaitForChild("UpperTorso")
@@ -33,6 +34,7 @@ local LocalPlayer = Players:GetPlayerFromCharacter(Character)
local CharacterShadows = Shadows.constructor(Character)
local Spine = SpineModule.constructor(Head, UpperTorso)
local Flashlight = FlashlightModule.constructor(Head)
CharacterShadows:off() --I plan having 2 player support and characters block a ton of light
@@ -41,12 +43,27 @@ Character.DescendantAdded:Connect(function(Instance)
CharacterShadows:PartToggle(Instance, false)
end)
Spine.Remote.OnServerEvent:Connect(function(Messenger: Player, CameraPosition: Vector3, IsFirstPerson: boolean)
Spine.Remote.OnServerEvent:Connect(function(Messenger: Player, CameraPosition: CFrame, IsFirstPerson: boolean)
if Messenger.UserId == LocalPlayer.UserId then
if Spine.Enabled then
Spine:Move(CameraPosition, IsFirstPerson)
else
--reset
print("TODO reached -", script.Name..".lua")
end
end
end)
local FlashlightDebounce = false
Flashlight.Remote.OnServerEvent:Connect(function(Messenger: Player)
if Messenger.UserId == LocalPlayer.UserId then
if not FlashlightDebounce then
Flashlight:Toggle()
FlashlightDebounce = true
task.wait(.10)
FlashlightDebounce = false
end
else
warn("hacker")
end
end)

View File

@@ -3,6 +3,9 @@ local CrosshairModule = {
}
CrosshairModule.__index = CrosshairModule
local Storage = game:GetService("ReplicatedStorage")
local Easings = require(Storage:WaitForChild("AlgebraEasings"))
--Use a custom crosshair so we can do effects to it
type rbxassetid = string
@@ -17,15 +20,24 @@ function CrosshairModule.constructor(PlayerGui: PlayerGui)
end
function CrosshairModule:Enable()
self.Screen.Enabled = true
(self.Screen :: ScreenGui).Enabled = true
end
function CrosshairModule:Disable()
self.Screen.Enabled = false
(self.Screen :: ScreenGui).Enabled = false
end
function CrosshairModule:Change(ID: rbxassetid)
self.Icon.Image = ID or CrosshairModule.Icon
(self.Icon :: ImageLabel).Image = ID or CrosshairModule.Icon
end
function CrosshairModule:Jump(RootVelocity: Vector3)
local X, Y = RootVelocity.X, RootVelocity.Y;
(self.Icon :: ImageLabel).Position = UDim2.fromScale(
Y>1 and Easings.Linear(.5,.5+(X/1000),.3) or .5,
math.clamp(.4, .5-(-Y/1000), .6)
)
end
return CrosshairModule

View File

@@ -0,0 +1,34 @@
local HealthModule = {}
HealthModule.__index = HealthModule
function HealthModule.constructor(PlayerGui: PlayerGui)
local HealthGui = PlayerGui:WaitForChild("Health")
local Amount = HealthGui:WaitForChild("Amount")
return setmetatable({
HealthGui = HealthGui,
Amount = Amount
}, HealthGui)
end
function HealthModule:Enable()
HealthModule.Enabled = true
end
function HealthModule:Disable()
HealthModule.Enabled = false
end
function HealthModule:DisplayHealth(Amount: number)
self.Amount.Text = tostring(Amount)
if Amount <= 40 then
self.Amount.TextColor3 = Color3.fromRGB(255,238,0)
elseif Amount <= 20 then
self.Amount.TextColor3 = Color3.fromRGB(255,0,38)
else
self.Amount.TextColor3 = Color3.new(1,1,1)
end
end
return HealthModule

View File

@@ -1,11 +1,13 @@
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 Players = game:GetService("Players")
local Storage = game:GetService("ReplicatedStorage")
local RS = game:GetService("RunService") :: RunService
local ClientStorage = Storage:WaitForChild("Client")
local LoadCompleted = ClientStorage:WaitForChild("LoadingComplete")
@@ -33,7 +35,7 @@ local Crosshair = CrosshairSettings.constructor(PlayerGui)
--Keybinds
local function CameraBinds()
local CameraBindMap = KeyBindsModule.constructor()
local CameraBindMap = KeyBindsModule.constructor(false)
CameraBindMap:AddInputBegan({Enum.KeyCode.C, Enum.KeyCode.Z}, function()
Camera:ZoomIn(Vignette, Crosshair)
@@ -43,9 +45,21 @@ local function CameraBinds()
end)
end
local function Crosshair3DEffect()
local RootVelocity = Instance.new("BindableEvent") :: BindableEvent
RootVelocity.Name = "RootVelocity"
RootVelocity.Parent = ClientStorage
RootVelocity.Event:Connect(function(RootVelocity: Vector3)
Crosshair:Jump(RootVelocity)
end)
end
CoreGuis:Off()
Camera:FirstPerson()
Mouse:DisablePointer()
Crosshair:Enable()
HealthSettings:Enable()
CameraBinds()
CameraBinds()
Crosshair3DEffect()