diff --git a/README.md b/README.md index aed31db4..2223427b 100644 --- a/README.md +++ b/README.md @@ -63,8 +63,6 @@ git clone https://github.com/ESX-Org/esx_menu_list [esx]/[ui]/esx_menu_list - Configure your `server.cfg` to look like this ``` -start baseevents - start mysql-async start essentialmode start esplugin_mysql diff --git a/__resource.lua b/__resource.lua index c947865a..a6a15dc6 100644 --- a/__resource.lua +++ b/__resource.lua @@ -52,6 +52,7 @@ client_scripts { 'client/wrapper.lua', 'client/main.lua', + 'client/modules/death.lua', 'client/modules/scaleform.lua', 'client/modules/streaming.lua', @@ -91,6 +92,5 @@ server_exports { dependencies { 'essentialmode', 'mysql-async', - 'async', - 'baseevents' + 'async' } diff --git a/client/main.lua b/client/main.lua index 10907c94..df46d989 100644 --- a/client/main.lua +++ b/client/main.lua @@ -76,56 +76,6 @@ AddEventHandler('playerSpawned', function() isDead = false end) -AddEventHandler('baseevents:onPlayerDied', function(killerType, deathCoords) - local playerPed = PlayerPedId() - - local data = { - killed = false, - killerType = killerType, - deathCoords = deathCoords, - deathCause = GetPedCauseOfDeath(playerPed) - } - - TriggerEvent('esx:onPlayerDeath', data) - TriggerServerEvent('esx:onPlayerDeath', data) -end) - -AddEventHandler('baseevents:onPlayerKilled', function(killerId, data) - local playerPed = PlayerPedId() - local killer = GetPlayerFromServerId(killerId) - - if NetworkIsPlayerActive(killer) then - local victimCoords = data.killerpos - local weaponHash = data.weaponhash - - data.killerpos = nil - data.weaponhash = nil - - local killerPed = GetPlayerPed(killer) - local killerCoords = GetEntityCoords(killerPed) - local distance = GetDistanceBetweenCoords(victimCoords[1], victimCoords[2], victimCoords[3], killerCoords, false) - - table.insert(data, { - victimCoords = victimCoords, - weaponHash = weaponHash, - deathCause = GetPedCauseOfDeath(playerPed), - killed = true, - killerId = killerId, - killerCoords = { table.unpack(killerCoords) }, - distance = ESX.Round(distance) - }) - - else - table.insert(data, { - killed = false, - deathCause = GetPedCauseOfDeath(playerPed) - }) - end - - TriggerEvent('esx:onPlayerDeath', data) - TriggerServerEvent('esx:onPlayerDeath', data) -end) - AddEventHandler('esx:onPlayerDeath', function() isDead = true end) diff --git a/client/modules/death.lua b/client/modules/death.lua new file mode 100644 index 00000000..4c9aca54 --- /dev/null +++ b/client/modules/death.lua @@ -0,0 +1,65 @@ +Citizen.CreateThread(function() + local isDead = false + + while true do + Citizen.Wait(0) + + local player = PlayerId() + + if NetworkIsPlayerActive(player) then + local playerPed = PlayerPedId() + + if IsPedFatallyInjured(playerPed) and not isDead then + isDead = true + + local killer, killerWeapon = NetworkGetEntityKillerOfPlayer(player) + local killerServerId = NetworkGetPlayerIndexFromPed(killer) + + if killer ~= playerPed and killerServerId ~= nil and NetworkIsPlayerActive(killerServerId) then + PlayerKilledByPlayer(killerServerId, GetPlayerServerId(killerServerId), killerWeapon) + else + PlayerKilled() + end + + elseif not IsPedFatallyInjured(playerPed) then + isDead = false + end + end + end +end) + +function PlayerKilledByPlayer(killerServerId, killerClientId, killerWeapon) + local victimCoords = GetEntityCoords(PlayerPedId()) + local killerCoords = GetEntityCoords(killerPed) + local distance = GetDistanceBetweenCoords(victimCoords, killerCoords, true) + + local data = { + victimCoords = victimCoords, + killerCoords = killerCoords, + + killedByPlayer = true, + deathCause = killerWeapon, + distance = ESX.Math.Round(distance, 1), + + killerServerId = killerServerId, + killerClientId = killerClientId + } + + TriggerEvent('esx:onPlayerDeath', data) + TriggerServerEvent('esx:onPlayerDeath', data) +end + +function PlayerKilled() + local playerPed = PlayerPedId() + local victimCoords = GetEntityCoords(PlayerPedId()) + + local data = { + victimCoords = victimCoords, + + killedByPlayer = false, + deathCause = GetPedCauseOfDeath(playerPed) + } + + TriggerEvent('esx:onPlayerDeath', data) + TriggerServerEvent('esx:onPlayerDeath', data) +end \ No newline at end of file