Advertisement
TaylorsRus

Untitled

Apr 17th, 2024
761
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.49 KB | None | 0 0
  1. local OmnitrixController = {}
  2.  
  3. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  4. local TweenService = game:GetService("TweenService")
  5. local SoundService = game:GetService("SoundService")
  6.  
  7. local Player = game:GetService("Players").LocalPlayer
  8.  
  9. local Packages = ReplicatedStorage:WaitForChild("Packages")
  10. local Aliens = ReplicatedStorage:WaitForChild("Aliens")
  11.  
  12. local ModelUtility = require(Packages:WaitForChild("ModelUtility"))
  13.  
  14. local Activated = false
  15. local Transformed = false
  16. local DefaultCharacter = nil
  17.  
  18. local REVERT_LOOP_SPEED  = 1.4
  19. local REVERT_LOOP_PITCH = .65
  20. local REVERT_TRASNFORM_POINT = 3
  21. local REVERT_FLICKER_DELAY = .5
  22.  
  23. local IDLE_LOOP_SPEED = 1.13
  24. local IDLE_LOOP_PITCH = .9
  25. local IDLE_VOLUME = .5
  26.  
  27. local DEFAULT_VOLUME = 7
  28.  
  29. local UsedDialSounds = {}
  30. local Selection =  {
  31.     [1] = Aliens:WaitForChild("Tetramand"),
  32. }
  33. local Selected = 1
  34.  
  35. local function OnCharacterAdded(Character)
  36.     Character.Archivable = true
  37.     DefaultCharacter = Character:Clone()
  38. end
  39.  
  40. local function GetSelectedAlien()
  41.     return Selection[Selected]
  42. end
  43.  
  44. local function SetSelectedAlien(NewValue)
  45.     if NewValue > #Selection then
  46.         NewValue = 1
  47.     elseif NewValue <= 0 then
  48.         NewValue = #Selection
  49.     end
  50.    
  51.     Selected = NewValue
  52. end
  53.  
  54. local function GetDialSound()
  55.     local Sounds = _G.GetSound("Turned")
  56.     local RandomInt = nil
  57.    
  58.     if #UsedDialSounds == #Sounds then
  59.         UsedDialSounds = {}
  60.     end
  61.  
  62.     repeat
  63.         RandomInt = math.random(1, #Sounds)
  64.         task.wait()
  65.     until not UsedDialSounds[RandomInt]
  66.     local Sound = Sounds[RandomInt]
  67.    
  68.     UsedDialSounds[RandomInt] = Sound
  69.     return Sound
  70. end
  71.  
  72. local function FlickerDialRed(Color)
  73.     local Character = Player.Character
  74.     local Omnitrix = Character:FindFirstChild("Omnitrix", true)
  75.     local Hourglass = Omnitrix:FindFirstChild("Hourglass", true)
  76.    
  77.     local CachedMaterial = Hourglass.Material
  78.     local CachedColor = Hourglass.Color
  79.    
  80.     while Transformed ~= false do
  81.         if not Hourglass then
  82.             break
  83.         end
  84.        
  85.         Hourglass.Material = Enum.Material.Neon
  86.         Hourglass.BrickColor = BrickColor.new("Really red")
  87.         task.wait(REVERT_FLICKER_DELAY)
  88.        
  89.         Hourglass.Material = CachedMaterial
  90.         Hourglass.Color = CachedColor
  91.         task.wait(REVERT_FLICKER_DELAY)
  92.     end
  93. end
  94.  
  95. local function ChangeModelTransparency(Model, Value)
  96.     for _,Component in Model:GetDescendants() do
  97.         if not Component:IsA("Part") then
  98.             continue
  99.         end
  100.  
  101.         Component.Transparency = Value
  102.     end
  103. end
  104.  
  105. local function PlayLoopingSound(Omnitrix, Loop)
  106.     local Sound = _G.GetSound(Loop)
  107.     local PitchShift = Instance.new("PitchShiftSoundEffect")
  108.  
  109.     local Speed = Loop == "Idle" and IDLE_LOOP_SPEED or REVERT_LOOP_SPEED
  110.     local Pitch = Loop == "Idle" and IDLE_LOOP_PITCH or REVERT_LOOP_PITCH
  111.     local Volume = Loop == "Idle" and IDLE_VOLUME
  112.    
  113.     Sound.PlaybackSpeed = Speed
  114.     Sound.Volume = Volume
  115.     Sound.Looped = true
  116.     Sound.Parent = Omnitrix and Omnitrix or Player.Character["Right Arm"]
  117.     PitchShift.Octave = Pitch
  118.     PitchShift.Parent = Sound  
  119.    
  120.     Sound:Play()
  121. end
  122.  
  123. local function DestroyLoopSounds(Omnitrix)
  124.     local Model = Omnitrix and Omnitrix or Player.Character["Right Arm"]
  125.    
  126.     for _,Sound in ipairs(Model:GetChildren()) do
  127.         if not Sound:IsA("Sound") or not Sound.Looped then
  128.             continue
  129.         end
  130.        
  131.         Sound:Destroy()
  132.     end
  133. end
  134.  
  135. local function DeActivate(Omnitrix)
  136.     if Activated == nil then
  137.         return
  138.     end
  139.     local Sound = _G.GetSound("DialDown")
  140.  
  141.     Activated = nil
  142.     DestroyLoopSounds()
  143.    
  144.     Sound.Ended:Once(function()
  145.         Activated = false
  146.         Sound:Destroy()
  147.     end)
  148.     Sound.Parent = Omnitrix and Omnitrix or Player.Character["Right Arm"]
  149.     Sound:Play()
  150. end
  151.  
  152. function OmnitrixController.Activate()
  153.     if Transformed or Activated == nil then
  154.         return
  155.     end
  156.     if Activated then
  157.         DeActivate()
  158.         return
  159.     end
  160.     local Sound = _G.GetSound("Activate")
  161.  
  162.     Sound.Ended:Once(function()
  163.         Activated = true
  164.         PlayLoopingSound(_, "Idle")
  165.         print(GetSelectedAlien())
  166.     end)
  167.     Sound.Volume = DEFAULT_VOLUME
  168.     Sound.Parent = Player.Character["Right Arm"]
  169.     Sound:Play()
  170.    
  171.     Activated = nil
  172. end
  173.  
  174. function OmnitrixController.Turn(InputObject)
  175.     if not Activated or Selected == nil then
  176.         return 
  177.     end
  178.    
  179.     local Sound = GetDialSound()
  180.    
  181.     local InputKey = InputObject.KeyCode
  182.     local NewValue = InputKey == Enum.KeyCode.E and 1 or -1
  183.     local CachedSelection = Selected + NewValue
  184.    
  185.     Selected = nil
  186.     Sound.Ended:Once(function()
  187.         SetSelectedAlien(CachedSelection)
  188.         print(GetSelectedAlien())
  189.     end)
  190.     Sound.Parent = Player.Character["Right Arm"]
  191.     Sound:Play()
  192. end
  193.  
  194. function OmnitrixController.Transform()
  195.     if Transformed == nil or Transformed then
  196.         return
  197.     end
  198.    
  199.     local Character = Player.Character
  200.     local Alien = Selection[Selected]
  201.    
  202.     local Sound = _G.GetSound("Transform")
  203.        
  204.     Transformed = nil
  205.  
  206.     DestroyLoopSounds()
  207.     if not Activated then
  208.         local Random = math.random(1, #Selection)
  209.         print(Random)
  210.        
  211.         SetSelectedAlien(Random)
  212.        
  213.         local Sound = _G.GetSound("Activate")
  214.         Sound.Volume = DEFAULT_VOLUME
  215.         Sound.Parent = Player.Character["Right Arm"]
  216.         Sound:Play()       
  217.         Sound.Ended:Wait()
  218.     end
  219.    
  220.     ModelUtility.TransformTo(Character, Alien)
  221.     Sound.Ended:Once(function()
  222.         Transformed = true
  223.         Activated = false
  224.        
  225.         Sound:Destroy()
  226.     end)
  227.     Sound.Volume = DEFAULT_VOLUME
  228.     Sound.Parent = Player.Character["Right Arm"]
  229.     Sound:Play()
  230. end
  231.  
  232. function OmnitrixController.Revert()
  233.     if not Transformed then
  234.         return
  235.     end
  236.    
  237.     local Character = Player.Character
  238.     local Alien = Selection[Selected]
  239.    
  240.     local Warning = _G.GetSound("Warning")
  241.     local Revert = _G.GetSound("Revert")
  242.    
  243.     local ThreeQuartersIn = (Revert.TimeLength / 4) * 3
  244.    
  245.     local TweenSound = TweenService:Create(Revert, TweenInfo.new(2), {Volume = DEFAULT_VOLUME})
  246.    
  247.     task.spawn(FlickerDialRed)
  248.     task.delay(REVERT_TRASNFORM_POINT, function()
  249.         ModelUtility.TransformTo(Character, DefaultCharacter, true)
  250.     end)
  251.    
  252.     Transformed = nil
  253.     Activated = false
  254.    
  255.     Revert.Ended:Once(function()
  256.         Revert:Destroy()
  257.         Transformed = false
  258.     end)   
  259.     Revert.Volume = 0
  260.     Revert.Parent =  Player.Character["Right Arm"]
  261.     Revert:Play()
  262.     TweenSound:Play()
  263.    
  264.     local VolumeTween = TweenService:Create(Revert,
  265.         TweenInfo.new(Revert.TimeLength / 4 - .1, Enum.EasingStyle.Linear), {Volume = 0})
  266.    
  267.     repeat
  268.         task.wait()
  269.     until Revert.TimePosition == ThreeQuartersIn
  270.  
  271.     VolumeTween:Play()
  272.     Revert.Ended:Wait()
  273.  
  274.     print("Now no longer transformed.")
  275. end
  276.  
  277. function OmnitrixController.Init()
  278.     if Player.Character then
  279.         OnCharacterAdded(Player.Character)
  280.     end
  281.     Player.CharacterAdded:Connect(OnCharacterAdded)
  282. end
  283.  
  284.  
  285. return OmnitrixController
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement