Загрузка данных


--[[
    vd script - Премиум GUI меню
    Особенности:
    - Перетаскивание за верхнюю панель
    - Открытие/закрытие по клавише Insert
    - Кнопка тестовой функции On/Off с переключателем
    - ESP функция (подсветка игроков)
    - Кнопка DestroyGUI (уничтожает всё меню и отключает функции)
    - Острые углы, тёмно-серый премиум стиль
    - Без эмодзи
    - Удобно расширять новыми функциями
--]]

local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")

local LocalPlayer = Players.LocalPlayer
local PlayerGui = LocalPlayer:WaitForChild("PlayerGui")

-- Очистка предыдущего экземпляра
local old = PlayerGui:FindFirstChild("vdscript")
if old then old:Destroy() end

-- ==== РЕЕСТР ФУНКЦИЙ ====
local Functions = {}

-- ==== ЦВЕТА ====
local Colors = {
    Background   = Color3.fromRGB(30, 30, 30),
    TopBar       = Color3.fromRGB(22, 22, 22),
    Module       = Color3.fromRGB(40, 40, 40),
    ModuleHover  = Color3.fromRGB(48, 48, 48),
    Text         = Color3.fromRGB(235, 235, 235),
    SubText      = Color3.fromRGB(150, 150, 150),
    Accent       = Color3.fromRGB(200, 200, 200),
    ToggleOff    = Color3.fromRGB(70, 70, 70),
    ToggleOn     = Color3.fromRGB(90, 170, 110),
    Destroy      = Color3.fromRGB(120, 45, 45),
    DestroyHover = Color3.fromRGB(150, 55, 55),
    Stroke       = Color3.fromRGB(55, 55, 55),
}

-- ==== ОСНОВНОЙ GUI ====
local ScreenGui = Instance.new("ScreenGui")
ScreenGui.Name = "vdscript"
ScreenGui.ResetOnSpawn = false
ScreenGui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
ScreenGui.Parent = PlayerGui

local Main = Instance.new("Frame")
Main.Name = "Main"
Main.Size = UDim2.new(0, 380, 0, 320)
Main.Position = UDim2.new(0.5, -190, 0.5, -160)
Main.BackgroundColor3 = Colors.Background
Main.BorderSizePixel = 0
Main.Active = true
Main.Parent = ScreenGui

local MainStroke = Instance.new("UIStroke")
MainStroke.Color = Colors.Stroke
MainStroke.Thickness = 1
MainStroke.Parent = Main

-- Верхняя панель
local TopBar = Instance.new("Frame")
TopBar.Name = "TopBar"
TopBar.Size = UDim2.new(1, 0, 0, 34)
TopBar.BackgroundColor3 = Colors.TopBar
TopBar.BorderSizePixel = 0
TopBar.Parent = Main

local Title = Instance.new("TextLabel")
Title.Size = UDim2.new(1, -12, 1, 0)
Title.Position = UDim2.new(0, 12, 0, 0)
Title.BackgroundTransparency = 1
Title.Text = "vd script"
Title.TextColor3 = Colors.Text
Title.Font = Enum.Font.GothamBold
Title.TextSize = 15
Title.TextXAlignment = Enum.TextXAlignment.Left
Title.Parent = TopBar

local CollapseBtn = Instance.new("TextButton")
CollapseBtn.Size = UDim2.new(0, 30, 1, 0)
CollapseBtn.Position = UDim2.new(1, -30, 0, 0)
CollapseBtn.BackgroundTransparency = 1
CollapseBtn.Text = "—"
CollapseBtn.TextColor3 = Colors.SubText
CollapseBtn.Font = Enum.Font.GothamBold
CollapseBtn.TextSize = 16
CollapseBtn.Parent = TopBar

-- Контейнер
local Container = Instance.new("ScrollingFrame")
Container.Name = "Container"
Container.Size = UDim2.new(1, -16, 1, -50)
Container.Position = UDim2.new(0, 8, 0, 42)
Container.BackgroundTransparency = 1
Container.BorderSizePixel = 0
Container.ScrollBarThickness = 3
Container.ScrollBarImageColor3 = Colors.Stroke
Container.CanvasSize = UDim2.new(0, 0, 0, 0)
Container.AutomaticCanvasSize = Enum.AutomaticSize.Y
Container.Parent = Main

local Layout = Instance.new("UIListLayout")
Layout.Padding = UDim.new(0, 6)
Layout.SortOrder = Enum.SortOrder.LayoutOrder
Layout.Parent = Container

-- ==== ПЕРЕТАСКИВАНИЕ ====
local dragging, dragStart, startPos
TopBar.InputBegan:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1
    or input.UserInputType == Enum.UserInputType.Touch then
        dragging = true
        dragStart = input.Position
        startPos = Main.Position
        input.Changed:Connect(function()
            if input.UserInputState == Enum.UserInputState.End then
                dragging = false
            end
        end)
    end
end)

UserInputService.InputChanged:Connect(function(input)
    if dragging and (input.UserInputType == Enum.UserInputType.MouseMovement
    or input.UserInputType == Enum.UserInputType.Touch) then
        local delta = input.Position - dragStart
        Main.Position = UDim2.new(
            startPos.X.Scale, startPos.X.Offset + delta.X,
            startPos.Y.Scale, startPos.Y.Offset + delta.Y
        )
    end
end)

-- ==== СВОРАЧИВАНИЕ ====
local collapsed = false
CollapseBtn.MouseButton1Click:Connect(function()
    collapsed = not collapsed
    if collapsed then
        Main.Size = UDim2.new(0, 380, 0, 34)
        Container.Visible = false
        CollapseBtn.Text = "+"
    else
        Main.Size = UDim2.new(0, 380, 0, 320)
        Container.Visible = true
        CollapseBtn.Text = "—"
    end
end)

-- ==== ПЕРЕКЛЮЧАТЕЛЬ ====
local function BuildToggle(parent, funcData)
    local Module = Instance.new("Frame")
    Module.Name = funcData.Name
    Module.Size = UDim2.new(1, -4, 0, 56)
    Module.BackgroundColor3 = Colors.Module
    Module.BorderSizePixel = 0
    Module.Parent = parent

    local Stroke = Instance.new("UIStroke")
    Stroke.Color = Colors.Stroke
    Stroke.Thickness = 1
    Stroke.Parent = Module

    local Info = Instance.new("Frame")
    Info.Size = UDim2.new(1, -70, 1, 0)
    Info.BackgroundTransparency = 1
    Info.Parent = Module

    local NameLabel = Instance.new("TextLabel")
    NameLabel.Size = UDim2.new(1, -12, 0, 22)
    NameLabel.Position = UDim2.new(0, 12, 0, 6)
    NameLabel.BackgroundTransparency = 1
    NameLabel.Text = funcData.Name
    NameLabel.TextColor3 = Colors.Text
    NameLabel.Font = Enum.Font.GothamSemibold
    NameLabel.TextSize = 14
    NameLabel.TextXAlignment = Enum.TextXAlignment.Left
    NameLabel.Parent = Info

    local DescLabel = Instance.new("TextLabel")
    DescLabel.Size = UDim2.new(1, -12, 0, 18)
    DescLabel.Position = UDim2.new(0, 12, 0, 28)
    DescLabel.BackgroundTransparency = 1
    DescLabel.Text = funcData.Description
    DescLabel.TextColor3 = Colors.SubText
    DescLabel.Font = Enum.Font.Gotham
    DescLabel.TextSize = 11
    DescLabel.TextXAlignment = Enum.TextXAlignment.Left
    DescLabel.Parent = Info

    local ToggleBtn = Instance.new("TextButton")
    ToggleBtn.Size = UDim2.new(0, 46, 0, 22)
    ToggleBtn.Position = UDim2.new(1, -56, 0.5, -11)
    ToggleBtn.BackgroundColor3 = Colors.ToggleOff
    ToggleBtn.BorderSizePixel = 0
    ToggleBtn.Text = ""
    ToggleBtn.AutoButtonColor = false
    ToggleBtn.Parent = Module

    local ToggleStroke = Instance.new("UIStroke")
    ToggleStroke.Color = Colors.Stroke
    ToggleStroke.Thickness = 1
    ToggleStroke.Parent = ToggleBtn

    local Knob = Instance.new("Frame")
    Knob.Size = UDim2.new(0, 16, 0, 16)
    Knob.Position = UDim2.new(0, 3, 0.5, -8)
    Knob.BackgroundColor3 = Colors.Accent
    Knob.BorderSizePixel = 0
    Knob.Parent = ToggleBtn

    funcData.UI.Module = Module
    funcData.UI.Toggle = ToggleBtn
    funcData.UI.Knob = Knob

    local function UpdateVisual()
        if funcData.Enabled then
            TweenService:Create(ToggleBtn, TweenInfo.new(0.15), {BackgroundColor3 = Colors.ToggleOn}):Play()
            Knob.Position = UDim2.new(1, -19, 0.5, -8)
        else
            TweenService:Create(ToggleBtn, TweenInfo.new(0.15), {BackgroundColor3 = Colors.ToggleOff}):Play()
            Knob.Position = UDim2.new(0, 3, 0.5, -8)
        end
    end

    ToggleBtn.MouseButton1Click:Connect(function()
        funcData.Enabled = not funcData.Enabled
        UpdateVisual()
        if funcData.Callback then
            pcall(funcData.Callback, funcData.Enabled)
        end
    end)

    Module.MouseEnter:Connect(function()
        Module.BackgroundColor3 = Colors.ModuleHover
    end)
    Module.MouseLeave:Connect(function()
        Module.BackgroundColor3 = Colors.Module
    end)

    UpdateVisual()
    return Module
end

-- ==== ПУБЛИЧНОЕ API ====
vdscript = {}
vdscript.Functions = Functions

function vdscript:AddFunction(name, description, callback)
    local data = {
        Name = name,
        Description = description,
        Enabled = false,
        Callback = callback,
        UI = {},
    }
    table.insert(Functions, data)
    if vdscript._ready then
        BuildToggle(Container, data)
    end
    return data
end

-- ==== КНОПКА DESTROY GUI ====
local DestroyBtn = Instance.new("TextButton")
DestroyBtn.Name = "DestroyGUI"
DestroyBtn.Size = UDim2.new(1, -4, 0, 36)
DestroyBtn.BackgroundColor3 = Colors.Destroy
DestroyBtn.BorderSizePixel = 0
DestroyBtn.Text = "DestroyGUI"
DestroyBtn.TextColor3 = Colors.Text
DestroyBtn.Font = Enum.Font.GothamBold
DestroyBtn.TextSize = 13
DestroyBtn.AutoButtonColor = false
DestroyBtn.Parent = Container

local DestroyStroke = Instance.new("UIStroke")
DestroyStroke.Color = Colors.Stroke
DestroyStroke.Thickness = 1
DestroyStroke.Parent = DestroyBtn

DestroyBtn.MouseEnter:Connect(function()
    DestroyBtn.BackgroundColor3 = Colors.DestroyHover
end)
DestroyBtn.MouseLeave:Connect(function()
    DestroyBtn.BackgroundColor3 = Colors.Destroy
end)

DestroyBtn.MouseButton1Click:Connect(function()
    for _, f in ipairs(Functions) do
        if f.Enabled and f.Callback then
            pcall(f.Callback, false)
        end
        f.Enabled = false
    end
    ScreenGui:Destroy()
end)

-- ==== ФУНКЦИЯ ESP ====
local ESPFolder = nil
local ESPConnections = {}

local function CreateESP(player)
    if player == LocalPlayer then return end
    local character = player.Character
    if not character then return end

    local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
    local humanoid = character:FindFirstChildOfClass("Humanoid")
    if not humanoidRootPart or not humanoid then return end

    -- Highlight
    local highlight = Instance.new("Highlight")
    highlight.Name = "vdscript_ESP"
    highlight.FillColor = Color3.fromRGB(90, 170, 255)
    highlight.OutlineColor = Color3.fromRGB(255, 255, 255)
    highlight.FillTransparency = 0.5
    highlight.OutlineTransparency = 0
    highlight.DepthMode = Enum.HighlightDepthMode.AlwaysOnTop
    highlight.Adornee = character
    highlight.Parent = character

    -- Nametag
    local billboard = Instance.new("BillboardGui")
    billboard.Name = "vdscript_ESP_Tag"
    billboard.Size = UDim2.new(0, 200, 0, 50)
    billboard.StudsOffset = Vector3.new(0, 3, 0)
    billboard.AlwaysOnTop = true
    billboard.Adornee = humanoidRootPart
    billboard.Parent = character

    local nameLabel = Instance.new("TextLabel")
    nameLabel.Size = UDim2.new(1, 0, 0.5, 0)
    nameLabel.BackgroundTransparency = 1
    nameLabel.Text = player.Name
    nameLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
    nameLabel.TextStrokeTransparency = 0
    nameLabel.TextStrokeColor3 = Color3.fromRGB(0, 0, 0)
    nameLabel.Font = Enum.Font.GothamBold
    nameLabel.TextSize = 14
    nameLabel.Parent = billboard

    local distLabel = Instance.new("TextLabel")
    distLabel.Size = UDim2.new(1, 0, 0.5, 0)
    distLabel.Position = UDim2.new(0, 0, 0.5, 0)
    distLabel.BackgroundTransparency = 1
    distLabel.Text = ""
    distLabel.TextColor3 = Color3.fromRGB(200, 200, 200)
    distLabel.TextStrokeTransparency = 0
    distLabel.TextStrokeColor3 = Color3.fromRGB(0, 0, 0)
    distLabel.Font = Enum.Font.Gotham
    distLabel.TextSize = 12
    distLabel.Parent = billboard

    -- Обновление дистанции
    local conn = RunService.RenderStepped:Connect(function()
        if not character.Parent or not humanoidRootPart.Parent then
            return
        end
        local myChar = LocalPlayer.Character
        if myChar and myChar:FindFirstChild("HumanoidRootPart") then
            local dist = (myChar.HumanoidRootPart.Position - humanoidRootPart.Position).Magnitude
            distLabel.Text = string.format("[%d studs]", math.floor(dist))
        end
    end)
    table.insert(ESPConnections, conn)
end

local function RemoveESP(player)
    local character = player.Character
    if not character then return end
    for _, obj in ipairs(character:GetChildren()) do
        if obj.Name == "vdscript_ESP" or obj.Name == "vdscript_ESP_Tag" then
            obj:Destroy()
        end
    end
end

local function ClearAllESP()
    for _, player in ipairs(Players:GetPlayers()) do
        RemoveESP(player)
    end
    for _, conn in ipairs(ESPConnections) do
        pcall(function() conn:Disconnect() end)
    end
    ESPConnections = {}
end

local playerAddedConn, playerRemovingConn, charAddedConn

local function EnableESP(state)
    if state then
        -- Добавляем всем текущим игрокам
        for _, player in ipairs(Players:GetPlayers()) do
            CreateESP(player)
            -- Отслеживаем респавн
            player.CharacterAdded:Connect(function()
                task.wait(0.5)
                if vdscript_ESPEnabled then
                    CreateESP(player)
                end
            end)
        end

        playerAddedConn = Players.PlayerAdded:Connect(function(player)
            player.CharacterAdded:Connect(function()
                task.wait(0.5)
                if vdscript_ESPEnabled then
                    CreateESP(player)
                end
            end)
        end)

        playerRemovingConn = Players.PlayerRemoving:Connect(function(player)
            RemoveESP(player)
        end)

        -- Отслеживание локального респавна
        LocalPlayer.CharacterAdded:Connect(function()
            task.wait(1)
            if vdscript_ESPEnabled then
                for _, p in ipairs(Players:GetPlayers()) do
                    CreateESP(p)
                end
            end
        end)
    else
        ClearAllESP()
        if playerAddedConn then playerAddedConn:Disconnect() end
        if playerRemovingConn then playerRemovingConn:Disconnect() end
    end
end

-- Флаг для отслеживания состояния
vdscript_ESPEnabled = false

vdscript:AddFunction(
    "ESP",
    "Подсветка игроков, имя и дистанция",
    function(state)
        vdscript_ESPEnabled = state
        EnableESP(state)
    end
)

-- ==== ТЕСТОВАЯ ФУНКЦИЯ ====
vdscript:AddFunction(
    "Test Function",
    "Тестовая функция для проверки переключателя",
    function(state)
        if state then
            print("[vd script] Test Function: ON")
        else
            print("[vd script] Test Function: OFF")
        end
    end
)

-- ==== ПЕРЕКЛЮЧЕНИЕ ПО INSERT ====
local isOpen = true

local function SetOpen(state)
    isOpen = state
    Main.Visible = state
end

UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if gameProcessed then return end
    if input.KeyCode == Enum.KeyCode.Insert then
        SetOpen(not isOpen)
    end
end)

vdscript._ready = true

-- Построение стартовых функций
for _, data in ipairs(Functions) do
    BuildToggle(Container, data)
end