Ditch baseevents, closes #125, see #118

This commit is contained in:
ElPumpo
2018-11-17 12:39:43 +01:00
parent d804fb316f
commit 096a84aa1b
4 changed files with 67 additions and 54 deletions
-2
View File
@@ -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
+2 -2
View File
@@ -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'
}
-50
View File
@@ -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)
+65
View File
@@ -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