Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local OmnitrixController = {}
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local TweenService = game:GetService("TweenService")
- local SoundService = game:GetService("SoundService")
- local Player = game:GetService("Players").LocalPlayer
- local Packages = ReplicatedStorage:WaitForChild("Packages")
- local Aliens = ReplicatedStorage:WaitForChild("Aliens")
- local ModelUtility = require(Packages:WaitForChild("ModelUtility"))
- local Activated = false
- local Transformed = false
- local DefaultCharacter = nil
- local REVERT_LOOP_SPEED = 1.4
- local REVERT_LOOP_PITCH = .65
- local REVERT_TRASNFORM_POINT = 3
- local REVERT_FLICKER_DELAY = .5
- local IDLE_LOOP_SPEED = 1.13
- local IDLE_LOOP_PITCH = .9
- local IDLE_VOLUME = .5
- local DEFAULT_VOLUME = 7
- local UsedDialSounds = {}
- local Selection = {
- [1] = Aliens:WaitForChild("Tetramand"),
- }
- local Selected = 1
- local function OnCharacterAdded(Character)
- Character.Archivable = true
- DefaultCharacter = Character:Clone()
- end
- local function GetSelectedAlien()
- return Selection[Selected]
- end
- local function SetSelectedAlien(NewValue)
- if NewValue > #Selection then
- NewValue = 1
- elseif NewValue <= 0 then
- NewValue = #Selection
- end
- Selected = NewValue
- end
- local function GetDialSound()
- local Sounds = _G.GetSound("Turned")
- local RandomInt = nil
- if #UsedDialSounds == #Sounds then
- UsedDialSounds = {}
- end
- repeat
- RandomInt = math.random(1, #Sounds)
- task.wait()
- until not UsedDialSounds[RandomInt]
- local Sound = Sounds[RandomInt]
- UsedDialSounds[RandomInt] = Sound
- return Sound
- end
- local function FlickerDialRed(Color)
- local Character = Player.Character
- local Omnitrix = Character:FindFirstChild("Omnitrix", true)
- local Hourglass = Omnitrix:FindFirstChild("Hourglass", true)
- local CachedMaterial = Hourglass.Material
- local CachedColor = Hourglass.Color
- while Transformed ~= false do
- if not Hourglass then
- break
- end
- Hourglass.Material = Enum.Material.Neon
- Hourglass.BrickColor = BrickColor.new("Really red")
- task.wait(REVERT_FLICKER_DELAY)
- Hourglass.Material = CachedMaterial
- Hourglass.Color = CachedColor
- task.wait(REVERT_FLICKER_DELAY)
- end
- end
- local function ChangeModelTransparency(Model, Value)
- for _,Component in Model:GetDescendants() do
- if not Component:IsA("Part") then
- continue
- end
- Component.Transparency = Value
- end
- end
- local function PlayLoopingSound(Omnitrix, Loop)
- local Sound = _G.GetSound(Loop)
- local PitchShift = Instance.new("PitchShiftSoundEffect")
- local Speed = Loop == "Idle" and IDLE_LOOP_SPEED or REVERT_LOOP_SPEED
- local Pitch = Loop == "Idle" and IDLE_LOOP_PITCH or REVERT_LOOP_PITCH
- local Volume = Loop == "Idle" and IDLE_VOLUME
- Sound.PlaybackSpeed = Speed
- Sound.Volume = Volume
- Sound.Looped = true
- Sound.Parent = Omnitrix and Omnitrix or Player.Character["Right Arm"]
- PitchShift.Octave = Pitch
- PitchShift.Parent = Sound
- Sound:Play()
- end
- local function DestroyLoopSounds(Omnitrix)
- local Model = Omnitrix and Omnitrix or Player.Character["Right Arm"]
- for _,Sound in ipairs(Model:GetChildren()) do
- if not Sound:IsA("Sound") or not Sound.Looped then
- continue
- end
- Sound:Destroy()
- end
- end
- local function DeActivate(Omnitrix)
- if Activated == nil then
- return
- end
- local Sound = _G.GetSound("DialDown")
- Activated = nil
- DestroyLoopSounds()
- Sound.Ended:Once(function()
- Activated = false
- Sound:Destroy()
- end)
- Sound.Parent = Omnitrix and Omnitrix or Player.Character["Right Arm"]
- Sound:Play()
- end
- function OmnitrixController.Activate()
- if Transformed or Activated == nil then
- return
- end
- if Activated then
- DeActivate()
- return
- end
- local Sound = _G.GetSound("Activate")
- Sound.Ended:Once(function()
- Activated = true
- PlayLoopingSound(_, "Idle")
- print(GetSelectedAlien())
- end)
- Sound.Volume = DEFAULT_VOLUME
- Sound.Parent = Player.Character["Right Arm"]
- Sound:Play()
- Activated = nil
- end
- function OmnitrixController.Turn(InputObject)
- if not Activated or Selected == nil then
- return
- end
- local Sound = GetDialSound()
- local InputKey = InputObject.KeyCode
- local NewValue = InputKey == Enum.KeyCode.E and 1 or -1
- local CachedSelection = Selected + NewValue
- Selected = nil
- Sound.Ended:Once(function()
- SetSelectedAlien(CachedSelection)
- print(GetSelectedAlien())
- end)
- Sound.Parent = Player.Character["Right Arm"]
- Sound:Play()
- end
- function OmnitrixController.Transform()
- if Transformed == nil or Transformed then
- return
- end
- local Character = Player.Character
- local Alien = Selection[Selected]
- local Sound = _G.GetSound("Transform")
- Transformed = nil
- DestroyLoopSounds()
- if not Activated then
- local Random = math.random(1, #Selection)
- print(Random)
- SetSelectedAlien(Random)
- local Sound = _G.GetSound("Activate")
- Sound.Volume = DEFAULT_VOLUME
- Sound.Parent = Player.Character["Right Arm"]
- Sound:Play()
- Sound.Ended:Wait()
- end
- ModelUtility.TransformTo(Character, Alien)
- Sound.Ended:Once(function()
- Transformed = true
- Activated = false
- Sound:Destroy()
- end)
- Sound.Volume = DEFAULT_VOLUME
- Sound.Parent = Player.Character["Right Arm"]
- Sound:Play()
- end
- function OmnitrixController.Revert()
- if not Transformed then
- return
- end
- local Character = Player.Character
- local Alien = Selection[Selected]
- local Warning = _G.GetSound("Warning")
- local Revert = _G.GetSound("Revert")
- local ThreeQuartersIn = (Revert.TimeLength / 4) * 3
- local TweenSound = TweenService:Create(Revert, TweenInfo.new(2), {Volume = DEFAULT_VOLUME})
- task.spawn(FlickerDialRed)
- task.delay(REVERT_TRASNFORM_POINT, function()
- ModelUtility.TransformTo(Character, DefaultCharacter, true)
- end)
- Transformed = nil
- Activated = false
- Revert.Ended:Once(function()
- Revert:Destroy()
- Transformed = false
- end)
- Revert.Volume = 0
- Revert.Parent = Player.Character["Right Arm"]
- Revert:Play()
- TweenSound:Play()
- local VolumeTween = TweenService:Create(Revert,
- TweenInfo.new(Revert.TimeLength / 4 - .1, Enum.EasingStyle.Linear), {Volume = 0})
- repeat
- task.wait()
- until Revert.TimePosition == ThreeQuartersIn
- VolumeTween:Play()
- Revert.Ended:Wait()
- print("Now no longer transformed.")
- end
- function OmnitrixController.Init()
- if Player.Character then
- OnCharacterAdded(Player.Character)
- end
- Player.CharacterAdded:Connect(OnCharacterAdded)
- end
- return OmnitrixController
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement