Advertisement
Aquarius_Raverus

Quest System pain

Jun 7th, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.49 KB | None | 0 0
  1. -- Quest System
  2.  
  3. local UIS = game:GetService("UserInputService")
  4. local Players = game:GetService("Players").LocalPlayer
  5. local Character = Players.Character or Players.CharacterAdded:Wait()
  6.  
  7. local Workspace = game:GetService("Workspace")
  8. local Quests = Workspace:WaitForChild("Quests")
  9.  
  10. local RS = game:GetService("RunService")
  11. local Storage = game:GetService("ReplicatedStorage")
  12.  
  13. local QuestModule = require(Storage:WaitForChild("Quests"))
  14. local Event = Storage:WaitForChild("QuestEvents").Quest
  15.  
  16. local Frame = script.Parent.Frame
  17.  
  18. local Target;
  19. local CurrentNumber = 1 -- add 1 every time player clicks continue
  20. local MaxDescription;
  21.  
  22. function updateDialogue(newDesc)
  23.     local getTarget = Quests:WaitForChild(Target).QuestName.Value
  24.    
  25.     if Event:InvokeServer('CheckCompleted', QuestModule.getObjective(getTarget) )  then
  26.         print'this quest has been completed'
  27.        
  28.         Frame.Description.Text = QuestModule.CompletedValue(getTarget)
  29.         Frame.CharacterName.Text = tostring(QuestModule.getCharacterName(getTarget))
  30.        
  31.         return
  32.     end
  33.    
  34.     if QuestModule.getCompleted(Players, getTarget) then -- checking if player has quest already
  35.        
  36.         Frame.Description.Text = QuestModule.getCompValue(getTarget)
  37.         Frame.CharacterName.Text = tostring(QuestModule.getCharacterName(getTarget) )
  38.        
  39.         return
  40.     end
  41.  
  42.    
  43.     print'boomer'
  44.    
  45.     Frame.Description.Text = newDesc
  46.     Frame.CharacterName.Text = tostring(QuestModule.getCharacterName(getTarget) )
  47. end
  48.  
  49. Frame:WaitForChild("Continue").MouseButton1Click:Connect(function()
  50.     local getTarget = Quests:WaitForChild(Target).QuestName.Value
  51.    
  52.     if Event:InvokeServer('CheckCompleted', QuestModule.getObjective(getTarget) )  then
  53.         print'this quest has been completed'
  54.        
  55.         Frame.Description.Text = QuestModule.CompletedValue(getTarget)
  56.         Frame.CharacterName.Text = tostring(QuestModule.getCharacterName(getTarget))
  57.        
  58.         Event:InvokeServer('QuestCompleted', QuestModule.getObjective(getTarget) )
  59.        
  60.        
  61.         Frame:TweenPosition(UDim2.new(0.286,0,-1,0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.5, true)
  62.         script.Parent:WaitForChild("TextButton"):TweenPosition(UDim2.new(0.387,0,1.1,0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.5, true)
  63.        
  64.         return
  65.     end
  66.    
  67.    
  68.     if QuestModule.getCompleted(Players, getTarget) then -- checking if player has quest already
  69.        
  70.         Frame.Description.Text = QuestModule.getCompValue(getTarget)
  71.         Frame.CharacterName.Text = tostring(QuestModule.getCharacterName(getTarget) )
  72.         return
  73.     end
  74.    
  75.     if CurrentNumber == MaxDescription then
  76.         print'Give quest'
  77.        
  78.         local getTarget = Quests:WaitForChild(Target)
  79.         print(getTarget.QuestName.Value)
  80.        
  81.         Event:InvokeServer('StartQuest', QuestModule.getObjective(getTarget.QuestName.Value), QuestModule.getRequirements(getTarget.QuestName.Value) )
  82.        
  83.         Frame:TweenPosition(UDim2.new(0.286,0,-1,0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.5, true)
  84.         script.Parent:WaitForChild("TextButton"):TweenPosition(UDim2.new(0.387,0,1.1,0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.5, true)
  85.        
  86.         return
  87.     end
  88.        
  89.     local getTarget = Quests:WaitForChild(Target)
  90.    
  91.     CurrentNumber = CurrentNumber + 1
  92.     print(CurrentNumber)
  93.     updateDialogue(QuestModule.getDialogue(getTarget.QuestName.Value)[CurrentNumber] )
  94. end)
  95.  
  96. UIS.InputBegan:Connect(function(input, gpe)
  97.     if gpe then return end
  98.    
  99.     if input.KeyCode == Enum.KeyCode.E then
  100.         if Target == "" or Target == nil then print'nothing found yet' return end
  101.        
  102.         print(Target)
  103.        
  104.         local getTarget = Quests:WaitForChild(Target)
  105.         if not getTarget then warn'fatal error could not get target' return end
  106.        
  107.         local Module = require(QuestModule.getModule(getTarget.QuestName.Value) )
  108.         print'test again'
  109.         local Dialogue = QuestModule.getDialogue(getTarget.QuestName.Value)
  110.         print'test againnn'
  111.        
  112.         for i = 1, #Dialogue do
  113.             MaxDescription = i
  114.         end
  115.        
  116.         updateDialogue(Dialogue[CurrentNumber])
  117.        
  118.         print(CurrentNumber)
  119.                
  120.        
  121.         if Frame.Open.Value == false then
  122.             updateDialogue(Dialogue[CurrentNumber])
  123.            
  124.        
  125.             Frame:TweenPosition(UDim2.new(0.286,0,0.215,0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.5, true)
  126.             print'what?'
  127.             Frame.Open.Value = true
  128.         elseif Frame.Open.Value == true then
  129.            
  130.             Frame:TweenPosition(UDim2.new(0.286,0,-1,0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.5, true)
  131.             Frame.Description.Text = ''
  132.            
  133.             Frame.Open.Value = false
  134.             CurrentNumber = 1
  135.         end
  136.     end
  137.    
  138. end)
  139.  
  140. RS.RenderStepped:Connect(function()
  141.     if Target == nil or Target == "" then
  142.    
  143.         for _,v in pairs(Quests:GetChildren()) do
  144.             local Mag = (Character:WaitForChild('HumanoidRootPart').Position - v.HumanoidRootPart.Position).magnitude
  145.                    
  146.             if Mag <= 7 then
  147.                 print'hi'
  148.                
  149.                 Target = v.Name
  150.                
  151.                 script.Parent:WaitForChild("TextButton"):TweenPosition(UDim2.new(0.387,0,0.908,0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.5, true)
  152.                 -- getting textbutton to tween (press E)
  153.                
  154.             end
  155.         end
  156.     end
  157.    
  158.     if Target ~= nil then
  159.         local HRP = Quests:WaitForChild(Target).HumanoidRootPart
  160.        
  161.         if not HRP then return end
  162.        
  163.         if (Character:WaitForChild('HumanoidRootPart').Position - HRP.Position).magnitude > 7 then
  164.             Target = nil
  165.             script.Parent:WaitForChild("TextButton"):TweenPosition(UDim2.new(0.387,0,1.1,0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.5, true)
  166.             Frame:TweenPosition(UDim2.new(0.286,0,-1,0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.5, true)
  167.            
  168.             CurrentNumber = 1
  169.             MaxDescription = nil
  170.            
  171.             Frame.Open.Value = false
  172.         end
  173.     end
  174.    
  175. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement