Aquarius_Raverus

NPC System

Nov 8th, 2020
1,195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.64 KB | None | 0 0
  1. -- Tavern Interaction
  2.  
  3. local NPCs = workspace:WaitForChild("NPCs")
  4. local Storage = game:GetService("ReplicatedStorage")
  5. local Players = game:GetService("Players")
  6. local RS = game:GetService("RunService")
  7. local UIS = game:GetService("UserInputService")
  8. local TS = game:GetService("TweenService")
  9.  
  10. local Modules = Storage:WaitForChild("Modules")
  11. local TavernNPCs = NPCs:WaitForChild("TavernNPCs")
  12.  
  13. local SpringModule = require(Modules.Utils.spr)
  14. local Typewriter = require(Modules.Utils.Typewrite)
  15.  
  16. local Player = Players.LocalPlayer
  17. local Char = Player.Character or Player.CharacterAdded:Wait()
  18.  
  19. local PrimaryPart = Char:WaitForChild('HumanoidRootPart')
  20.  
  21. local NPCStorage = {};
  22.  
  23. local canInteract = true
  24.  
  25. local function getAmount(dict)
  26.     local i = 0
  27.    
  28.     for index,value in pairs(dict) do
  29.         i += 1
  30.     end
  31.    
  32.     return i
  33. end
  34.  
  35. UIS.InputBegan:Connect(function(input, gpe)
  36.     if gpe then return end
  37.    
  38.     if input.KeyCode == Enum.KeyCode.E then
  39.         if canInteract == false then return end
  40.        
  41.        
  42.         if getAmount(NPCStorage) == 0 then
  43.             return;
  44.         else
  45.            
  46.             if getAmount(NPCStorage) == 1 then
  47.                 for index,values in pairs(NPCStorage) do
  48.                     canInteract = false
  49.                    
  50.                     local NormalJump = Char.Humanoid.JumpPower
  51.                    
  52.                     Char.Humanoid.JumpPower = 0
  53.                    
  54.                     local bv = Instance.new("BodyVelocity", PrimaryPart)
  55.                     bv.Name = 'InteractionDialogue'
  56.                     bv.MaxForce = Vector3.new(999999,999999,999999)
  57.                     bv.Velocity = Vector3.new(0,0,0)
  58.                    
  59.                     Char.Humanoid.AutoRotate = false
  60.                    
  61.                     warn("Interact with ".. index.. ' | Hierarchy: '.. values:GetFullName().. ' | Quest Type: '.. values.NPCInfo.QuestType.Value..' Quest')
  62.                    
  63.                     local cam = workspace.CurrentCamera
  64.                     cam.CameraType = Enum.CameraType.Scriptable
  65.                    
  66.                     local tween = TS:Create(workspace.CurrentCamera, TweenInfo.new(0.7), {CFrame = values.CamPart.CFrame})
  67.                     tween:Play()
  68.                    
  69.                     script.Parent.TavernUI.Main.NPCName.Text = values.Head.Display.NPCName.Text
  70.                     script.Parent.TavernUI.Main.Role.Text = values.Head.Display.TitleName.Text
  71.                    
  72.                     SpringModule.target(script.Parent.TavernUI.Main, 1, 1.6, {
  73.                         Position = UDim2.fromScale(0, 0.823),
  74.                     })
  75.                    
  76.                     wait(0.5)
  77.                     -- change dialogue later
  78.                     Typewriter.typeWrite(script.Parent.TavernUI.Main.DialogueText, "Hey there! I'm Mitsuki. I need some help, do have a moment?")
  79.                    
  80.                     wait(0.5)
  81.                    
  82.                     local textTween1 = TS:Create(script.Parent.TavernUI.Main.Interact, TweenInfo.new(0.5), {TextTransparency = 0, TextStrokeTransparency = 0.7})
  83.                     textTween1:Play()
  84.            
  85.                     Typewriter.typeWrite(script.Parent.TavernUI.Main.Interact , "Sure, what happened?")
  86.                     local textTween2 = TS:Create(script.Parent.TavernUI.Main.Goodbye, TweenInfo.new(0.5), {TextTransparency = 0, TextStrokeTransparency = 0.7})
  87.                     textTween2:Play()
  88.                     Typewriter.typeWrite(script.Parent.TavernUI.Main.Goodbye , "Sorry, I'm a bit busy right now!")
  89.                    
  90.                     local yesCon;
  91.                     local noCon;
  92.                    
  93.                     local yesHover1;
  94.                     local noHover1;
  95.                    
  96.                     local yesHover2;
  97.                     local noHover2;
  98.                    
  99.                     yesHover1 = script.Parent.TavernUI.Main.Interact.MouseEnter:Connect(function()
  100.                         script.Parent.TavernUI.Main.Interact.TextColor3 = Color3.fromRGB(255,255,153)
  101.                     end)
  102.                    
  103.                     noHover1 = script.Parent.TavernUI.Main.Interact.MouseLeave:Connect(function()
  104.                         script.Parent.TavernUI.Main.Interact.TextColor3 = Color3.fromRGB(255,255,255)
  105.                     end)
  106.                    
  107.                     yesHover2 = script.Parent.TavernUI.Main.Goodbye.MouseEnter:Connect(function()
  108.                         script.Parent.TavernUI.Main.Goodbye.TextColor3 = Color3.fromRGB(255,255,153)
  109.                     end)
  110.                    
  111.                     noHover2 = script.Parent.TavernUI.Main.Goodbye.MouseLeave:Connect(function()
  112.                         script.Parent.TavernUI.Main.Goodbye.TextColor3 = Color3.fromRGB(255,255,255)
  113.                     end)
  114.                    
  115.                     yesCon = script.Parent.TavernUI.Main.Interact.MouseButton1Click:Connect(function()
  116.                        
  117.                     end)
  118.                     noCon = script.Parent.TavernUI.Main.Goodbye.MouseButton1Click:Connect(function()
  119.                        
  120.                         yesCon:Disconnect()
  121.                         noCon:Disconnect()
  122.                        
  123.                         yesHover1:Disconnect()
  124.                         noHover1:Disconnect()
  125.                        
  126.                         yesHover2:Disconnect()
  127.                         noHover2:Disconnect()
  128.                        
  129.                         local tween1 = TS:Create(script.Parent.TavernUI.Main.Interact, TweenInfo.new(0.5), {TextTransparency = 1, TextStrokeTransparency = 1})
  130.                         local tween2 = TS:Create(script.Parent.TavernUI.Main.Goodbye, TweenInfo.new(0.5), {TextTransparency = 1, TextStrokeTransparency = 1})
  131.                        
  132.                         tween1:Play()
  133.                         tween2:Play()
  134.                        
  135.                         tween2.Completed:Wait()
  136.                        
  137.                         script.Parent.TavernUI.Main.Interact.TextColor3 = Color3.fromRGB(255,255,255)
  138.                         script.Parent.TavernUI.Main.Goodbye.TextColor3 = Color3.fromRGB(255,255,255)
  139.                        
  140.                         Typewriter.typeWrite(script.Parent.TavernUI.Main.DialogueText, "Oh okay. It was worth a try!")
  141.                                                
  142.                         wait(0.2)
  143.                        
  144.                         SpringModule.target(script.Parent.TavernUI.Main, 1, 1.6, {
  145.                             Position = UDim2.fromScale(0, 1.1),
  146.                         })
  147.                        
  148.                         cam.CameraType = Enum.CameraType.Custom
  149.                        
  150.                         bv:Destroy()
  151.                         Char.Humanoid.JumpPower = NormalJump
  152.                         Char.Humanoid.AutoRotate = true
  153.                        
  154.                         coroutine.resume(coroutine.create(function()
  155.                             wait(2)
  156.                             canInteract = true
  157.                            
  158.                             script.Parent.TavernUI.Main.DialogueText.Text = ''
  159.                             script.Parent.TavernUI.Main.Goodbye.Text = ''
  160.                             script.Parent.TavernUI.Main.Interact.Text = ''
  161.                            
  162.                             script.Parent.TavernUI.Main.Interact.TextColor3 = Color3.fromRGB(255,255,255)
  163.                             script.Parent.TavernUI.Main.Goodbye.TextColor3 = Color3.fromRGB(255,255,255)
  164.                         end))
  165.                     end)
  166.                    
  167.                 end    
  168.             end
  169.         end
  170.     end
  171. end)
Advertisement
Add Comment
Please, Sign In to add comment