Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Quest System
- local UIS = game:GetService("UserInputService")
- local Players = game:GetService("Players").LocalPlayer
- local Character = Players.Character or Players.CharacterAdded:Wait()
- local Workspace = game:GetService("Workspace")
- local Quests = Workspace:WaitForChild("Quests")
- local RS = game:GetService("RunService")
- local Storage = game:GetService("ReplicatedStorage")
- local QuestModule = require(Storage:WaitForChild("Quests"))
- local Event = Storage:WaitForChild("QuestEvents").Quest
- local Frame = script.Parent.Frame
- local Target;
- local CurrentNumber = 1 -- add 1 every time player clicks continue
- local MaxDescription;
- function updateDialogue(newDesc)
- local getTarget = Quests:WaitForChild(Target).QuestName.Value
- if Event:InvokeServer('CheckCompleted', QuestModule.getObjective(getTarget) ) then
- print'this quest has been completed'
- Frame.Description.Text = QuestModule.CompletedValue(getTarget)
- Frame.CharacterName.Text = tostring(QuestModule.getCharacterName(getTarget))
- return
- end
- if QuestModule.getCompleted(Players, getTarget) then -- checking if player has quest already
- Frame.Description.Text = QuestModule.getCompValue(getTarget)
- Frame.CharacterName.Text = tostring(QuestModule.getCharacterName(getTarget) )
- return
- end
- print'boomer'
- Frame.Description.Text = newDesc
- Frame.CharacterName.Text = tostring(QuestModule.getCharacterName(getTarget) )
- end
- Frame:WaitForChild("Continue").MouseButton1Click:Connect(function()
- local getTarget = Quests:WaitForChild(Target).QuestName.Value
- if Event:InvokeServer('CheckCompleted', QuestModule.getObjective(getTarget) ) then
- print'this quest has been completed'
- Frame.Description.Text = QuestModule.CompletedValue(getTarget)
- Frame.CharacterName.Text = tostring(QuestModule.getCharacterName(getTarget))
- Event:InvokeServer('QuestCompleted', QuestModule.getObjective(getTarget) )
- Frame:TweenPosition(UDim2.new(0.286,0,-1,0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.5, true)
- script.Parent:WaitForChild("TextButton"):TweenPosition(UDim2.new(0.387,0,1.1,0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.5, true)
- return
- end
- if QuestModule.getCompleted(Players, getTarget) then -- checking if player has quest already
- Frame.Description.Text = QuestModule.getCompValue(getTarget)
- Frame.CharacterName.Text = tostring(QuestModule.getCharacterName(getTarget) )
- return
- end
- if CurrentNumber == MaxDescription then
- print'Give quest'
- local getTarget = Quests:WaitForChild(Target)
- print(getTarget.QuestName.Value)
- Event:InvokeServer('StartQuest', QuestModule.getObjective(getTarget.QuestName.Value), QuestModule.getRequirements(getTarget.QuestName.Value) )
- Frame:TweenPosition(UDim2.new(0.286,0,-1,0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.5, true)
- script.Parent:WaitForChild("TextButton"):TweenPosition(UDim2.new(0.387,0,1.1,0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.5, true)
- return
- end
- local getTarget = Quests:WaitForChild(Target)
- CurrentNumber = CurrentNumber + 1
- print(CurrentNumber)
- updateDialogue(QuestModule.getDialogue(getTarget.QuestName.Value)[CurrentNumber] )
- end)
- UIS.InputBegan:Connect(function(input, gpe)
- if gpe then return end
- if input.KeyCode == Enum.KeyCode.E then
- if Target == "" or Target == nil then print'nothing found yet' return end
- print(Target)
- local getTarget = Quests:WaitForChild(Target)
- if not getTarget then warn'fatal error could not get target' return end
- local Module = require(QuestModule.getModule(getTarget.QuestName.Value) )
- print'test again'
- local Dialogue = QuestModule.getDialogue(getTarget.QuestName.Value)
- print'test againnn'
- for i = 1, #Dialogue do
- MaxDescription = i
- end
- updateDialogue(Dialogue[CurrentNumber])
- print(CurrentNumber)
- if Frame.Open.Value == false then
- updateDialogue(Dialogue[CurrentNumber])
- Frame:TweenPosition(UDim2.new(0.286,0,0.215,0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.5, true)
- print'what?'
- Frame.Open.Value = true
- elseif Frame.Open.Value == true then
- Frame:TweenPosition(UDim2.new(0.286,0,-1,0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.5, true)
- Frame.Description.Text = ''
- Frame.Open.Value = false
- CurrentNumber = 1
- end
- end
- end)
- RS.RenderStepped:Connect(function()
- if Target == nil or Target == "" then
- for _,v in pairs(Quests:GetChildren()) do
- local Mag = (Character:WaitForChild('HumanoidRootPart').Position - v.HumanoidRootPart.Position).magnitude
- if Mag <= 7 then
- print'hi'
- Target = v.Name
- script.Parent:WaitForChild("TextButton"):TweenPosition(UDim2.new(0.387,0,0.908,0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.5, true)
- -- getting textbutton to tween (press E)
- end
- end
- end
- if Target ~= nil then
- local HRP = Quests:WaitForChild(Target).HumanoidRootPart
- if not HRP then return end
- if (Character:WaitForChild('HumanoidRootPart').Position - HRP.Position).magnitude > 7 then
- Target = nil
- script.Parent:WaitForChild("TextButton"):TweenPosition(UDim2.new(0.387,0,1.1,0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.5, true)
- Frame:TweenPosition(UDim2.new(0.286,0,-1,0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.5, true)
- CurrentNumber = 1
- MaxDescription = nil
- Frame.Open.Value = false
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement