mirror of
https://github.com/ND-Framework/ND_Core.git
synced 2026-08-18 14:26:03 +01:00
wip: death system
This commit is contained in:
55
client/death.lua
Normal file
55
client/death.lua
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
local ambulance
|
||||||
|
local usingAmbulance = false
|
||||||
|
local alreadyEliminated = false
|
||||||
|
|
||||||
|
NDCore.isResourceStarted("ND_Ambulance", function(started)
|
||||||
|
usingAmbulance = started
|
||||||
|
if not usingAmbulance then return end
|
||||||
|
ambulance = exports["ND_Ambulance"]
|
||||||
|
end)
|
||||||
|
|
||||||
|
local function PlayerEliminated(deathCause, killerServerId, killerClientId)
|
||||||
|
if alreadyEliminated then return end
|
||||||
|
alreadyEliminated = true
|
||||||
|
local info = {
|
||||||
|
deathCause = deathCause,
|
||||||
|
killerServerId = killerServerId,
|
||||||
|
killerClientId = killerClientId,
|
||||||
|
damagedBones = usingAmbulance and ambulance:getBodyDamage() or {}
|
||||||
|
}
|
||||||
|
TriggerEvent("ND:playerEliminated", info)
|
||||||
|
TriggerServerEvent("ND:playerEliminated", info)
|
||||||
|
Wait(1000)
|
||||||
|
alreadyEliminated = false
|
||||||
|
end
|
||||||
|
|
||||||
|
AddEventHandler("gameEventTriggered", function(name, args)
|
||||||
|
if name ~= "CEventNetworkEntityDamage" then return end
|
||||||
|
|
||||||
|
local victim = args[1]
|
||||||
|
if not IsPedAPlayer(victim) or NetworkGetPlayerIndexFromPed(victim) ~= cache.playerId then return end
|
||||||
|
|
||||||
|
if not IsPedDeadOrDying(victim, true) and GetEntityHealth(victim) > 0 then
|
||||||
|
local hit, bone = GetPedLastDamageBone(victim)
|
||||||
|
if hit and usingAmbulance then
|
||||||
|
local damageWeapon = ambulance:getLastDamagingWeapon(victim)
|
||||||
|
return damageWeapon and ambulance:updateBodyDamage(bone, damageWeapon)
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local killerEntity, deathCause = GetPedSourceOfDeath(cache.ped), GetPedCauseOfDeath(cache.ped)
|
||||||
|
local killerClientId = NetworkGetPlayerIndexFromPed(killerEntity)
|
||||||
|
if killerEntity ~= cache.ped and killerClientId and NetworkIsPlayerActive(killerClientId) then
|
||||||
|
return PlayerEliminated(deathCause, GetPlayerServerId(killerClientId), killerClientId)
|
||||||
|
end
|
||||||
|
PlayerEliminated(deathCause)
|
||||||
|
end)
|
||||||
|
|
||||||
|
local firstSpawn = true
|
||||||
|
exports.spawnmanager:setAutoSpawnCallback(function()
|
||||||
|
if firstSpawn then
|
||||||
|
firstSpawn = false
|
||||||
|
return exports.spawnmanager:spawnPlayer() and exports.spawnmanager:setAutoSpawn(false)
|
||||||
|
end
|
||||||
|
end)
|
||||||
@@ -16,6 +16,7 @@ client_scripts {
|
|||||||
"client/peds.lua",
|
"client/peds.lua",
|
||||||
"client/functions.lua",
|
"client/functions.lua",
|
||||||
"client/events.lua",
|
"client/events.lua",
|
||||||
|
"client/death.lua",
|
||||||
"compatibility/**/client.lua"
|
"compatibility/**/client.lua"
|
||||||
}
|
}
|
||||||
server_scripts {
|
server_scripts {
|
||||||
|
|||||||
@@ -122,3 +122,13 @@ SetTimeout(500, function()
|
|||||||
"database/vehicles.sql"
|
"database/vehicles.sql"
|
||||||
}, resourceName)
|
}, resourceName)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
RegisterNetEvent("ND:playerEliminated", function(info)
|
||||||
|
local src = source
|
||||||
|
local player = NDCore.getPlayer(src)
|
||||||
|
if not player then return end
|
||||||
|
player.setMetadata({
|
||||||
|
dead = true,
|
||||||
|
deathInfo = info
|
||||||
|
})
|
||||||
|
end)
|
||||||
|
|||||||
Reference in New Issue
Block a user