From 53adfb86b448356baf2d7159cb879d01c10f5be5 Mon Sep 17 00:00:00 2001 From: VegaZ Date: Sun, 21 Oct 2018 15:35:33 +0200 Subject: [PATCH] Edit Death System --- Client/Gui/deathscreen.js | 47 +++++++++++++++++++++++++-------------- Server/Events/Death.cs | 12 ++++++++++ 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/Client/Gui/deathscreen.js b/Client/Gui/deathscreen.js index 6cca290c..806ec6d2 100644 --- a/Client/Gui/deathscreen.js +++ b/Client/Gui/deathscreen.js @@ -12,38 +12,51 @@ var isDeath = false; var deathTime; var respawnTime; var deathSeconds; +var fade; + +mp.game.gameplay.setFadeOutAfterDeath(false); mp.events.add("startDeathTimer", () => { if (isDeath === false) { isDeath = true; mp.gui.chat.activate(false); - mp.gui.chat.show(false); deathDate = new Date(); - respawnTime = deathDate.getSeconds() + 120; - secondsToAlpha = 120; + respawnTime = Math.floor(deathDate.getTime() / 1000 + 120); + fade = 255 - 120; } }); mp.events.add("onPlayerRevived", () => { isDeath = false; mp.gui.chat.activate(true); - mp.gui.chat.show(true); + mp.game.gameplay.setFadeOutAfterDeath(false); + mp.events.callRemote('RespawnPlayerAtDeathpoint'); +}); + +mp.events.add("respawnDeathPlayer", () => { + isDeath = false; + mp.gui.chat.activate(true); + mp.game.gameplay.setFadeOutAfterDeath(false); + mp.events.callRemote('RespawnPlayerAtHospital'); }); mp.events.add("render", () => { + currentDate = new Date(); - if (isDeath === true) { - currentDate = new Date(); - - deathSeconds = respawnTime - currentDate.getSeconds(); - mp.game.graphics.drawText("~y~" + deathSeconds, [0.5, 0.5], - { - font: 7, - color: [255, 255, 255, 255], - scale: [0.8, 0.8], - outline: true - }) - mp.game.graphics.drawRect(0.5, 0.5, 1, 1, 0, 0, 0, deathSeconds); - + if (isDeath === true) { + deathSeconds = respawnTime - Math.floor(currentDate.getTime() / 1000); + var alpha = fade + (Math.floor((currentDate.getTime() / 1000) - (deathDate.getTime() / 1000))); + if (deathSeconds >= 0) { + mp.game.graphics.drawText("~y~" + deathSeconds, [0.5, 0.5], + { + font: 7, + color: [255, 255, 255, 255], + scale: [0.8, 0.8], + outline: true + }) + mp.game.graphics.drawRect(0.5, 0.5, 1, 1, 0, 0, 0, alpha); + } else { + mp.events.call("respawnDeathPlayer"); + } } }); \ No newline at end of file diff --git a/Server/Events/Death.cs b/Server/Events/Death.cs index c345bedc..048d43a5 100644 --- a/Server/Events/Death.cs +++ b/Server/Events/Death.cs @@ -62,5 +62,17 @@ namespace reallife_gamemode.Server.Events userDeath.SaveChanges(); } } + [RemoteEvent("RespawnPlayerAtHospital")] + public void RespawnPlayerAtHospital(Client player) + { + player.RemoveAllWeapons(); + NAPI.Player.SpawnPlayer(player, new Vector3(-495.45, -336.33, 34.5)); + } + [RemoteEvent("RespawnPlayerAtDeathpoint")] + public void RespawnPlayerAtDeathpoint(Client player) + { + NAPI.Player.SpawnPlayer(player, player.Position); + } } + }