feat: 50 игр на Lua + импорт Roblox для всех + поддержка Lua в плеере #39
@ -275,36 +275,106 @@ end)`;
|
||||
// ИГРА 4 — «Кнопка и дверь»
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
'button-door': {
|
||||
g4_main: `-- === ИГРА «КНОПКА И ДВЕРЬ» — главный скрипт (Lua) ===
|
||||
g4_main: `-- === ИГРА «КНОПКА-ОТКРЫВАШКА» — главный скрипт (Lua) ===
|
||||
${SNIPPET_BROADCAST}
|
||||
print("Найди кнопку и открой дверь!")
|
||||
-- Глобальный канал для оповещения двери
|
||||
getEvent("DoorOpen")`,
|
||||
|
||||
__rbxl_show_text("Подойди к красной кнопке и нажми E", 4)
|
||||
|
||||
local winSound = Instance.new("Sound", workspace)
|
||||
winSound.SoundId = "win"; winSound.Volume = 1
|
||||
|
||||
local winEvent = getEvent("WinReached")
|
||||
winEvent.Event:Connect(function()
|
||||
__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)`,
|
||||
g4_button: `-- === Скрипт кнопки (Lua) ===
|
||||
-- Висит на красной кнопке. Реагирует на E когда игрок рядом.
|
||||
local UserInputService = game:GetService("UserInputService")
|
||||
local Players = game:GetService("Players")
|
||||
local RunService = game:GetService("RunService")
|
||||
local TweenService = game:GetService("TweenService")
|
||||
|
||||
local part = script.Parent
|
||||
local player = Players.LocalPlayer
|
||||
local opened = false
|
||||
local inRange = false
|
||||
local hintGui = nil
|
||||
|
||||
-- Подсказка над кнопкой при подходе
|
||||
local function showHint()
|
||||
if hintGui then return end
|
||||
hintGui = Instance.new("BillboardGui", part)
|
||||
hintGui.Size = UDim2.new(4, 0, 1, 0)
|
||||
hintGui.StudsOffset = Vector3.new(0, 2, 0)
|
||||
hintGui.AlwaysOnTop = true
|
||||
local label = Instance.new("TextLabel", hintGui)
|
||||
label.Size = UDim2.new(1, 0, 1, 0)
|
||||
label.BackgroundTransparency = 1
|
||||
label.TextColor3 = Color3.fromRGB(255, 255, 255)
|
||||
label.TextStrokeTransparency = 0
|
||||
label.TextScaled = true
|
||||
label.Text = "[E] Открыть дверь"
|
||||
end
|
||||
local function hideHint()
|
||||
if hintGui then hintGui:Destroy(); hintGui = nil end
|
||||
end
|
||||
|
||||
-- Каждый кадр проверяем расстояние до игрока
|
||||
RunService.Heartbeat:Connect(function()
|
||||
if opened then return end
|
||||
local px = __rbxl_player_x()
|
||||
local py = __rbxl_player_y()
|
||||
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)
|
||||
if dist <= 4 and not inRange then
|
||||
inRange = true
|
||||
showHint()
|
||||
elseif dist > 4 and inRange then
|
||||
inRange = false
|
||||
hideHint()
|
||||
end
|
||||
end)
|
||||
|
||||
local clickSound = Instance.new("Sound", part)
|
||||
clickSound.SoundId = "click"; clickSound.Volume = 0.8
|
||||
|
||||
UserInputService.InputBegan:Connect(function(input, gp)
|
||||
if gp then return end
|
||||
if opened or not inRange then return end
|
||||
if input.KeyCode ~= Enum.KeyCode.E then return end
|
||||
opened = true
|
||||
hideHint()
|
||||
clickSound:Play()
|
||||
__rbxl_show_text("Дверь открывается!", 2)
|
||||
part.Color = Color3.fromRGB(100, 255, 100) -- зелёная
|
||||
|
||||
-- Находим дверь по имени и поднимаем её
|
||||
local door = workspace:FindFirstChild("Дверь")
|
||||
if door then
|
||||
local goal = { Position = door.Position + Vector3.new(0, 6, 0) }
|
||||
TweenService:Create(door, TweenInfo.new(1.2), goal):Play()
|
||||
door.CanCollide = false
|
||||
end
|
||||
end)`,
|
||||
g4_finish: `-- === Скрипт финиша (Lua) ===
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local part = script.Parent
|
||||
local fired = false
|
||||
|
||||
part.Touched:Connect(function(hit)
|
||||
if fired then return end
|
||||
local h = hit.Parent and hit.Parent:FindFirstChild("Humanoid")
|
||||
if not h then return end
|
||||
local ev = ReplicatedStorage:FindFirstChild("DoorOpen")
|
||||
fired = true
|
||||
local ev = ReplicatedStorage:FindFirstChild("WinReached")
|
||||
if ev then ev:Fire() end
|
||||
print("Кнопка нажата!")
|
||||
part.Color = Color3.fromRGB(100, 255, 100) -- зелёная
|
||||
end)`,
|
||||
g4_door: `-- === Скрипт двери (Lua) ===
|
||||
local TweenService = game:GetService("TweenService")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local door = script.Parent
|
||||
local startPos = door.Position
|
||||
|
||||
local ev = ReplicatedStorage:WaitForChild("DoorOpen")
|
||||
ev.Event:Connect(function()
|
||||
-- Поднимаем дверь вверх
|
||||
local goal = { Position = startPos + Vector3.new(0, 5, 0) }
|
||||
TweenService:Create(door, TweenInfo.new(1), goal):Play()
|
||||
door.CanCollide = false
|
||||
print("Дверь открыта!")
|
||||
end)`,
|
||||
},
|
||||
|
||||
|
||||
@ -2083,10 +2083,29 @@ export function registerRobloxShim(lua, opts) {
|
||||
try { playerMouse.Button1Up.Fire(); } catch (_) {}
|
||||
}
|
||||
if (p.type === 'keyDown') {
|
||||
try { playerMouse.KeyDown.Fire(String(p.key || '').toLowerCase()); } catch (_) {}
|
||||
const k = String(p.key || '').toLowerCase();
|
||||
try { playerMouse.KeyDown.Fire(k); } catch (_) {}
|
||||
// Также фейерим UserInputService.InputBegan с InputObject.
|
||||
// KeyCode должна быть та же ссылка что и Enum.KeyCode.E,
|
||||
// чтобы скрипт мог сравнивать input.KeyCode == Enum.KeyCode.E.
|
||||
try {
|
||||
const keyEnum = global.get('Enum')?.KeyCode || {};
|
||||
const kc = keyEnum[k.toUpperCase()]
|
||||
|| { Name: k.toUpperCase(), Value: k.toUpperCase() };
|
||||
const inputObj = { UserInputType: 'Keyboard', KeyCode: kc };
|
||||
uis.InputBegan.Fire(inputObj, false);
|
||||
} catch (_) {}
|
||||
}
|
||||
if (p.type === 'keyUp') {
|
||||
try { playerMouse.KeyUp.Fire(String(p.key || '').toLowerCase()); } catch (_) {}
|
||||
const k = String(p.key || '').toLowerCase();
|
||||
try { playerMouse.KeyUp.Fire(k); } catch (_) {}
|
||||
try {
|
||||
const keyEnum = global.get('Enum')?.KeyCode || {};
|
||||
const kc = keyEnum[k.toUpperCase()]
|
||||
|| { Name: k.toUpperCase(), Value: k.toUpperCase() };
|
||||
const inputObj = { UserInputType: 'Keyboard', KeyCode: kc };
|
||||
uis.InputEnded.Fire(inputObj, false);
|
||||
} catch (_) {}
|
||||
}
|
||||
},
|
||||
// Tool registry (для GameRuntime: какой Tool сделать script.Parent)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user