diff --git a/src/community/docsGamesBuildersLua.js b/src/community/docsGamesBuildersLua.js index 50a908d..e54f241 100644 --- a/src/community/docsGamesBuildersLua.js +++ b/src/community/docsGamesBuildersLua.js @@ -1468,45 +1468,94 @@ end)`, // ИГРА 17 — «Ключ от сундука» // ═══════════════════════════════════════════════════════════════ 'key-chest': { - g17_main: `-- === ИГРА «КЛЮЧ ОТ СУНДУКА» (Lua) === -local Players = game:GetService("Players") -Players.PlayerAdded:Connect(function(player) - local stats = Instance.new("Folder", player); stats.Name = "leaderstats" - local key = Instance.new("BoolValue", stats); key.Name = "Ключ" + g17_main: `-- === ИГРА «КЛЮЧ И СУНДУК» — главный скрипт (Lua) === +${SNIPPET_BROADCAST} + +local won = false + +__rbxl_show_text("Найди ключ и открой сундук!", 3) + +local pickupSound = Instance.new("Sound", workspace) +pickupSound.SoundId = "pickup"; pickupSound.Volume = 0.8 +local winSound = Instance.new("Sound", workspace) +winSound.SoundId = "win"; winSound.Volume = 1 +local loseSound = Instance.new("Sound", workspace) +loseSound.SoundId = "lose"; loseSound.Volume = 0.6 + +-- Определяем итем "Ключ" в инвентаре (показывает иконку в hotbar) +__rbxl_inventory_define("key", "Ключ", "#ffd700") + +-- Игрок подобрал ключ +local takeEvent = getEvent("TakeKey") +takeEvent.Event:Connect(function() + __rbxl_inventory_add("key", 1) + __rbxl_show_text("Ты нашёл Ключ!", 2) + pickupSound:Play() end) -for _, p in ipairs(Players:GetPlayers()) do - if not p:FindFirstChild("leaderstats") then - local stats = Instance.new("Folder", p); stats.Name = "leaderstats" - local key = Instance.new("BoolValue", stats); key.Name = "Ключ" + +-- Игрок пытается открыть сундук +local openEvent = getEvent("OpenChest") +openEvent.Event:Connect(function() + if won then return end + if not __rbxl_inventory_has("key") then + __rbxl_show_text("Сундук заперт. Сначала найди ключ.", 2) + loseSound:Play() + return end -end -print("Найди ключ и открой сундук!")`, + won = true + __rbxl_show_text("Победа! Сундук открыт — там сокровище!", 5) + winSound:Play() + local px = __rbxl_player_x() + local py = __rbxl_player_y() + local pz = __rbxl_player_z() + __rbxl_spawn_particles("confetti", px, py + 3, pz, 3, 3) +end)`, g17_key: `-- === Скрипт ключа (Lua) === -local Players = game:GetService("Players") +-- При касании игроком — отправляем событие и удаляем ключ. +local ReplicatedStorage = game:GetService("ReplicatedStorage") local part = script.Parent +local taken = false + part.Touched:Connect(function(hit) - local player = Players:GetPlayerFromCharacter(hit.Parent) - if not player then return end - local stats = player:FindFirstChild("leaderstats") - if stats and stats:FindFirstChild("Ключ") then - stats['Ключ'].Value = true - print("Подобрал ключ!") - part:Destroy() - end + if taken then return end + local h = hit.Parent and hit.Parent:FindFirstChild("Humanoid") + if not h then return end + taken = true + local ev = ReplicatedStorage:FindFirstChild("TakeKey") + if ev then ev:Fire() end + part:Destroy() end)`, g17_chest: `-- === Скрипт сундука (Lua) === -local Players = game:GetService("Players") +-- Подойти и нажать E чтобы открыть. +local UserInputService = game:GetService("UserInputService") +local ReplicatedStorage = game:GetService("ReplicatedStorage") +local RunService = game:GetService("RunService") local part = script.Parent -part.Touched:Connect(function(hit) - local player = Players:GetPlayerFromCharacter(hit.Parent) - if not player then return end - local stats = player:FindFirstChild("leaderstats") - if stats and stats['Ключ'] and stats['Ключ'].Value then - print("Сундук открыт! ПОБЕДА!") - part.Color = Color3.fromRGB(255, 215, 0) - else - print("Нужен ключ!") +local hintVisible = false + +RunService.Heartbeat:Connect(function() + local px = __rbxl_player_x() + local pz = __rbxl_player_z() + local dx = part.Position.X - px + local dz = part.Position.Z - pz + local dist = math.sqrt(dx*dx + dz*dz) + local near = dist <= 4 + if near ~= hintVisible then + hintVisible = near + if near then + __rbxl_hud_set("g17_chest_hint", "[E] Открыть сундук", 50, 75, "#ffe44a", 20) + else + __rbxl_hud_set("g17_chest_hint", nil) + end end +end) + +UserInputService.InputBegan:Connect(function(input, gp) + if gp then return end + if not hintVisible then return end + if input.KeyCode ~= Enum.KeyCode.E then return end + local ev = ReplicatedStorage:FindFirstChild("OpenChest") + if ev then ev:Fire() end end)`, },