Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local UserInputService = game:GetService("UserInputService")
- local Knit = require(ReplicatedStorage.Packages.Knit)
- local Signal = require(ReplicatedStorage.Packages.Signal)
- local SkillModule = require(ReplicatedStorage.SharedSource.Externals.Utilities.SkillModule)
- local SkillsController = Knit.CreateController {
- Name = "SkillsController",
- SkillSystems = {},
- IsSkillButtonPressed = {},
- Toggle = false,
- SkillDisabled = false, -- if enabled, cannot skill for a while
- }
- local GameSettings = require(ReplicatedStorage.SharedSource.Datas.GameSettings)
- local plr = game.Players.LocalPlayer
- local clickSound = ReplicatedStorage.Assets.Sounds:WaitForChild("CastSkill")
- ---- Services
- local SkillsService, ProfileService
- ---- Controllers
- local DataController, MobileTargetSystemController, GamemodeController, HookController
- local function changeSkillColorButton(castSkill)
- if SkillsController.SkillDisabled then
- castSkill.ImageColor3 = Color3.fromRGB(152, 0, 0)
- else
- castSkill.ImageColor3 = Color3.fromRGB(0, 0, 0)
- end
- end
- local disableSkillBackupThread
- local maximumSkillDisablingTime = 10 -- modify this to increase the allowed time to disable hook
- function SkillsController:DisableSkillToggle(toggle: boolean)
- local controlsGui = plr.PlayerGui:WaitForChild("ControlsGui")
- local castSkill = controlsGui:WaitForChild("CastSkill")
- SkillsController.SkillDisabled = toggle
- changeSkillColorButton(castSkill)
- if disableSkillBackupThread and coroutine.status(disableSkillBackupThread) ~= "dead" then
- pcall(function()
- task.cancel(disableSkillBackupThread)
- end)
- end
- disableSkillBackupThread = task.delay(maximumSkillDisablingTime, function() -- timeout for disabling hook
- SkillsController:DisableSkillToggle(false)
- end)
- end
- local MobileTargetSystemCF
- function SkillsController:InputBeganSkill(user, skillName, interactionStep, infos)
- local skillSystem = SkillsController.SkillSystems[skillName]
- if not skillSystem then
- skillSystem = require(script:WaitForChild("Skills"):FindFirstChild(skillName) or script:WaitForChild("Skills"):FindFirstChild("Default"))
- end
- local canProceed = true
- if skillSystem.InputBeganSkill then
- skillSystem.InputBeganSkill(user, skillName, interactionStep, infos)
- end
- repeat
- game["Run Service"].RenderStepped:Wait()
- if skillSystem.OnUpdateBeganSkill then
- canProceed = skillSystem.OnUpdateBeganSkill(user, skillName, interactionStep, {
- ["MobileTargetSystemCF"] = MobileTargetSystemCF
- })
- end
- until not SkillsController.IsSkillButtonPressed[skillName]
- if skillSystem.InputEndedSkill then
- skillSystem.InputEndedSkill(user, skillName, interactionStep, infos)
- end
- return canProceed
- end
- local cds = {}
- function SkillsController:InitiateSkill(user, skillName, interactionStep, infos)
- if not SkillsController.SkillSystems[skillName] then
- SkillsController.SkillSystems[skillName] = require(script:WaitForChild("Skills"):FindFirstChild(skillName) or script:WaitForChild("Skills"):FindFirstChild("Default"))
- end
- local skillData = SkillModule.FindSkillData(skillName)
- if interactionStep == 1 then
- if cds[skillName] then
- return
- end
- local cooldownTime = skillData.SkillVariables.Cooldown
- cds[skillName] = true
- local controlsGui = plr.PlayerGui:WaitForChild("ControlsGui")
- local castSkill = controlsGui.CastSkill
- if GameSettings.NumberOfSkillsEquippable > 1 then
- local profileData = DataController.Data
- local found = table.find(profileData.SkillsEquipped, skillName)
- if found then
- castSkill = controlsGui["CastSkill"..found]
- end
- end
- if castSkill then
- castSkill.Cooldown.Visible = true
- castSkill.Cooldown.ImageRectSize = Vector2.new(256,256)
- castSkill.Cooldown.Size = UDim2.new(1,0,1,0)
- local Tween = game.TweenService:Create(castSkill.Cooldown,TweenInfo.new(cooldownTime,Enum.EasingStyle.Linear),{
- Size = UDim2.new(1,0,0,0),
- ImageRectSize = Vector2.new(256, 0)
- })
- Tween:Play()
- task.spawn(function()
- local loopAmountPerSecond = 10*cooldownTime
- castSkill.CooldownText.Visible = true
- for i=1,loopAmountPerSecond do
- local timeNow = math.round((cooldownTime - ((cooldownTime/loopAmountPerSecond)*i))*100)/100
- castSkill.CooldownText.Text = timeNow.."s"
- task.wait(cooldownTime/loopAmountPerSecond)
- end
- castSkill.CooldownText.Text = ""
- end)
- task.delay(cooldownTime, function()
- cds[skillName] = false
- castSkill.Cooldown.Visible = false
- end)
- end
- end
- SkillsController.SkillSystems[skillName].Interactions[interactionStep](user, skillName, interactionStep, infos)
- end
- function SkillsController:FireToServer(user, skillName, interactionStep, infos, bypassUserOnlyFilter: boolean)
- local userPlayerIns = game.Players:GetPlayerFromCharacter(user)
- if (userPlayerIns and userPlayerIns ~= plr) and not bypassUserOnlyFilter then
- if game["Run Service"]:IsStudio() then
- print("Cannot fire, skill user ~= plr")
- end
- end
- if ((userPlayerIns and userPlayerIns == plr) or bypassUserOnlyFilter) or (infos.PlayerNetworkOwner ~= nil and plr.Name == infos.PlayerNetworkOwner.Name) then
- SkillsService.InitiateSkill:Fire(user, skillName, interactionStep, infos)
- end
- end
- -- confirms if self or NPC that is assigned to the player
- function SkillsController:IsSelfOrNPC(user, skillName, interactionStep, infos, bypassUserOnlyFilter: boolean)
- return user == plr.Character or (infos.PlayerNetworkOwner ~= nil and plr.Name == infos.PlayerNetworkOwner.Name)
- end
- function SkillsController:KnitStart()
- DataController:WaitUntilProfileLoaded()
- local profileData = DataController.Data
- local controlsGui = plr.PlayerGui:WaitForChild("ControlsGui")
- local function setSkill(i)
- local castSkill = controlsGui:WaitForChild("CastSkill")
- if GameSettings.NumberOfSkillsEquippable > 1 then
- castSkill = controlsGui:WaitForChild("CastSkill"..i, 5)
- end
- local skillData = SkillModule.FindSkillData(profileData.SkillsEquipped[i])
- if skillData then
- castSkill.ImageLabel.Image = skillData.Image
- else
- castSkill.ImageLabel.Image = ""
- end
- end
- for i=1,GameSettings.NumberOfSkillsEquippable do
- setSkill(i)
- end
- ProfileService.UpdateSpecificData:Connect(function(Redirectories,newValue)
- if Redirectories[1] == "SkillsEquipped" then
- task.wait(.1)
- for i=1,GameSettings.NumberOfSkillsEquippable do
- setSkill(i)
- end
- end
- end)
- local function inputEndedSkill(plr, equipNum)
- clickSound:Play()
- SkillsController:InitiateSkill(plr.Character, profileData.SkillsEquipped[equipNum], 1, {
- ["MobileTargetSystemCF"] = MobileTargetSystemCF
- })
- end
- local function inputBeganSkill(plr, equipNum)
- local skillName = profileData.SkillsEquipped[equipNum]
- if cds[skillName] then
- return
- end
- if SkillsController.SkillDisabled or not GamemodeController.ControlsEnabled then
- return
- end
- local canProceed = SkillsController:InputBeganSkill(plr.Character, profileData.SkillsEquipped[equipNum], 1, {})
- if canProceed then
- inputEndedSkill(plr, equipNum)
- end
- end
- UserInputService.InputBegan:Connect(function(Input, Other)
- -- ButtonA is counted as jump so it doesn't detect it
- if Input.KeyCode == Enum.KeyCode.X or Input.KeyCode == Enum.KeyCode.ButtonA then
- if profileData.SkillsEquipped[2] then
- SkillsController.IsSkillButtonPressed[profileData.SkillsEquipped[2]] = true
- inputBeganSkill(plr, 2)
- end
- end
- if Other then
- return
- end
- if GameSettings.NumberOfSkillsEquippable == 1 then
- if Input.KeyCode == Enum.KeyCode.Q or Input.KeyCode == Enum.KeyCode.ButtonX then
- SkillsController.IsSkillButtonPressed[profileData.SkillsEquipped[1]] = true
- inputBeganSkill(plr, 1)
- end
- else
- -- 2+ skills
- if Input.KeyCode == Enum.KeyCode.Z or Input.KeyCode == Enum.KeyCode.ButtonX then
- if profileData.SkillsEquipped[1] then
- SkillsController.IsSkillButtonPressed[profileData.SkillsEquipped[1]] = true
- inputBeganSkill(plr, 1)
- end
- elseif Input.KeyCode == Enum.KeyCode.C or Input.KeyCode == Enum.KeyCode.ButtonB then
- if profileData.SkillsEquipped[3] then
- SkillsController.IsSkillButtonPressed[profileData.SkillsEquipped[3]] = true
- inputBeganSkill(plr, 3)
- end
- end
- end
- end)
- UserInputService.InputEnded:Connect(function(Input, Other)
- if GameSettings.NumberOfSkillsEquippable == 1 then
- if Input.KeyCode == Enum.KeyCode.Q or Input.KeyCode == Enum.KeyCode.ButtonX then
- SkillsController.IsSkillButtonPressed[profileData.SkillsEquipped[1]] = false
- end
- else
- -- 2+ skills
- if Input.KeyCode == Enum.KeyCode.Z or Input.KeyCode == Enum.KeyCode.ButtonX then
- if profileData.SkillsEquipped[1] then
- SkillsController.IsSkillButtonPressed[profileData.SkillsEquipped[1]] = false
- end
- elseif Input.KeyCode == Enum.KeyCode.X or Input.KeyCode == Enum.KeyCode.ButtonA then
- if profileData.SkillsEquipped[2] then
- SkillsController.IsSkillButtonPressed[profileData.SkillsEquipped[2]] = false
- end
- elseif Input.KeyCode == Enum.KeyCode.C or Input.KeyCode == Enum.KeyCode.ButtonB then
- if profileData.SkillsEquipped[3] then
- SkillsController.IsSkillButtonPressed[profileData.SkillsEquipped[3]] = false
- end
- end
- end
- end)
- local chainSystem = HookController.ChainSystem
- local otherDatas = {
- OnEnabledMobileTargetSystem = function()
- local skillEquipped = profileData.SkillsEquipped[1]
- SkillsController.IsSkillButtonPressed[skillEquipped] = true
- task.spawn(function()
- inputBeganSkill(plr, 1)
- end)
- end,
- OnInputChangedFunction = function(CFTarget)
- local skillEquipped = profileData.SkillsEquipped[1]
- SkillsController.IsSkillButtonPressed[skillEquipped] = true
- MobileTargetSystemCF = CFTarget
- chainSystem.CustomCFToFace = CFTarget
- end,
- Release = function()
- local skillEquipped = profileData.SkillsEquipped[1]
- SkillsController.IsSkillButtonPressed[skillEquipped] = false
- chainSystem.CustomCFToFace = nil
- end,
- OnCancelledFunction = function()
- local skillEquipped = profileData.SkillsEquipped[1]
- SkillsController.IsSkillButtonPressed[skillEquipped] = false
- chainSystem.CustomCFToFace = nil
- end,
- }
- local castSkill = controlsGui:WaitForChild("CastSkill")
- MobileTargetSystemController:SetupMobileTargetSystem(castSkill, otherDatas)
- for i=1,3 do
- local castSkill = controlsGui:WaitForChild("CastSkill"..i)
- local otherDatas = {
- OnEnabledMobileTargetSystem = function()
- local skillEquipped = profileData.SkillsEquipped[i]
- SkillsController.IsSkillButtonPressed[skillEquipped] = true
- task.spawn(function()
- inputBeganSkill(plr, i)
- end)
- end,
- OnInputChangedFunction = function(CFTarget)
- local skillEquipped = profileData.SkillsEquipped[i]
- SkillsController.IsSkillButtonPressed[skillEquipped] = true
- MobileTargetSystemCF = CFTarget
- chainSystem.CustomCFToFace = CFTarget
- end,
- Release = function()
- local skillEquipped = profileData.SkillsEquipped[i]
- SkillsController.IsSkillButtonPressed[skillEquipped] = false
- chainSystem.CustomCFToFace = nil
- end,
- OnCancelledFunction = function()
- local skillEquipped = profileData.SkillsEquipped[i]
- SkillsController.IsSkillButtonPressed[skillEquipped] = false
- chainSystem.CustomCFToFace = nil
- end,
- }
- MobileTargetSystemController:SetupMobileTargetSystem(castSkill, otherDatas)
- end
- if GameSettings.NumberOfSkillsEquippable > 1 then
- castSkill.Visible = false
- for i=1,GameSettings.NumberOfSkillsEquippable do
- local castSkill = controlsGui:WaitForChild("CastSkill"..i, 6)
- castSkill.Visible = true
- end
- else
- end
- SkillsService.InitiateSkill:Connect(function(...)
- SkillsController:InitiateSkill(...)
- end)
- for i,v in pairs(script:WaitForChild("Skills"):GetChildren()) do
- local succ, err = pcall(function()
- local skillName = v.Name
- if not SkillsController.SkillSystems[skillName] then
- SkillsController.SkillSystems[skillName] = require(script:WaitForChild("Skills"):FindFirstChild(skillName) or script:WaitForChild("Skills"):FindFirstChild("Default"))
- end
- SkillsController.SkillSystems[skillName].Initiate()
- end)
- if not succ then
- warn(err)
- end
- end
- end
- function SkillsController:KnitInit()
- SkillsService = Knit.GetService("SkillsService")
- ProfileService = Knit.GetService("ProfileService")
- DataController = Knit.GetController("DataController")
- MobileTargetSystemController = Knit.GetController("MobileTargetSystemController")
- GamemodeController = Knit.GetController("GamemodeController")
- HookController = Knit.GetController("HookController")
- end
- return SkillsController
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement