Guest

Roblox Game Script for Ability Activation and Mana Check

Nov 22nd, 2025
136
0
Never
Not a member of gistpad yet? Sign Up, it unlocks many cool features!
Lua 33.37 KB | Source Code | 0 0
  1. local Players = game:GetService("Players")
  2. local UserInputService = game:GetService("UserInputService")
  3. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  4. local StarterGui = game:GetService("StarterGui")
  5. local TweenService = game:GetService("TweenService")
  6.  
  7. print("--- ЗАПУСК КОНТРОЛЛЕРА (v14: Mana System Integration) ---")
  8.  
  9. local player = Players.LocalPlayer
  10. local gui = script.Parent
  11. local hotbar = gui:WaitForChild("Hotbar")
  12. local menuFrame = gui:WaitForChild("AbilityMenu")
  13. local openMenuBtn = gui:WaitForChild("OpenMenuBtn")
  14. local AbilitiesFolder = ReplicatedStorage:WaitForChild("Abilities")
  15.  
  16. local resetButton = menuFrame:FindFirstChild("ResetButton")
  17.  
  18. -- ==============================================================
  19. -- 1. ФУНКЦИЯ ВИЗУАЛЬНОГО КУЛДАУНА
  20. -- ==============================================================
  21. local function PlayCooldownAnimation(slotBtn, duration)
  22. local cdFrame = slotBtn:FindFirstChild("CooldownOverlay")
  23. if not cdFrame then
  24. cdFrame = Instance.new("Frame")
  25. cdFrame.Name = "CooldownOverlay"
  26. cdFrame.Size = UDim2.new(1, 0, 1, 0)
  27. cdFrame.Position = UDim2.new(0,0,0,0)
  28. cdFrame.BackgroundColor3 = Color3.new(0, 0, 0)
  29. cdFrame.BackgroundTransparency = 0.3
  30. cdFrame.ZIndex = 10
  31. cdFrame.Parent = slotBtn
  32.  
  33. local corner = Instance.new("UICorner")
  34. corner.CornerRadius = UDim.new(0, 8)
  35. corner.Parent = cdFrame
  36.  
  37. local text = Instance.new("TextLabel")
  38. text.Name = "TimerText"
  39. text.Size = UDim2.new(0.5, 0, 0.5, 0)
  40. text.Position = UDim2.new(0.25, 0, 0.25, 0)
  41. text.BackgroundTransparency = 1
  42. text.TextColor3 = Color3.new(1, 1, 1)
  43. text.TextScaled = true
  44. text.Font = Enum.Font.GothamBold
  45. text.ZIndex = 11
  46. text.Parent = cdFrame
  47. end
  48.  
  49. local textLabel = cdFrame.TimerText
  50. cdFrame.Visible = true
  51.  
  52. task.spawn(function()
  53. local startTime = tick()
  54. while tick() - startTime < duration do
  55. local timeLeft = duration - (tick() - startTime)
  56. if timeLeft < 1 then
  57. textLabel.Text = string.format("%.1f", timeLeft)
  58. else
  59. textLabel.Text = math.ceil(timeLeft)
  60. end
  61. task.wait(0.1)
  62. end
  63. cdFrame.Visible = false
  64. end)
  65. end
  66.  
  67. -- ==============================================================
  68. -- 2. ЛОГИКА СБРОСА
  69. -- ==============================================================
  70. local currentLoadout = {}
  71. local cooldowns = {}
  72.  
  73. if resetButton then
  74. resetButton.MouseButton1Click:Connect(function()
  75. currentLoadout = {}
  76. for _, child in pairs(hotbar:GetChildren()) do
  77. if child:IsA("ImageButton") or child:IsA("TextButton") then
  78. child.Image = ""
  79. local overlay = child:FindFirstChild("CooldownOverlay")
  80. if overlay then overlay.Visible = false end
  81. end
  82. end
  83. end)
  84. end
  85.  
  86. -- ==============================================================
  87. -- 3. ЗАГРУЗКА И НАСТРОЙКА СЛОТОВ
  88. -- ==============================================================
  89. openMenuBtn.MouseButton1Click:Connect(function()
  90. menuFrame.Visible = not menuFrame.Visible
  91. end)
  92.  
  93. local AbilityModules = {}
  94. local selectedAbilityName = nil
  95.  
  96. for _, module in pairs(AbilitiesFolder:GetChildren()) do
  97. if module:IsA("ModuleScript") then
  98. local success, result = pcall(function() return require(module) end)
  99. if success then
  100. AbilityModules[module.Name] = result
  101. local btnName = module.Name .. "Icon"
  102. local btn = menuFrame:FindFirstChild(btnName)
  103. if btn then
  104. btn.MouseButton1Click:Connect(function()
  105. selectedAbilityName = module.Name
  106. print("🔵 ВЫБРАНО: " .. module.Name)
  107. end)
  108. end
  109. end
  110. end
  111. end
  112.  
  113. for _, child in pairs(hotbar:GetChildren()) do
  114. if child:IsA("ImageButton") or child:IsA("TextButton") then
  115. child.MouseButton1Click:Connect(function()
  116. if selectedAbilityName then
  117. local module = AbilityModules[selectedAbilityName]
  118. if not module or not module.Info then return end
  119.  
  120. for slot, ability in pairs(currentLoadout) do
  121. if ability == selectedAbilityName then
  122. currentLoadout[slot] = nil
  123. local oldBtn = hotbar:FindFirstChild(slot)
  124. if oldBtn then oldBtn.Image = "" end
  125. end
  126. end
  127.  
  128. currentLoadout[child.Name] = selectedAbilityName
  129. child.Image = module.Info.Icon
  130. print("🎉 УСПЕХ! " .. selectedAbilityName .. " -> " .. child.Name)
  131.  
  132. selectedAbilityName = nil
  133. end
  134. end)
  135. end
  136. end
  137.  
  138. -- ==============================================================
  139. -- 4. АКТИВАЦИЯ С ПРОВЕРКОЙ МАНЫ
  140. -- ==============================================================
  141. local ControllerAPI = {}
  142. function ControllerAPI.ShowNotification(text)
  143. StarterGui:SetCore("SendNotification", {Title = "Ability"; Text = text; Duration = 2;})
  144. end
  145.  
  146. local keyMap = {
  147. [Enum.KeyCode.E] = "Slot1", [Enum.KeyCode.R] = "Slot2",
  148. [Enum.KeyCode.X] = "Slot3", [Enum.KeyCode.F] = "Slot4",
  149. [Enum.KeyCode.V] = "Slot5", [Enum.KeyCode.C] = "Slot6"
  150. }
  151.  
  152. UserInputService.InputBegan:Connect(function(input, gp)
  153. if gp then return end
  154.  
  155. local slotName = keyMap[input.KeyCode]
  156.  
  157. if slotName then
  158. local abilityName = currentLoadout[slotName]
  159.  
  160. if abilityName and AbilityModules[abilityName] then
  161. local module = AbilityModules[abilityName]
  162.  
  163. -- [НОВОЕ] ПРОВЕРКА МАНЫ ПЕРЕД НАЖАТИЕМ
  164. local char = player.Character
  165. if char then
  166. local currentMana = char:GetAttribute("Mana") or 0
  167. local manaCost = module.Info.ManaCost or 0
  168.  
  169. if currentMana < manaCost then
  170. ControllerAPI.ShowNotification("Мана: " .. math.floor(currentMana) .. "/" .. manaCost)
  171. return -- ОТМЕНА, ЕСЛИ НЕТ МАНЫ
  172. end
  173. end
  174.  
  175. -- Проверка Кулдауна
  176. local lastTime = cooldowns[abilityName] or 0
  177. local cdTime = module.Info.Cooldown or 0
  178. if tick() - lastTime < cdTime then return end
  179.  
  180. -- Активация
  181. local success = module.Activate(ControllerAPI)
  182.  
  183. if success ~= false then
  184. cooldowns[abilityName] = tick()
  185. local slotBtn = hotbar:FindFirstChild(slotName)
  186. if slotBtn then
  187. PlayCooldownAnimation(slotBtn, cdTime)
  188. end
  189. end
  190. end
  191. end
  192. end)
RAW Gist Data Copied