Guest

Roblox Game Controller Script

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