fix(lua): humanoid.Health=0 теперь реально убивает игрока через PlayerController.takeDamage

This commit is contained in:
min 2026-06-08 11:38:03 +03:00
parent 30d472bf43
commit 55f4a3fc38

View File

@ -3979,21 +3979,21 @@ export class GameRuntime {
return; return;
} }
if (cmd === 'playerSet' && payload) { if (cmd === 'playerSet' && payload) {
// Из Lua-runtime: humanoid.Health = 0 → шлёт {prop:'health', value:N}. // Из Lua-runtime: humanoid.Health = N → {prop:'health', value:N}.
// Применяем к реальному игроку BabylonScene. // Используем PlayerController.takeDamage, который запускает полный
// death-flow: distance debris, _onDeath callback (respawn), звук.
// Сбрасываем _lastDamageTime чтобы invulnerability не блокировал.
const player = this.scene3d?.player; const player = this.scene3d?.player;
if (!player) return; if (!player) return;
if (payload.prop === 'health') { if (payload.prop === 'health') {
const v = Math.max(0, Number(payload.value) || 0); const target = Math.max(0, Number(payload.value) || 0);
player.hp = v; const damage = Math.max(0, (player.hp || 0) - target);
if (v === 0) { if (damage > 0 && typeof player.takeDamage === 'function') {
try { this.routeGlobalEvent('playerDied', {}); } catch (_) {} player._lastDamageTime = 0;
// Перезагружаем игру (как при смерти) player.takeDamage(damage, 'lua');
try { } else {
if (this.scene3d?.respawnPlayer) this.scene3d.respawnPlayer(); player.hp = target;
} catch (_) {}
} }
try { this.routeGlobalEvent('hpChange', { hp: v }); } catch (_) {}
} }
return; return;
} }