From bbaf1aa90f4fce80e40f113a31cc3751d2af282e Mon Sep 17 00:00:00 2001 From: Andyyy7666 <86536434+Andyyy7666@users.noreply.github.com> Date: Sun, 24 Sep 2023 11:19:22 +0200 Subject: [PATCH] feat: revive player --- client/functions.lua | 39 +++++++++++++++++++++++++++++++++++++++ server/player.lua | 8 ++++++++ 2 files changed, 47 insertions(+) diff --git a/client/functions.lua b/client/functions.lua index 9cd34f2..074e0a5 100644 --- a/client/functions.lua +++ b/client/functions.lua @@ -26,6 +26,45 @@ function NDCore.getPlayersFromCoords(distance, coords) return closePlayers end +function NDCore.revivePlayer(reset, keepDead) + local usingAmbulance = GetResourceState("ND_Ambulance") == "started" + local veh = GetVehiclePedIsIn(cache.ped) + local seat = cache.seat + local coords = GetEntityCoords(cache.ped) + NetworkResurrectLocalPlayer(coords.x, coords.y, coords.z, GetEntityHeading(cache.ped), true, true, false) + + local ped = PlayerPedId() + if cache.ped ~= ped then + DeleteEntity(cache.ped) + ClearAreaOfPeds(coords.x, coords.y, coords.z, 1.5, false) + end + + SetEntityInvincible(ped, false) + FreezeEntityPosition(ped, false) + SetEntityVisible(ped, true) + SetEveryoneIgnorePlayer(ped, false) + SetPedCanBeTargetted(ped, true) + SetEntityCanBeDamaged(ped, true) + SetBlockingOfNonTemporaryEvents(ped, false) + SetPedCanRagdollFromPlayerImpact(ped, true) + ClearPedTasksImmediately(ped) + + if veh and veh ~= 0 then + SetPedIntoVehicle(ped, veh, seat) + end + if not keepDead then + LocalPlayer.state.dead = false + end + if reset and GetPedMovementClipset(ped) == `move_m@injured` then + ClearEntityLastDamageEntity(ped) + SetPedMoveRateOverride(ped, 1.0) + ResetPedMovementClipset(ped, 0) + end + if reset and usingAmbulance then + exports["ND_Ambulance"]:resetBodyDamage() + end +end + function NDCore.notify(...) if GetResourceState("ModernHUD") == "started" then exports["ModernHUD"]:notify(...) diff --git a/server/player.lua b/server/player.lua index 8b0fa0e..ea2557b 100644 --- a/server/player.lua +++ b/server/player.lua @@ -261,6 +261,14 @@ local function createCharacterTable(info) return true end + function self.revive() + self.triggerEvent("ND:revivePlayer") + self.setMetadata({ + dead = nil, + deathInfo = nil, + }) + end + ---@param reason string function self.drop(reason) if not self.source then return end