Not a member of gistpad yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local UserInputService = game:GetService("UserInputService")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local StarterGui = game:GetService("StarterGui")
- local TweenService = game:GetService("TweenService")
- print("--- ЗАПУСК КОНТРОЛЛЕРА (v14: Mana System Integration) ---")
- local player = Players.LocalPlayer
- local gui = script.Parent
- local hotbar = gui:WaitForChild("Hotbar")
- local menuFrame = gui:WaitForChild("AbilityMenu")
- local openMenuBtn = gui:WaitForChild("OpenMenuBtn")
- local AbilitiesFolder = ReplicatedStorage:WaitForChild("Abilities")
- local resetButton = menuFrame:FindFirstChild("ResetButton")
- -- ==============================================================
- -- 1. ФУНКЦИЯ ВИЗУАЛЬНОГО КУЛДАУНА
- -- ==============================================================
- local function PlayCooldownAnimation(slotBtn, duration)
- local cdFrame = slotBtn:FindFirstChild("CooldownOverlay")
- if not cdFrame then
- cdFrame = Instance.new("Frame")
- cdFrame.Name = "CooldownOverlay"
- cdFrame.Size = UDim2.new(1, 0, 1, 0)
- cdFrame.Position = UDim2.new(0,0,0,0)
- cdFrame.BackgroundColor3 = Color3.new(0, 0, 0)
- cdFrame.BackgroundTransparency = 0.3
- cdFrame.ZIndex = 10
- cdFrame.Parent = slotBtn
- local corner = Instance.new("UICorner")
- corner.CornerRadius = UDim.new(0, 8)
- corner.Parent = cdFrame
- local text = Instance.new("TextLabel")
- text.Name = "TimerText"
- text.Size = UDim2.new(0.5, 0, 0.5, 0)
- text.Position = UDim2.new(0.25, 0, 0.25, 0)
- text.BackgroundTransparency = 1
- text.TextColor3 = Color3.new(1, 1, 1)
- text.TextScaled = true
- text.Font = Enum.Font.GothamBold
- text.ZIndex = 11
- text.Parent = cdFrame
- end
- local textLabel = cdFrame.TimerText
- cdFrame.Visible = true
- task.spawn(function()
- local startTime = tick()
- while tick() - startTime < duration do
- local timeLeft = duration - (tick() - startTime)
- if timeLeft < 1 then
- textLabel.Text = string.format("%.1f", timeLeft)
- else
- textLabel.Text = math.ceil(timeLeft)
- end
- task.wait(0.1)
- end
- cdFrame.Visible = false
- end)
- end
- -- ==============================================================
- -- 2. ЛОГИКА СБРОСА
- -- ==============================================================
- local currentLoadout = {}
- local cooldowns = {}
- if resetButton then
- resetButton.MouseButton1Click:Connect(function()
- currentLoadout = {}
- for _, child in pairs(hotbar:GetChildren()) do
- if child:IsA("ImageButton") or child:IsA("TextButton") then
- child.Image = ""
- local overlay = child:FindFirstChild("CooldownOverlay")
- if overlay then overlay.Visible = false end
- end
- end
- end)
- end
- -- ==============================================================
- -- 3. ЗАГРУЗКА И НАСТРОЙКА СЛОТОВ
- -- ==============================================================
- openMenuBtn.MouseButton1Click:Connect(function()
- menuFrame.Visible = not menuFrame.Visible
- end)
- local AbilityModules = {}
- local selectedAbilityName = nil
- for _, module in pairs(AbilitiesFolder:GetChildren()) do
- if module:IsA("ModuleScript") then
- local success, result = pcall(function() return require(module) end)
- if success then
- AbilityModules[module.Name] = result
- local btnName = module.Name .. "Icon"
- local btn = menuFrame:FindFirstChild(btnName)
- if btn then
- btn.MouseButton1Click:Connect(function()
- selectedAbilityName = module.Name
- print("🔵 ВЫБРАНО: " .. module.Name)
- end)
- end
- end
- end
- end
- for _, child in pairs(hotbar:GetChildren()) do
- if child:IsA("ImageButton") or child:IsA("TextButton") then
- child.MouseButton1Click:Connect(function()
- if selectedAbilityName then
- local module = AbilityModules[selectedAbilityName]
- if not module or not module.Info then return end
- for slot, ability in pairs(currentLoadout) do
- if ability == selectedAbilityName then
- currentLoadout[slot] = nil
- local oldBtn = hotbar:FindFirstChild(slot)
- if oldBtn then oldBtn.Image = "" end
- end
- end
- currentLoadout[child.Name] = selectedAbilityName
- child.Image = module.Info.Icon
- print("🎉 УСПЕХ! " .. selectedAbilityName .. " -> " .. child.Name)
- selectedAbilityName = nil
- end
- end)
- end
- end
- -- ==============================================================
- -- 4. АКТИВАЦИЯ С ПРОВЕРКОЙ МАНЫ
- -- ==============================================================
- local ControllerAPI = {}
- function ControllerAPI.ShowNotification(text)
- StarterGui:SetCore("SendNotification", {Title = "Ability"; Text = text; Duration = 2;})
- end
- local keyMap = {
- [Enum.KeyCode.E] = "Slot1", [Enum.KeyCode.R] = "Slot2",
- [Enum.KeyCode.X] = "Slot3", [Enum.KeyCode.F] = "Slot4",
- [Enum.KeyCode.V] = "Slot5", [Enum.KeyCode.C] = "Slot6"
- }
- UserInputService.InputBegan:Connect(function(input, gp)
- if gp then return end
- local slotName = keyMap[input.KeyCode]
- if slotName then
- local abilityName = currentLoadout[slotName]
- if abilityName and AbilityModules[abilityName] then
- local module = AbilityModules[abilityName]
- -- [НОВОЕ] ПРОВЕРКА МАНЫ ПЕРЕД НАЖАТИЕМ
- local char = player.Character
- if char then
- local currentMana = char:GetAttribute("Mana") or 0
- local manaCost = module.Info.ManaCost or 0
- if currentMana < manaCost then
- ControllerAPI.ShowNotification("Мана: " .. math.floor(currentMana) .. "/" .. manaCost)
- return -- ОТМЕНА, ЕСЛИ НЕТ МАНЫ
- end
- end
- -- Проверка Кулдауна
- local lastTime = cooldowns[abilityName] or 0
- local cdTime = module.Info.Cooldown or 0
- if tick() - lastTime < cdTime then return end
- -- Активация
- local success = module.Activate(ControllerAPI)
- if success ~= false then
- cooldowns[abilityName] = tick()
- local slotBtn = hotbar:FindFirstChild(slotName)
- if slotBtn then
- PlayCooldownAnimation(slotBtn, cdTime)
- end
- end
- end
- end
- end)
RAW Gist Data
Copied
