2022-10-13 03:53:17 -05:00
|
|
|
--!strict
|
2023-07-07 22:01:02 -05:00
|
|
|
local Core = script.Parent
|
|
|
|
|
|
|
|
if Core:GetAttribute("HotLoading") then
|
|
|
|
task.wait(3)
|
|
|
|
end
|
|
|
|
|
|
|
|
for i, desc in script:GetDescendants() do
|
|
|
|
if desc:IsA("BaseScript") then
|
|
|
|
desc.Enabled = true
|
|
|
|
end
|
|
|
|
end
|
2022-10-13 03:53:17 -05:00
|
|
|
|
2022-10-13 18:26:11 -05:00
|
|
|
local Players = game:GetService("Players")
|
|
|
|
local RunService = game:GetService("RunService")
|
|
|
|
local StarterGui = game:GetService("StarterGui")
|
|
|
|
local TweenService = game:GetService("TweenService")
|
|
|
|
local UserInputService = game:GetService("UserInputService")
|
|
|
|
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
|
|
|
local ContextActionService = game:GetService("ContextActionService")
|
2022-10-13 03:53:17 -05:00
|
|
|
|
2023-07-07 22:01:02 -05:00
|
|
|
local Shared = require(Core.Shared)
|
|
|
|
local Sounds = Shared.Sounds
|
|
|
|
|
2022-10-13 03:53:17 -05:00
|
|
|
local Enums = require(script.Enums)
|
|
|
|
local Mario = require(script.Mario)
|
|
|
|
local Types = require(script.Types)
|
|
|
|
local Util = require(script.Util)
|
|
|
|
|
|
|
|
local Action = Enums.Action
|
|
|
|
local Buttons = Enums.Buttons
|
2023-07-07 22:01:02 -05:00
|
|
|
local MarioFlags = Enums.MarioFlags
|
2022-10-13 03:53:17 -05:00
|
|
|
local ParticleFlags = Enums.ParticleFlags
|
|
|
|
|
|
|
|
type InputType = Enum.UserInputType | Enum.KeyCode
|
|
|
|
type Controller = Types.Controller
|
|
|
|
type Mario = Mario.Class
|
|
|
|
|
|
|
|
local player: Player = assert(Players.LocalPlayer)
|
2023-07-17 19:19:03 -05:00
|
|
|
local mario: Mario = Mario.new()
|
2023-07-07 22:01:02 -05:00
|
|
|
|
2022-10-13 03:53:17 -05:00
|
|
|
local STEP_RATE = 30
|
2023-07-07 22:01:02 -05:00
|
|
|
local NULL_TEXT = `<font color="#FF0000">NULL</font>`
|
2023-07-17 19:19:03 -05:00
|
|
|
local FLIP = CFrame.Angles(0, math.pi, 0)
|
2023-07-07 22:01:02 -05:00
|
|
|
|
|
|
|
local debugStats = Instance.new("BoolValue")
|
|
|
|
debugStats.Name = "DebugStats"
|
|
|
|
debugStats.Archivable = false
|
|
|
|
debugStats.Parent = game
|
2022-10-13 03:53:17 -05:00
|
|
|
|
|
|
|
local PARTICLE_CLASSES = {
|
|
|
|
Fire = true,
|
|
|
|
Smoke = true,
|
|
|
|
Sparkles = true,
|
|
|
|
ParticleEmitter = true,
|
|
|
|
}
|
|
|
|
|
2023-07-07 22:01:02 -05:00
|
|
|
local AUTO_STATS = {
|
|
|
|
"Position",
|
|
|
|
"Velocity",
|
|
|
|
"AnimFrame",
|
|
|
|
"FaceAngle",
|
|
|
|
|
|
|
|
"ActionState",
|
|
|
|
"ActionTimer",
|
|
|
|
"ActionArg",
|
|
|
|
|
|
|
|
"ForwardVel",
|
|
|
|
"SlideVelX",
|
|
|
|
"SlideVelZ",
|
|
|
|
|
|
|
|
"CeilHeight",
|
|
|
|
"FloorHeight",
|
2023-07-17 19:19:03 -05:00
|
|
|
"WaterLevel",
|
2023-07-07 22:01:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
local ControlModule: {
|
|
|
|
GetMoveVector: (self: any) -> Vector3,
|
|
|
|
}
|
|
|
|
|
|
|
|
while not ControlModule do
|
|
|
|
local inst = player:FindFirstChild("ControlModule", true)
|
|
|
|
|
|
|
|
if inst then
|
|
|
|
ControlModule = (require :: any)(inst)
|
|
|
|
end
|
|
|
|
|
|
|
|
task.wait(0.1)
|
|
|
|
end
|
2022-10-13 03:53:17 -05:00
|
|
|
|
|
|
|
-------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
-- Input Driver
|
|
|
|
-------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
2023-07-07 22:01:02 -05:00
|
|
|
-- NOTE: I had to replace the default BindAction via KeyCode and UserInputType
|
|
|
|
-- BindAction forces some mappings (such as R2 mapping to MouseButton1) which you
|
|
|
|
-- can't turn off otherwise.
|
|
|
|
|
|
|
|
local BUTTON_FEED = {}
|
|
|
|
local BUTTON_BINDS = {}
|
2022-10-13 03:53:17 -05:00
|
|
|
|
|
|
|
local function toStrictNumber(str: string): number
|
|
|
|
local result = tonumber(str)
|
|
|
|
return assert(result, "Invalid number!")
|
|
|
|
end
|
|
|
|
|
2023-07-07 22:01:02 -05:00
|
|
|
local function processAction(id: string, state: Enum.UserInputState, input: InputObject)
|
|
|
|
if id == "MarioDebug" and Core:GetAttribute("DebugToggle") then
|
2022-10-13 03:53:17 -05:00
|
|
|
if state == Enum.UserInputState.Begin then
|
|
|
|
local character = player.Character
|
|
|
|
|
2023-07-07 22:01:02 -05:00
|
|
|
if character then
|
|
|
|
local isDebug = not character:GetAttribute("Debug")
|
|
|
|
character:SetAttribute("Debug", isDebug)
|
2022-10-13 03:53:17 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
local button = toStrictNumber(id:sub(5))
|
|
|
|
BUTTON_FEED[button] = state
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-07-07 22:01:02 -05:00
|
|
|
local function processInput(input: InputObject, gameProcessedEvent: boolean)
|
|
|
|
if gameProcessedEvent then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if BUTTON_BINDS[input.UserInputType] ~= nil then
|
|
|
|
processAction(BUTTON_BINDS[input.UserInputType], input.UserInputState, input)
|
|
|
|
end
|
|
|
|
if BUTTON_BINDS[input.KeyCode] ~= nil then
|
|
|
|
processAction(BUTTON_BINDS[input.KeyCode], input.UserInputState, input)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
UserInputService.InputBegan:Connect(processInput)
|
|
|
|
UserInputService.InputChanged:Connect(processInput)
|
|
|
|
UserInputService.InputEnded:Connect(processInput)
|
|
|
|
|
2022-10-13 03:53:17 -05:00
|
|
|
local function bindInput(button: number, label: string, ...: InputType)
|
|
|
|
local id = "BTN_" .. button
|
|
|
|
|
|
|
|
if UserInputService.TouchEnabled then
|
2023-07-07 22:01:02 -05:00
|
|
|
ContextActionService:BindAction(id, processAction, true)
|
2022-10-13 03:53:17 -05:00
|
|
|
ContextActionService:SetTitle(id, label)
|
|
|
|
end
|
2023-07-07 22:01:02 -05:00
|
|
|
|
|
|
|
for i, input in { ... } do
|
|
|
|
BUTTON_BINDS[input] = id
|
|
|
|
end
|
2022-10-13 03:53:17 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
local function updateCollisions()
|
|
|
|
for i, player in Players:GetPlayers() do
|
2022-12-03 04:15:52 -06:00
|
|
|
-- stylua: ignore
|
2023-07-07 22:01:02 -05:00
|
|
|
local character = player.Character
|
|
|
|
local rootPart = character and character.PrimaryPart
|
2022-10-13 03:53:17 -05:00
|
|
|
|
|
|
|
if rootPart then
|
|
|
|
local parts = rootPart:GetConnectedParts(true)
|
|
|
|
|
|
|
|
for i, part in parts do
|
|
|
|
if part:IsA("BasePart") then
|
|
|
|
part.CanCollide = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-07-07 22:01:02 -05:00
|
|
|
local function updateController(controller: Controller, humanoid: Humanoid?)
|
|
|
|
if not humanoid then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local moveDir = ControlModule:GetMoveVector()
|
2022-10-13 03:53:17 -05:00
|
|
|
local pos = Vector2.new(moveDir.X, -moveDir.Z)
|
2023-07-07 22:01:02 -05:00
|
|
|
local mag = 0
|
2022-10-13 03:53:17 -05:00
|
|
|
|
2023-07-07 22:01:02 -05:00
|
|
|
if pos.Magnitude > 0 then
|
|
|
|
if pos.Magnitude > 1 then
|
|
|
|
pos = pos.Unit
|
|
|
|
end
|
|
|
|
|
|
|
|
mag = pos.Magnitude
|
|
|
|
end
|
|
|
|
|
|
|
|
controller.StickMag = mag * 64
|
2022-10-13 03:53:17 -05:00
|
|
|
controller.StickX = pos.X * 64
|
|
|
|
controller.StickY = pos.Y * 64
|
|
|
|
|
|
|
|
humanoid:ChangeState(Enum.HumanoidStateType.Physics)
|
|
|
|
controller.ButtonPressed:Clear()
|
|
|
|
|
|
|
|
if humanoid.Jump then
|
|
|
|
BUTTON_FEED[Buttons.A_BUTTON] = Enum.UserInputState.Begin
|
|
|
|
elseif controller.ButtonDown:Has(Buttons.A_BUTTON) then
|
|
|
|
BUTTON_FEED[Buttons.A_BUTTON] = Enum.UserInputState.End
|
|
|
|
end
|
|
|
|
|
2023-07-07 22:01:02 -05:00
|
|
|
local lastButtonValue = controller.ButtonDown()
|
|
|
|
|
2022-10-13 03:53:17 -05:00
|
|
|
for button, state in pairs(BUTTON_FEED) do
|
|
|
|
if state == Enum.UserInputState.Begin then
|
|
|
|
controller.ButtonDown:Add(button)
|
|
|
|
elseif state == Enum.UserInputState.End then
|
|
|
|
controller.ButtonDown:Remove(button)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
table.clear(BUTTON_FEED)
|
2023-07-07 22:01:02 -05:00
|
|
|
|
2023-07-08 20:43:00 -05:00
|
|
|
local buttonValue = controller.ButtonDown()
|
|
|
|
controller.ButtonPressed:Set(buttonValue)
|
|
|
|
controller.ButtonPressed:Band(bit32.bxor(buttonValue, lastButtonValue))
|
2023-07-07 22:01:02 -05:00
|
|
|
|
2023-07-08 20:43:00 -05:00
|
|
|
local character = humanoid.Parent
|
|
|
|
if (character and character:GetAttribute("TAS")) or Core:GetAttribute("ToolAssistedInput") then
|
2023-07-17 19:19:03 -05:00
|
|
|
if not mario.Action:Has(Enums.ActionFlags.SWIMMING) then
|
|
|
|
if controller.ButtonDown:Has(Buttons.A_BUTTON) then
|
|
|
|
controller.ButtonPressed:Set(Buttons.A_BUTTON)
|
|
|
|
end
|
2023-07-08 20:43:00 -05:00
|
|
|
end
|
2023-07-07 22:01:02 -05:00
|
|
|
end
|
2022-10-13 03:53:17 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
ContextActionService:BindAction("MarioDebug", processAction, false, Enum.KeyCode.P)
|
|
|
|
bindInput(Buttons.B_BUTTON, "B", Enum.UserInputType.MouseButton1, Enum.KeyCode.ButtonX)
|
2023-07-07 22:01:02 -05:00
|
|
|
bindInput(
|
|
|
|
Buttons.Z_TRIG,
|
|
|
|
"Z",
|
|
|
|
Enum.KeyCode.LeftShift,
|
|
|
|
Enum.KeyCode.RightShift,
|
|
|
|
Enum.KeyCode.ButtonL2,
|
|
|
|
Enum.KeyCode.ButtonR2
|
|
|
|
)
|
2022-10-13 03:53:17 -05:00
|
|
|
|
|
|
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
-- Network Dispatch
|
|
|
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
local Commands = {}
|
2023-07-08 18:42:28 -05:00
|
|
|
local soundDecay = {}
|
2022-10-13 03:53:17 -05:00
|
|
|
|
|
|
|
local lazyNetwork = ReplicatedStorage:WaitForChild("LazyNetwork")
|
|
|
|
assert(lazyNetwork:IsA("RemoteEvent"), "bad lazyNetwork!")
|
|
|
|
|
2023-07-08 18:42:28 -05:00
|
|
|
local function stepDecay(sound: Sound)
|
|
|
|
local decay = soundDecay[sound]
|
|
|
|
|
|
|
|
if decay then
|
|
|
|
task.cancel(decay)
|
|
|
|
end
|
|
|
|
|
|
|
|
soundDecay[sound] = task.delay(0.1, function()
|
|
|
|
sound:Stop()
|
|
|
|
sound:Destroy()
|
|
|
|
soundDecay[sound] = nil
|
|
|
|
end)
|
|
|
|
|
|
|
|
sound.Playing = true
|
|
|
|
end
|
|
|
|
|
2022-10-13 03:53:17 -05:00
|
|
|
function Commands.PlaySound(player: Player, name: string)
|
|
|
|
local sound: Sound? = Sounds[name]
|
|
|
|
local character = player.Character
|
2023-07-07 22:01:02 -05:00
|
|
|
local rootPart = character and character.PrimaryPart
|
2022-10-13 03:53:17 -05:00
|
|
|
|
|
|
|
if rootPart and sound then
|
|
|
|
local oldSound: Instance? = rootPart:FindFirstChild(name)
|
2023-07-08 18:42:28 -05:00
|
|
|
local canPlay = true
|
|
|
|
|
|
|
|
if oldSound and oldSound:IsA("Sound") then
|
|
|
|
canPlay = false
|
|
|
|
|
2023-07-17 19:19:03 -05:00
|
|
|
if name:sub(1, 6) == "MOVING" or sound:GetAttribute("Decay") then
|
|
|
|
-- Keep decaying audio alive.
|
|
|
|
stepDecay(oldSound)
|
|
|
|
elseif name:sub(1, 5) == "MARIO" then
|
2023-07-08 18:42:28 -05:00
|
|
|
-- Restart mario sound if a 30hz interval passed.
|
|
|
|
local now = os.clock()
|
|
|
|
local lastPlay = oldSound:GetAttribute("LastPlay") or 0
|
|
|
|
|
|
|
|
if now - lastPlay >= 2 / STEP_RATE then
|
|
|
|
oldSound.TimePosition = 0
|
|
|
|
oldSound:SetAttribute("LastPlay", now)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
-- Allow stacking.
|
|
|
|
canPlay = true
|
|
|
|
end
|
|
|
|
end
|
2022-10-13 03:53:17 -05:00
|
|
|
|
2023-07-08 18:42:28 -05:00
|
|
|
if canPlay then
|
2022-10-13 03:53:17 -05:00
|
|
|
local newSound: Sound = sound:Clone()
|
|
|
|
newSound.Parent = rootPart
|
|
|
|
newSound:Play()
|
|
|
|
|
2023-07-08 18:42:28 -05:00
|
|
|
if name:find("MOVING") then
|
|
|
|
-- Audio will decay if PlaySound isn't continuously called.
|
|
|
|
stepDecay(newSound)
|
|
|
|
end
|
|
|
|
|
2022-10-13 03:53:17 -05:00
|
|
|
newSound.Ended:Connect(function()
|
|
|
|
newSound:Destroy()
|
|
|
|
end)
|
2023-07-08 18:42:28 -05:00
|
|
|
|
|
|
|
newSound:SetAttribute("LastPlay", os.clock())
|
2022-10-13 03:53:17 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Commands.SetParticle(player: Player, name: string, set: boolean)
|
|
|
|
local character = player.Character
|
2023-07-07 22:01:02 -05:00
|
|
|
local rootPart = character and character.PrimaryPart
|
2022-10-13 03:53:17 -05:00
|
|
|
|
|
|
|
if rootPart then
|
|
|
|
local particles = rootPart:FindFirstChild("Particles")
|
2023-07-08 18:42:28 -05:00
|
|
|
local inst = particles and particles:FindFirstChild(name, true)
|
2022-10-13 03:53:17 -05:00
|
|
|
|
|
|
|
if inst and PARTICLE_CLASSES[inst.ClassName] then
|
|
|
|
local particle = inst :: ParticleEmitter
|
|
|
|
local emit = particle:GetAttribute("Emit")
|
|
|
|
|
|
|
|
if typeof(emit) == "number" then
|
|
|
|
particle:Emit(emit)
|
|
|
|
elseif set ~= nil then
|
|
|
|
particle.Enabled = set
|
|
|
|
end
|
2023-07-17 19:19:03 -05:00
|
|
|
else
|
|
|
|
warn("particle not found:", name)
|
2022-10-13 03:53:17 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-07-17 19:19:03 -05:00
|
|
|
function Commands.SetTorsoAngle(player: Player, angle: Vector3int16)
|
2022-10-13 03:53:17 -05:00
|
|
|
local character = player.Character
|
2023-07-07 22:01:02 -05:00
|
|
|
local waist = character and character:FindFirstChild("Waist", true)
|
2022-10-13 03:53:17 -05:00
|
|
|
|
|
|
|
if waist and waist:IsA("Motor6D") then
|
|
|
|
local props = { C1 = Util.ToRotation(-angle) + waist.C1.Position }
|
|
|
|
local tween = TweenService:Create(waist, TweenInfo.new(0.1), props)
|
|
|
|
tween:Play()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-07-17 19:19:03 -05:00
|
|
|
function Commands.SetHeadAngle(player: Player, angle: Vector3int16)
|
|
|
|
local character = player.Character
|
|
|
|
local neck = character and character:FindFirstChild("Neck", true)
|
|
|
|
|
|
|
|
if neck and neck:IsA("Motor6D") then
|
|
|
|
local props = { C1 = Util.ToRotation(-angle) + neck.C1.Position }
|
|
|
|
local tween = TweenService:Create(neck, TweenInfo.new(0.1), props)
|
|
|
|
tween:Play()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-07-07 22:01:02 -05:00
|
|
|
function Commands.SetCamera(player: Player, cf: CFrame?)
|
|
|
|
local camera = workspace.CurrentCamera
|
|
|
|
|
|
|
|
if cf ~= nil then
|
|
|
|
camera.CameraType = Enum.CameraType.Scriptable
|
|
|
|
camera.CFrame = cf
|
|
|
|
else
|
|
|
|
camera.CameraType = Enum.CameraType.Custom
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-13 03:53:17 -05:00
|
|
|
local function processCommand(player: Player, cmd: string, ...: any)
|
|
|
|
local command = Commands[cmd]
|
|
|
|
|
|
|
|
if command then
|
|
|
|
task.spawn(command, player, ...)
|
|
|
|
else
|
|
|
|
warn("Unknown Command:", cmd, ...)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function networkDispatch(cmd: string, ...: any)
|
|
|
|
lazyNetwork:FireServer(cmd, ...)
|
|
|
|
processCommand(player, cmd, ...)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function onNetworkReceive(target: Player, cmd: string, ...: any)
|
|
|
|
if target ~= player then
|
|
|
|
processCommand(target, cmd, ...)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
lazyNetwork.OnClientEvent:Connect(onNetworkReceive)
|
|
|
|
|
|
|
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
-- Mario Driver
|
|
|
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
local lastUpdate = os.clock()
|
2023-07-17 19:19:03 -05:00
|
|
|
local lastHeadAngle: Vector3int16?
|
|
|
|
local lastTorsoAngle: Vector3int16?
|
2022-10-13 03:53:17 -05:00
|
|
|
|
2023-07-12 15:35:04 -05:00
|
|
|
local activeScale = 1
|
2023-07-07 22:01:02 -05:00
|
|
|
local subframe = 0 -- 30hz subframe
|
|
|
|
local emptyId = ""
|
|
|
|
|
2022-10-13 03:53:17 -05:00
|
|
|
local goalCF: CFrame
|
2023-07-07 22:01:02 -05:00
|
|
|
local prevCF: CFrame
|
2022-10-13 03:53:17 -05:00
|
|
|
local activeTrack: AnimationTrack?
|
|
|
|
|
|
|
|
local reset = Instance.new("BindableEvent")
|
|
|
|
reset.Archivable = false
|
|
|
|
reset.Parent = script
|
|
|
|
reset.Name = "Reset"
|
|
|
|
|
2022-10-13 18:26:11 -05:00
|
|
|
if RunService:IsStudio() then
|
|
|
|
local dummySequence = Instance.new("KeyframeSequence")
|
|
|
|
local provider = game:GetService("KeyframeSequenceProvider")
|
|
|
|
emptyId = provider:RegisterKeyframeSequence(dummySequence)
|
|
|
|
end
|
|
|
|
|
2022-10-13 03:53:17 -05:00
|
|
|
while not player.Character do
|
|
|
|
player.CharacterAdded:Wait()
|
|
|
|
end
|
|
|
|
|
|
|
|
local character = assert(player.Character)
|
2023-07-07 22:01:02 -05:00
|
|
|
local pivot = character:GetPivot()
|
|
|
|
mario.Position = Util.ToSM64(pivot.Position)
|
|
|
|
|
|
|
|
goalCF = pivot
|
|
|
|
prevCF = pivot
|
|
|
|
|
|
|
|
local function setDebugStat(key: string, value: any)
|
|
|
|
if typeof(value) == "Vector3" then
|
|
|
|
value = string.format("%.3f, %.3f, %.3f", value.X, value.Y, value.Z)
|
|
|
|
elseif typeof(value) == "Vector3int16" then
|
|
|
|
value = string.format("%i, %i, %i", value.X, value.Y, value.Z)
|
|
|
|
elseif type(value) == "number" then
|
|
|
|
value = string.format("%.3f", value)
|
|
|
|
end
|
|
|
|
|
|
|
|
debugStats:SetAttribute(key, value)
|
|
|
|
end
|
2022-10-13 03:53:17 -05:00
|
|
|
|
2024-04-19 17:24:14 -05:00
|
|
|
|
|
|
|
--THIS IS WHERE THE SPAWNLOCATION IMPLEMENTATION IS
|
|
|
|
local function getTeamSpawnPosition(player)
|
|
|
|
local teamColor = player.TeamColor
|
|
|
|
local spawnLocations = game.Workspace:GetDescendants()
|
|
|
|
local teamSpawn = nil
|
|
|
|
|
|
|
|
-- Find a spawn location with the same TeamColor as the player's team
|
|
|
|
for _, spawn in pairs(spawnLocations) do
|
|
|
|
if spawn.ClassName == "SpawnLocation" then
|
|
|
|
if spawn.TeamColor == teamColor then
|
|
|
|
teamSpawn = spawn
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if teamSpawn then
|
|
|
|
return teamSpawn.Position
|
|
|
|
else
|
|
|
|
warn("No spawn location found for team color: " .. tostring(teamColor))
|
|
|
|
return game.workspace:FindFirstChild("SpawnLocation") --default
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2022-10-13 03:53:17 -05:00
|
|
|
local function onReset()
|
2024-04-19 17:24:14 -05:00
|
|
|
local roblox = getTeamSpawnPosition(player) --THIS IS WHERE THE SPAWNLOCATION IMPLEMENTATION IS CALLED
|
2022-10-13 03:53:17 -05:00
|
|
|
local sm64 = Util.ToSM64(roblox)
|
|
|
|
local char = player.Character
|
|
|
|
|
|
|
|
if char then
|
|
|
|
local reset = char:FindFirstChild("Reset")
|
2023-07-07 22:01:02 -05:00
|
|
|
|
2022-10-13 03:53:17 -05:00
|
|
|
local cf = CFrame.new(roblox)
|
2023-07-07 22:01:02 -05:00
|
|
|
|
|
|
|
goalCF = cf
|
|
|
|
prevCF = cf
|
2022-10-13 03:53:17 -05:00
|
|
|
|
|
|
|
if reset and reset:IsA("RemoteEvent") then
|
|
|
|
reset:FireServer()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
mario.SlideVelX = 0
|
|
|
|
mario.SlideVelZ = 0
|
|
|
|
mario.ForwardVel = 0
|
|
|
|
mario.IntendedYaw = 0
|
|
|
|
|
|
|
|
mario.Position = sm64
|
|
|
|
mario.Velocity = Vector3.zero
|
|
|
|
mario.FaceAngle = Vector3int16.new()
|
|
|
|
|
|
|
|
mario:SetAction(Action.SPAWN_SPIN_AIRBORNE)
|
|
|
|
end
|
|
|
|
|
2023-07-17 19:19:03 -05:00
|
|
|
local function getWaterLevel(pos: Vector3)
|
|
|
|
local terrain = workspace.Terrain
|
|
|
|
local voxelPos = terrain:WorldToCellPreferSolid(pos)
|
|
|
|
|
|
|
|
local voxelRegion = Region3.new(voxelPos * 4, (voxelPos + Vector3.one + (Vector3.yAxis * 3)) * 4)
|
|
|
|
voxelRegion = voxelRegion:ExpandToGrid(4)
|
|
|
|
|
|
|
|
local materials, occupancies = terrain:ReadVoxels(voxelRegion, 4)
|
|
|
|
local size: Vector3 = occupancies.Size
|
|
|
|
local waterLevel = -11000
|
|
|
|
|
|
|
|
for y = 1, size.Y do
|
|
|
|
local occupancy = occupancies[1][y][1]
|
|
|
|
local material = materials[1][y][1]
|
|
|
|
|
|
|
|
if occupancy >= 0.9 and material == Enum.Material.Water then
|
|
|
|
local top = ((voxelPos.Y * 4) + (4 * y + 2))
|
|
|
|
waterLevel = math.max(waterLevel, top / Util.Scale)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return waterLevel
|
|
|
|
end
|
|
|
|
|
2022-10-13 03:53:17 -05:00
|
|
|
local function update()
|
|
|
|
local character = player.Character
|
|
|
|
|
|
|
|
if not character then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local now = os.clock()
|
|
|
|
local gfxRot = CFrame.identity
|
2023-07-07 22:01:02 -05:00
|
|
|
local scale = character:GetScale()
|
2023-07-12 15:35:04 -05:00
|
|
|
|
|
|
|
if scale ~= activeScale then
|
|
|
|
local marioPos = Util.ToRoblox(mario.Position)
|
|
|
|
Util.Scale = scale / 20 -- HACK! Should this be instanced?
|
|
|
|
|
|
|
|
mario.Position = Util.ToSM64(marioPos)
|
|
|
|
activeScale = scale
|
|
|
|
end
|
2023-07-12 01:11:34 -05:00
|
|
|
|
|
|
|
-- Disabled for now because this causes parallel universes to break.
|
|
|
|
-- TODO: Find a better way to do two-way syncing between these values.
|
2022-10-13 03:53:17 -05:00
|
|
|
|
2023-07-17 19:19:03 -05:00
|
|
|
-- local pos = character:GetPivot().Position
|
|
|
|
-- local dist = (Util.ToRoblox(mario.Position) - pos).Magnitude
|
2022-10-13 03:53:17 -05:00
|
|
|
|
2023-07-17 19:19:03 -05:00
|
|
|
-- if dist > (scale * 20) then
|
|
|
|
-- mario.Position = Util.ToSM64(pos)
|
|
|
|
-- end
|
2022-10-13 03:53:17 -05:00
|
|
|
|
2023-07-12 01:11:34 -05:00
|
|
|
local humanoid = character:FindFirstChildOfClass("Humanoid")
|
2023-07-07 22:01:02 -05:00
|
|
|
local simSpeed = tonumber(character:GetAttribute("TimeScale") or nil) or 1
|
2023-07-12 01:11:34 -05:00
|
|
|
|
2023-07-17 19:19:03 -05:00
|
|
|
local robloxPos = Util.ToRoblox(mario.Position)
|
|
|
|
mario.WaterLevel = getWaterLevel(robloxPos)
|
|
|
|
Util.DebugWater(mario.WaterLevel)
|
|
|
|
|
2023-07-07 22:01:02 -05:00
|
|
|
subframe += (now - lastUpdate) * (STEP_RATE * simSpeed)
|
|
|
|
lastUpdate = now
|
2022-10-13 03:53:17 -05:00
|
|
|
|
2023-07-07 22:01:02 -05:00
|
|
|
if character:GetAttribute("WingCap") or Core:GetAttribute("WingCap") then
|
|
|
|
mario.Flags:Add(MarioFlags.WING_CAP)
|
|
|
|
else
|
|
|
|
mario.Flags:Remove(MarioFlags.WING_CAP)
|
|
|
|
end
|
|
|
|
|
2023-07-08 18:42:28 -05:00
|
|
|
if character:GetAttribute("Metal") then
|
|
|
|
mario.Flags:Add(MarioFlags.METAL_CAP)
|
|
|
|
else
|
|
|
|
mario.Flags:Remove(MarioFlags.METAL_CAP)
|
|
|
|
end
|
|
|
|
|
2023-07-07 22:01:02 -05:00
|
|
|
subframe = math.min(subframe, 4) -- Prevent execution runoff
|
|
|
|
|
|
|
|
while subframe >= 1 do
|
|
|
|
subframe -= 1
|
|
|
|
updateCollisions()
|
|
|
|
|
|
|
|
updateController(mario.Controller, humanoid)
|
|
|
|
mario:ExecuteAction()
|
2022-10-13 03:53:17 -05:00
|
|
|
|
2023-07-07 22:01:02 -05:00
|
|
|
local gfxPos = Util.ToRoblox(mario.Position)
|
2022-10-13 03:53:17 -05:00
|
|
|
gfxRot = Util.ToRotation(mario.GfxAngle)
|
|
|
|
|
2023-07-07 22:01:02 -05:00
|
|
|
prevCF = goalCF
|
|
|
|
goalCF = CFrame.new(gfxPos) * FLIP * gfxRot
|
|
|
|
end
|
2022-10-13 03:53:17 -05:00
|
|
|
|
|
|
|
if character and goalCF then
|
|
|
|
local cf = character:GetPivot()
|
|
|
|
local rootPart = character.PrimaryPart
|
|
|
|
local animator = character:FindFirstChildWhichIsA("Animator", true)
|
|
|
|
|
|
|
|
if animator and (mario.AnimDirty or mario.AnimReset) and mario.AnimFrame >= 0 then
|
|
|
|
local anim = mario.AnimCurrent
|
|
|
|
local animSpeed = 0.1 / simSpeed
|
|
|
|
|
|
|
|
if activeTrack and (activeTrack.Animation ~= anim or mario.AnimReset) then
|
2023-07-07 22:01:02 -05:00
|
|
|
if tostring(activeTrack.Animation) == "TURNING_PART1" then
|
|
|
|
if anim and anim.Name == "TURNING_PART2" then
|
|
|
|
mario.AnimSkipInterp = 2
|
|
|
|
animSpeed *= 2
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-13 03:53:17 -05:00
|
|
|
activeTrack:Stop(animSpeed)
|
|
|
|
activeTrack = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
if not activeTrack and anim then
|
2022-10-13 18:26:11 -05:00
|
|
|
if anim.AnimationId == "" then
|
|
|
|
if RunService:IsStudio() then
|
|
|
|
warn("!! FIXME: Empty AnimationId for", anim.Name, "will break in live games!")
|
|
|
|
end
|
|
|
|
|
|
|
|
anim.AnimationId = emptyId
|
|
|
|
end
|
|
|
|
|
2022-10-13 03:53:17 -05:00
|
|
|
local track = animator:LoadAnimation(anim)
|
|
|
|
track:Play(animSpeed, 1, 0)
|
|
|
|
activeTrack = track
|
|
|
|
end
|
|
|
|
|
|
|
|
if activeTrack then
|
|
|
|
local speed = mario.AnimAccel / 0x10000
|
|
|
|
|
|
|
|
if speed > 0 then
|
|
|
|
activeTrack:AdjustSpeed(speed * simSpeed)
|
|
|
|
else
|
|
|
|
activeTrack:AdjustSpeed(simSpeed)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
mario.AnimDirty = false
|
|
|
|
mario.AnimReset = false
|
|
|
|
end
|
|
|
|
|
|
|
|
if activeTrack and mario.AnimSetFrame > -1 then
|
|
|
|
activeTrack.TimePosition = mario.AnimSetFrame / STEP_RATE
|
|
|
|
mario.AnimSetFrame = -1
|
|
|
|
end
|
|
|
|
|
|
|
|
if rootPart then
|
|
|
|
local particles = rootPart:FindFirstChild("Particles")
|
|
|
|
local alignPos = rootPart:FindFirstChildOfClass("AlignPosition")
|
|
|
|
local alignCF = rootPart:FindFirstChildOfClass("AlignOrientation")
|
2023-07-07 22:01:02 -05:00
|
|
|
|
|
|
|
local actionId = mario.Action()
|
2022-10-13 03:53:17 -05:00
|
|
|
local throw = mario.ThrowMatrix
|
|
|
|
|
|
|
|
if throw then
|
2023-07-07 22:01:02 -05:00
|
|
|
local throwPos = Util.ToRoblox(throw.Position)
|
|
|
|
goalCF = throw.Rotation * FLIP + throwPos
|
2022-10-13 03:53:17 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
if alignCF then
|
2023-07-07 22:01:02 -05:00
|
|
|
local nextCF = prevCF:Lerp(goalCF, subframe)
|
|
|
|
|
|
|
|
-- stylua: ignore
|
|
|
|
cf = if mario.AnimSkipInterp > 0
|
|
|
|
then cf.Rotation + nextCF.Position
|
|
|
|
else nextCF
|
|
|
|
|
2022-10-13 03:53:17 -05:00
|
|
|
alignCF.CFrame = cf.Rotation
|
|
|
|
end
|
2023-07-07 22:01:02 -05:00
|
|
|
|
|
|
|
local isDebug = character:GetAttribute("Debug")
|
|
|
|
local limits = character:GetAttribute("EmulateLimits")
|
|
|
|
|
|
|
|
script.Util:SetAttribute("Debug", isDebug)
|
|
|
|
debugStats.Value = isDebug
|
|
|
|
|
|
|
|
if limits ~= nil then
|
|
|
|
Core:SetAttribute("TruncateBounds", limits)
|
|
|
|
end
|
|
|
|
|
|
|
|
if isDebug then
|
|
|
|
local animName = activeTrack and tostring(activeTrack.Animation)
|
|
|
|
setDebugStat("Animation", animName)
|
|
|
|
|
|
|
|
local actionName = Enums.GetName(Action, actionId)
|
|
|
|
setDebugStat("Action", actionName)
|
|
|
|
|
|
|
|
local wall = mario.Wall
|
|
|
|
setDebugStat("Wall", wall and wall.Instance.Name or NULL_TEXT)
|
|
|
|
|
|
|
|
local floor = mario.Floor
|
|
|
|
setDebugStat("Floor", floor and floor.Instance.Name or NULL_TEXT)
|
|
|
|
|
|
|
|
local ceil = mario.Ceil
|
|
|
|
setDebugStat("Ceiling", ceil and ceil.Instance.Name or NULL_TEXT)
|
|
|
|
end
|
|
|
|
|
|
|
|
for _, name in AUTO_STATS do
|
|
|
|
local value = rawget(mario :: any, name)
|
|
|
|
setDebugStat(name, value)
|
2022-10-13 03:53:17 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
if alignPos then
|
|
|
|
alignPos.Position = cf.Position
|
|
|
|
end
|
|
|
|
|
|
|
|
local bodyState = mario.BodyState
|
2023-07-17 19:19:03 -05:00
|
|
|
local headAngle = bodyState.HeadAngle
|
|
|
|
local torsoAngle = bodyState.TorsoAngle
|
2022-10-13 03:53:17 -05:00
|
|
|
|
2023-07-07 22:01:02 -05:00
|
|
|
if actionId ~= Action.BUTT_SLIDE and actionId ~= Action.WALKING then
|
2022-10-13 03:53:17 -05:00
|
|
|
bodyState.TorsoAngle *= 0
|
|
|
|
end
|
|
|
|
|
2023-07-17 19:19:03 -05:00
|
|
|
if torsoAngle ~= lastTorsoAngle then
|
|
|
|
networkDispatch("SetTorsoAngle", torsoAngle)
|
|
|
|
lastTorsoAngle = torsoAngle
|
|
|
|
end
|
|
|
|
|
|
|
|
if headAngle ~= lastHeadAngle then
|
|
|
|
networkDispatch("SetHeadAngle", headAngle)
|
|
|
|
lastHeadAngle = headAngle
|
2022-10-13 03:53:17 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
if particles then
|
|
|
|
for name, flag in pairs(ParticleFlags) do
|
2023-07-12 15:51:59 -05:00
|
|
|
local inst = particles:FindFirstChild(name, true)
|
2022-10-13 03:53:17 -05:00
|
|
|
|
|
|
|
if inst and PARTICLE_CLASSES[inst.ClassName] then
|
|
|
|
local particle = inst :: ParticleEmitter
|
|
|
|
local emit = particle:GetAttribute("Emit")
|
|
|
|
local hasFlag = mario.ParticleFlags:Has(flag)
|
|
|
|
|
2023-07-17 19:19:03 -05:00
|
|
|
if hasFlag then
|
|
|
|
print("SetParticle", name)
|
|
|
|
end
|
|
|
|
|
2022-10-13 03:53:17 -05:00
|
|
|
if emit then
|
|
|
|
if hasFlag then
|
|
|
|
networkDispatch("SetParticle", name)
|
|
|
|
end
|
|
|
|
elseif particle.Enabled ~= hasFlag then
|
|
|
|
networkDispatch("SetParticle", name, hasFlag)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
for name: string, sound: Sound in pairs(Sounds) do
|
|
|
|
local looped = false
|
|
|
|
|
|
|
|
if sound:IsA("Sound") then
|
|
|
|
if sound.TimeLength == 0 then
|
|
|
|
continue
|
|
|
|
end
|
|
|
|
|
|
|
|
looped = sound.Looped
|
|
|
|
end
|
|
|
|
|
|
|
|
if sound:GetAttribute("Play") then
|
|
|
|
networkDispatch("PlaySound", sound.Name)
|
|
|
|
|
|
|
|
if not looped then
|
|
|
|
sound:SetAttribute("Play", false)
|
|
|
|
end
|
|
|
|
elseif looped then
|
|
|
|
sound:Stop()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
character:PivotTo(cf)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
reset.Event:Connect(onReset)
|
|
|
|
RunService.Heartbeat:Connect(update)
|
|
|
|
|
|
|
|
while task.wait(1) do
|
|
|
|
local success = pcall(function()
|
|
|
|
return StarterGui:SetCore("ResetButtonCallback", reset)
|
|
|
|
end)
|
|
|
|
|
|
|
|
if success then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------
|