Created
August 27, 2020 16:01
-
-
Save wowjeeez/22302bdb2fa2fdaf5393003be7be07be to your computer and use it in GitHub Desktop.
not made by me
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Citizen.CreateThread(function() | |
local isDead = false | |
local hasBeenDead = false | |
local diedAt | |
while true do | |
Wait(0) | |
local player = PlayerId() | |
if NetworkIsPlayerActive(player) then | |
local ped = PlayerPedId() | |
if IsPedFatallyInjured(ped) and not isDead then | |
isDead = true | |
if not diedAt then | |
diedAt = GetGameTimer() | |
end | |
local killer, killerweapon = NetworkGetEntityKillerOfPlayer(player) | |
local killerentitytype = GetEntityType(killer) | |
local killertype = -1 | |
local killerinvehicle = false | |
local killervehiclename = '' | |
local killervehicleseat = 0 | |
if killerentitytype == 1 then | |
killertype = GetPedType(killer) | |
if IsPedInAnyVehicle(killer, false) == 1 then | |
killerinvehicle = true | |
killervehiclename = GetDisplayNameFromVehicleModel(GetEntityModel(GetVehiclePedIsUsing(killer))) | |
killervehicleseat = GetPedVehicleSeat(killer) | |
else killerinvehicle = false | |
end | |
end | |
local killerid = GetPlayerByEntityID(killer) | |
if killer ~= ped and killerid ~= nil and NetworkIsPlayerActive(killerid) then killerid = GetPlayerServerId(killerid) | |
else killerid = -1 | |
end | |
if killer == ped or killer == -1 then | |
TriggerEvent('baseevents:onPlayerDied', killertype, { table.unpack(GetEntityCoords(ped)) }) | |
TriggerServerEvent('baseevents:onPlayerDied', killertype, { table.unpack(GetEntityCoords(ped)) }) | |
hasBeenDead = true | |
else | |
TriggerEvent('baseevents:onPlayerKilled', killerid, {killertype=killertype, weaponhash = killerweapon, killerinveh=killerinvehicle, killervehseat=killervehicleseat, killervehname=killervehiclename, killerpos={table.unpack(GetEntityCoords(ped))}}) | |
TriggerServerEvent('baseevents:onPlayerKilled', killerid, {killertype=killertype, weaponhash = killerweapon, killerinveh=killerinvehicle, killervehseat=killervehicleseat, killervehname=killervehiclename, killerpos={table.unpack(GetEntityCoords(ped))}}) | |
hasBeenDead = true | |
end | |
elseif not IsPedFatallyInjured(ped) then | |
isDead = false | |
diedAt = nil | |
end | |
-- check if the player has to respawn in order to trigger an event | |
if not hasBeenDead and diedAt ~= nil and diedAt > 0 then | |
TriggerEvent('baseevents:onPlayerWasted', { table.unpack(GetEntityCoords(ped)) }) | |
TriggerServerEvent('baseevents:onPlayerWasted', { table.unpack(GetEntityCoords(ped)) }) | |
hasBeenDead = true | |
elseif hasBeenDead and diedAt ~= nil and diedAt <= 0 then | |
hasBeenDead = false | |
end | |
end | |
end | |
end) | |
function GetPlayerByEntityID(id) | |
for i=0,32 do | |
if(NetworkIsPlayerActive(i) and GetPlayerPed(i) == id) then return i end | |
end | |
return nil | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment