From 55f4a3fc381f110626b2e293a1c2152038844cba Mon Sep 17 00:00:00 2001 From: min Date: Mon, 8 Jun 2026 11:38:03 +0300 Subject: [PATCH] =?UTF-8?q?fix(lua):=20humanoid.Health=3D0=20=D1=82=D0=B5?= =?UTF-8?q?=D0=BF=D0=B5=D1=80=D1=8C=20=D1=80=D0=B5=D0=B0=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D0=BE=20=D1=83=D0=B1=D0=B8=D0=B2=D0=B0=D0=B5=D1=82=20=D0=B8?= =?UTF-8?q?=D0=B3=D1=80=D0=BE=D0=BA=D0=B0=20=D1=87=D0=B5=D1=80=D0=B5=D0=B7?= =?UTF-8?q?=20PlayerController.takeDamage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/editor/engine/GameRuntime.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/editor/engine/GameRuntime.js b/src/editor/engine/GameRuntime.js index 7062b70..0c9c3a7 100644 --- a/src/editor/engine/GameRuntime.js +++ b/src/editor/engine/GameRuntime.js @@ -3979,21 +3979,21 @@ export class GameRuntime { return; } if (cmd === 'playerSet' && payload) { - // Из Lua-runtime: humanoid.Health = 0 → шлёт {prop:'health', value:N}. - // Применяем к реальному игроку BabylonScene. + // Из Lua-runtime: humanoid.Health = N → {prop:'health', value:N}. + // Используем PlayerController.takeDamage, который запускает полный + // death-flow: distance debris, _onDeath callback (respawn), звук. + // Сбрасываем _lastDamageTime чтобы invulnerability не блокировал. const player = this.scene3d?.player; if (!player) return; if (payload.prop === 'health') { - const v = Math.max(0, Number(payload.value) || 0); - player.hp = v; - if (v === 0) { - try { this.routeGlobalEvent('playerDied', {}); } catch (_) {} - // Перезагружаем игру (как при смерти) - try { - if (this.scene3d?.respawnPlayer) this.scene3d.respawnPlayer(); - } catch (_) {} + const target = Math.max(0, Number(payload.value) || 0); + const damage = Math.max(0, (player.hp || 0) - target); + if (damage > 0 && typeof player.takeDamage === 'function') { + player._lastDamageTime = 0; + player.takeDamage(damage, 'lua'); + } else { + player.hp = target; } - try { this.routeGlobalEvent('hpChange', { hp: v }); } catch (_) {} } return; }