docs(41) + feat(g42): «RPG-деревня»
g41 docs: CodeBoth 4 скрипта (main+coin_10+cp+finish). g42 паритет: - 2 NPC (Староста character-a, Кузнец character-b) - stage 0→1→2→3 цепочка - BindableEvents ElderTalk/TakeAmulet/SmithTalk - g42_elder/smith: Heartbeat distance(4) + '[E] Поговорить' InputBegan E → Fire - g42_amulet: Touched → TakeAmulet:Fire + Destroy - stage 1 elder: 'Найди амулет' - stage 1 amulet: __rbxl_inventory_define/add 'amulet' - stage 2 smith: inventory_remove + 'Победа!' + confetti - Прочие говорят соответствующую реплику
This commit is contained in:
parent
e75121cb3d
commit
4085fce0d3
@ -3799,7 +3799,151 @@ end)`;
|
|||||||
})(),
|
})(),
|
||||||
|
|
||||||
// ═══════════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════════
|
||||||
// ИГРЫ 42-50: явных Lua-версий пока нет.
|
// ИГРА 42 — «RPG-деревня»
|
||||||
|
// ═══════════════════════════════════════════════════════════════
|
||||||
|
'rpg-village': {
|
||||||
|
g42_main: `-- === ИГРА «RPG-ДЕРЕВНЯ» — главный скрипт (Lua) ===
|
||||||
|
${SNIPPET_BROADCAST}
|
||||||
|
|
||||||
|
local stage = 0 -- 0=начало, 1=ищем амулет, 2=несём кузнецу, 3=готово
|
||||||
|
local hasAmulet = false
|
||||||
|
|
||||||
|
__rbxl_show_text("Деревня. Поговори со старостой (E)", 4)
|
||||||
|
|
||||||
|
local elderRef = __rbxl_spawn_npc("character-a", 1.6, 1, 2, "Староста", 100, 0)
|
||||||
|
local smithRef = __rbxl_spawn_npc("character-b", 12.6, 1, 7, "Кузнец", 100, 0)
|
||||||
|
|
||||||
|
local pickupSound = Instance.new("Sound", workspace)
|
||||||
|
pickupSound.SoundId = "pickup"; pickupSound.Volume = 0.7
|
||||||
|
local winSound = Instance.new("Sound", workspace)
|
||||||
|
winSound.SoundId = "win"; winSound.Volume = 1
|
||||||
|
|
||||||
|
-- Староста
|
||||||
|
local elderEvent = getEvent("ElderTalk")
|
||||||
|
elderEvent.Event:Connect(function()
|
||||||
|
if stage == 0 then
|
||||||
|
stage = 1
|
||||||
|
__rbxl_npc_say(elderRef, "Найди потерянный амулет за домом!", 4)
|
||||||
|
__rbxl_show_text("Квест: найди фиолетовый амулет", 3)
|
||||||
|
elseif stage == 1 then
|
||||||
|
__rbxl_npc_say(elderRef, "Амулет всё ещё не у тебя...", 3)
|
||||||
|
else
|
||||||
|
__rbxl_npc_say(elderRef, "Спасибо за помощь деревне!", 3)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Амулет
|
||||||
|
local amuletEvent = getEvent("TakeAmulet")
|
||||||
|
amuletEvent.Event:Connect(function()
|
||||||
|
if stage ~= 1 then return end
|
||||||
|
stage = 2
|
||||||
|
hasAmulet = true
|
||||||
|
__rbxl_inventory_define("amulet", "Амулет", "#a855f7")
|
||||||
|
__rbxl_inventory_add("amulet", 1)
|
||||||
|
pickupSound:Play()
|
||||||
|
__rbxl_show_text("Амулет найден! Отнеси кузнецу.", 3)
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Кузнец
|
||||||
|
local smithEvent = getEvent("SmithTalk")
|
||||||
|
smithEvent.Event:Connect(function()
|
||||||
|
if stage == 2 and hasAmulet then
|
||||||
|
stage = 3
|
||||||
|
hasAmulet = false
|
||||||
|
__rbxl_inventory_remove("amulet", 1)
|
||||||
|
__rbxl_npc_say(smithRef, "Отличный амулет! Вот награда, герой!", 4)
|
||||||
|
__rbxl_show_text("Победа! Квест RPG-деревни выполнен!", 6)
|
||||||
|
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)
|
||||||
|
elseif stage == 3 then
|
||||||
|
__rbxl_npc_say(smithRef, "Доброго пути!", 3)
|
||||||
|
else
|
||||||
|
__rbxl_npc_say(smithRef, "Принеси мне амулет — поговори со старостой.", 4)
|
||||||
|
end
|
||||||
|
end)`,
|
||||||
|
g42_elder: `-- === Скрипт старосты (Lua) ===
|
||||||
|
local UserInputService = game:GetService("UserInputService")
|
||||||
|
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||||
|
local RunService = game:GetService("RunService")
|
||||||
|
local part = script.Parent
|
||||||
|
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("g42_elder_hint", "[E] Поговорить со старостой", 50, 75, "#ffe44a", 20)
|
||||||
|
else
|
||||||
|
__rbxl_hud_set("g42_elder_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("ElderTalk")
|
||||||
|
if ev then ev:Fire() end
|
||||||
|
end)`,
|
||||||
|
g42_smith: `-- === Скрипт кузнеца (Lua) ===
|
||||||
|
local UserInputService = game:GetService("UserInputService")
|
||||||
|
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||||
|
local RunService = game:GetService("RunService")
|
||||||
|
local part = script.Parent
|
||||||
|
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("g42_smith_hint", "[E] Поговорить с кузнецом", 50, 75, "#ffe44a", 20)
|
||||||
|
else
|
||||||
|
__rbxl_hud_set("g42_smith_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("SmithTalk")
|
||||||
|
if ev then ev:Fire() end
|
||||||
|
end)`,
|
||||||
|
g42_amulet: `-- === Скрипт амулета (Lua) ===
|
||||||
|
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||||
|
local part = script.Parent
|
||||||
|
local taken = false
|
||||||
|
|
||||||
|
part.Touched:Connect(function(hit)
|
||||||
|
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("TakeAmulet")
|
||||||
|
if ev then ev:Fire() end
|
||||||
|
part:Destroy()
|
||||||
|
end)`,
|
||||||
|
},
|
||||||
|
|
||||||
|
// ═══════════════════════════════════════════════════════════════
|
||||||
|
// ИГРЫ 43-50: явных Lua-версий пока нет.
|
||||||
// buildGameProject в docsGamesBuilders.js использует generateFallbackLua
|
// buildGameProject в docsGamesBuilders.js использует generateFallbackLua
|
||||||
// (главный скрипт → показ подсказки + слушает FinishReached →
|
// (главный скрипт → показ подсказки + слушает FinishReached →
|
||||||
// победа+конфетти; скрипт на финиш-примитиве → шлёт FinishReached;
|
// победа+конфетти; скрипт на финиш-примитиве → шлёт FinishReached;
|
||||||
|
|||||||
@ -5837,7 +5837,7 @@ game.after(2, startWave); // первая волна через 2 секунд
|
|||||||
|
|
||||||
<h3 className="lessonH">Шаг 2. Главный скрипт</h3>
|
<h3 className="lessonH">Шаг 2. Главный скрипт</h3>
|
||||||
<ScriptKind kind="global" />
|
<ScriptKind kind="global" />
|
||||||
<Code>{`// === ИГРА «ПЛАТФОРМЕР-ПРИКЛЮЧЕНИЕ» — главный скрипт ===
|
<CodeBoth game="adventure-platformer" script="g41_main">{`// === ИГРА «ПЛАТФОРМЕР-ПРИКЛЮЧЕНИЕ» — главный скрипт ===
|
||||||
|
|
||||||
let coins = 0;
|
let coins = 0;
|
||||||
let won = false;
|
let won = false;
|
||||||
@ -5879,7 +5879,7 @@ game.onMessage('treasure', () => {
|
|||||||
const p = game.player.position;
|
const p = game.player.position;
|
||||||
game.scene.spawnParticles('confetti',
|
game.scene.spawnParticles('confetti',
|
||||||
{ x: p.x, y: p.y + 3, z: p.z }, { duration: 3, count: 3 });
|
{ x: p.x, y: p.y + 3, z: p.z }, { duration: 3, count: 3 });
|
||||||
});`}</Code>
|
});`}</CodeBoth>
|
||||||
<p>Разберём:</p>
|
<p>Разберём:</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li><code>game.onMessage('coin', ...)</code> — пришла
|
<li><code>game.onMessage('coin', ...)</code> — пришла
|
||||||
@ -5899,21 +5899,21 @@ game.onMessage('treasure', () => {
|
|||||||
|
|
||||||
<h3 className="lessonH">Шаг 3. Скрипты монетки, чекпоинта и сокровища</h3>
|
<h3 className="lessonH">Шаг 3. Скрипты монетки, чекпоинта и сокровища</h3>
|
||||||
<ScriptKind kind="object" on="каждую монетку" />
|
<ScriptKind kind="object" on="каждую монетку" />
|
||||||
<Code>{`// === Скрипт монетки ===
|
<CodeBoth game="adventure-platformer" script="g41_coin_10">{`// === Скрипт монетки ===
|
||||||
game.self.onTouch(() => {
|
game.self.onTouch(() => {
|
||||||
game.broadcast('coin');
|
game.broadcast('coin');
|
||||||
game.self.delete();
|
game.self.delete();
|
||||||
});`}</Code>
|
});`}</CodeBoth>
|
||||||
<ScriptKind kind="object" on="жёлтый чекпоинт" />
|
<ScriptKind kind="object" on="жёлтый чекпоинт" />
|
||||||
<Code>{`// === Скрипт чекпоинта ===
|
<CodeBoth game="adventure-platformer" script="g41_cp">{`// === Скрипт чекпоинта ===
|
||||||
game.self.onTouch(() => {
|
game.self.onTouch(() => {
|
||||||
game.broadcast('checkpoint');
|
game.broadcast('checkpoint');
|
||||||
});`}</Code>
|
});`}</CodeBoth>
|
||||||
<ScriptKind kind="object" on="золотое сокровище" />
|
<ScriptKind kind="object" on="золотое сокровище" />
|
||||||
<Code>{`// === Скрипт сокровища ===
|
<CodeBoth game="adventure-platformer" script="g41_finish">{`// === Скрипт сокровища ===
|
||||||
game.self.onTouch(() => {
|
game.self.onTouch(() => {
|
||||||
game.broadcast('treasure');
|
game.broadcast('treasure');
|
||||||
});`}</Code>
|
});`}</CodeBoth>
|
||||||
<p>
|
<p>
|
||||||
Монетка при касании засчитывается и исчезает. Чекпоинт
|
Монетка при касании засчитывается и исчезает. Чекпоинт
|
||||||
сохраняет место. Сокровище зовёт победу.
|
сохраняет место. Сокровище зовёт победу.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user