161 lines
5.0 KiB
Lua
161 lines
5.0 KiB
Lua
print("^2[turfwar]^7 killfeed_chat.lua loaded (client)")
|
|
|
|
local PlayerGang = {} -- [serverId] = gangId
|
|
|
|
RegisterNetEvent('turfwar:playerGang', function(serverId, gangId)
|
|
PlayerGang[tonumber(serverId)] = tonumber(gangId) or 0
|
|
end)
|
|
|
|
-- Optional snapshot
|
|
CreateThread(function()
|
|
Wait(1500)
|
|
TriggerServerEvent('turfwar:requestAllPlayerGangs')
|
|
end)
|
|
|
|
RegisterNetEvent('turfwar:allPlayerGangs', function(map)
|
|
if type(map) ~= "table" then return end
|
|
for sid, gid in pairs(map) do
|
|
PlayerGang[tonumber(sid)] = tonumber(gid) or 0
|
|
end
|
|
end)
|
|
|
|
local function weaponLabelFromHash(hash)
|
|
local t = {
|
|
[`WEAPON_UNARMED`] = "Fists",
|
|
[`WEAPON_KNIFE`] = "Knife",
|
|
[`WEAPON_PISTOL`] = "Pistol",
|
|
[`WEAPON_COMBATPISTOL`] = "Combat Pistol",
|
|
[`WEAPON_APPISTOL`] = "AP Pistol",
|
|
[`WEAPON_SMG`] = "SMG",
|
|
[`WEAPON_ASSAULTRIFLE`] = "Assault Rifle",
|
|
[`WEAPON_CARBINERIFLE`] = "Carbine Rifle",
|
|
[`WEAPON_PUMPSHOTGUN`] = "Pump Shotgun",
|
|
[`WEAPON_SNIPERRIFLE`] = "Sniper Rifle",
|
|
[`WEAPON_HEAVYSNIPER`] = "Heavy Sniper",
|
|
[`WEAPON_GRENADE`] = "Grenade",
|
|
[`WEAPON_EXPLOSION`] = "Explosion",
|
|
[`WEAPON_RUN_OVER_BY_CAR`] = "Vehicle",
|
|
}
|
|
if t[hash] then return t[hash] end
|
|
|
|
local disp = GetWeaponDisplayNameFromHash(hash)
|
|
if disp and disp ~= "" then
|
|
local label = GetLabelText(disp)
|
|
if label and label ~= "NULL" then return label end
|
|
end
|
|
|
|
return tostring(hash)
|
|
end
|
|
|
|
local function gangRgbTable(gangId)
|
|
gangId = tonumber(gangId) or 0
|
|
local g = (Config and Config.GANGS and Config.GANGS[gangId]) or nil
|
|
if g and type(g.rgb) == "table" then
|
|
local r = tonumber(g.rgb[1]) or 255
|
|
local gg = tonumber(g.rgb[2]) or 255
|
|
local b = tonumber(g.rgb[3]) or 255
|
|
return { r, gg, b }
|
|
end
|
|
return {255,255,255}
|
|
end
|
|
|
|
-- =========================================================
|
|
-- Victim reports once (PvP + non-player deaths)
|
|
-- =========================================================
|
|
local lastSentAt = 0
|
|
CreateThread(function()
|
|
while true do
|
|
Wait(0)
|
|
|
|
local ped = PlayerPedId()
|
|
if ped ~= 0 and IsEntityDead(ped) then
|
|
local now = GetGameTimer()
|
|
if now - lastSentAt > 2000 then
|
|
lastSentAt = now
|
|
|
|
local killerPed = GetPedSourceOfDeath(ped)
|
|
local weaponHash = GetPedCauseOfDeath(ped)
|
|
local victimServerId = GetPlayerServerId(PlayerId())
|
|
|
|
local reported = false
|
|
|
|
-- PvP killer?
|
|
if killerPed and killerPed ~= 0 and IsEntityAPed(killerPed) and IsPedAPlayer(killerPed) then
|
|
local killerPlayer = NetworkGetPlayerIndexFromPed(killerPed)
|
|
local killerServerId = killerPlayer and GetPlayerServerId(killerPlayer) or 0
|
|
|
|
if killerServerId and killerServerId > 0 then
|
|
local myCoords = GetEntityCoords(ped)
|
|
local kCoords = GetEntityCoords(killerPed)
|
|
local dist = #(myCoords - kCoords)
|
|
|
|
local ok, bone = GetPedLastDamageBone(ped)
|
|
local headshot = (ok and bone == 31086)
|
|
|
|
TriggerServerEvent('turfwar:killfeed:report', {
|
|
killer = killerServerId,
|
|
victim = victimServerId,
|
|
weapon = weaponHash,
|
|
headshot = headshot,
|
|
distance = dist,
|
|
killerGang = PlayerGang[killerServerId] or 0,
|
|
victimGang = PlayerGang[victimServerId] or 0,
|
|
})
|
|
|
|
reported = true
|
|
end
|
|
end
|
|
|
|
-- Non-player death fallback
|
|
if not reported then
|
|
TriggerServerEvent('turfwar:killfeed:report', {
|
|
killer = 0,
|
|
victim = victimServerId,
|
|
weapon = weaponHash or 0,
|
|
headshot = false,
|
|
distance = 0,
|
|
killerGang = 0,
|
|
victimGang = PlayerGang[victimServerId] or 0,
|
|
})
|
|
end
|
|
end
|
|
|
|
while IsEntityDead(PlayerPedId()) do Wait(200) end
|
|
Wait(500)
|
|
end
|
|
end
|
|
end)
|
|
|
|
-- =========================================================
|
|
-- Receive broadcast -> send to NUI
|
|
-- =========================================================
|
|
RegisterNetEvent('turfwar:killfeed:chat', function(data)
|
|
if type(data) ~= "table" then return end
|
|
|
|
local victimRgb = gangRgbTable(data.victimGang)
|
|
local killerRgb = gangRgbTable(data.killerGang)
|
|
|
|
local deathOnly = (data.isDeathOnly == true) or (tonumber(data.killer or 0) <= 0)
|
|
|
|
if deathOnly then
|
|
SendNUIMessage({
|
|
type = "killfeed:add",
|
|
isDeathOnly = true,
|
|
victimName = data.victimName or "Unknown",
|
|
victimRgb = victimRgb,
|
|
})
|
|
return
|
|
end
|
|
|
|
SendNUIMessage({
|
|
type = "killfeed:add",
|
|
killerName = data.killerName or "Unknown",
|
|
victimName = data.victimName or "Unknown",
|
|
weapon = weaponLabelFromHash(tonumber(data.weapon or 0) or 0),
|
|
headshot = (data.headshot == true),
|
|
distance = tonumber(data.distance or 0) or 0,
|
|
killerRgb = killerRgb,
|
|
victimRgb = victimRgb,
|
|
})
|
|
end)
|