2026-04-14 15:54:53 +02:00

159 lines
5.9 KiB
Lua

-- MercyV Kill Logs
-- Sendet alle Spielertode an Discord via Bot API
local API_URL = 'http://185.223.31.65:3010/api/events/killlogs'
local API_SECRET = 'MercyV_SecureAPI_2025_xK9mP2nL7qR'
-- Waffen-Hash zu Name Mapping (die wichtigsten)
local WeaponNames = {
-- Nahkampf
[`WEAPON_UNARMED`] = 'WEAPON_FIST',
[`WEAPON_KNIFE`] = 'WEAPON_KNIFE',
[`WEAPON_BAT`] = 'WEAPON_BAT',
[`WEAPON_HAMMER`] = 'WEAPON_HAMMER',
[`WEAPON_MACHETE`] = 'WEAPON_MACHETE',
-- Pistolen
[`WEAPON_PISTOL`] = 'WEAPON_PISTOL',
[`WEAPON_COMBATPISTOL`] = 'WEAPON_COMBATPISTOL',
[`WEAPON_APPISTOL`] = 'WEAPON_APPISTOL',
[`WEAPON_PISTOL50`] = 'WEAPON_PISTOL50',
[`WEAPON_REVOLVER`] = 'WEAPON_REVOLVER',
[`WEAPON_SNSPISTOL`] = 'WEAPON_SNSPISTOL',
[`WEAPON_HEAVYPISTOL`] = 'WEAPON_HEAVYPISTOL',
-- SMGs
[`WEAPON_MICROSMG`] = 'WEAPON_MICROSMG',
[`WEAPON_SMG`] = 'WEAPON_SMG',
[`WEAPON_ASSAULTSMG`] = 'WEAPON_ASSAULTSMG',
[`WEAPON_COMBATPDW`] = 'WEAPON_COMBATPDW',
[`WEAPON_MACHINEPISTOL`] = 'WEAPON_MACHINEPISTOL',
[`WEAPON_MINISMG`] = 'WEAPON_MINISMG',
-- Gewehre
[`WEAPON_ASSAULTRIFLE`] = 'WEAPON_ASSAULTRIFLE',
[`WEAPON_CARBINERIFLE`] = 'WEAPON_CARBINERIFLE',
[`WEAPON_ADVANCEDRIFLE`] = 'WEAPON_ADVANCEDRIFLE',
[`WEAPON_SPECIALCARBINE`] = 'WEAPON_SPECIALCARBINE',
[`WEAPON_BULLPUPRIFLE`] = 'WEAPON_BULLPUPRIFLE',
[`WEAPON_COMPACTRIFLE`] = 'WEAPON_COMPACTRIFLE',
-- MGs
[`WEAPON_MG`] = 'WEAPON_MG',
[`WEAPON_COMBATMG`] = 'WEAPON_COMBATMG',
[`WEAPON_GUSENBERG`] = 'WEAPON_GUSENBERG',
-- Scharfschützengewehre
[`WEAPON_SNIPERRIFLE`] = 'WEAPON_SNIPERRIFLE',
[`WEAPON_HEAVYSNIPER`] = 'WEAPON_HEAVYSNIPER',
[`WEAPON_MARKSMANRIFLE`] = 'WEAPON_MARKSMANRIFLE',
-- Shotguns
[`WEAPON_PUMPSHOTGUN`] = 'WEAPON_PUMPSHOTGUN',
[`WEAPON_SAWNOFFSHOTGUN`] = 'WEAPON_SAWNOFFSHOTGUN',
[`WEAPON_ASSAULTSHOTGUN`] = 'WEAPON_ASSAULTSHOTGUN',
[`WEAPON_BULLPUPSHOTGUN`] = 'WEAPON_BULLPUPSHOTGUN',
[`WEAPON_HEAVYSHOTGUN`] = 'WEAPON_HEAVYSHOTGUN',
[`WEAPON_DBSHOTGUN`] = 'WEAPON_DBSHOTGUN',
[`WEAPON_MUSKET`] = 'WEAPON_MUSKET',
-- Explosiv
[`WEAPON_GRENADE`] = 'WEAPON_GRENADE',
[`WEAPON_STICKYBOMB`] = 'WEAPON_STICKYBOMB',
[`WEAPON_MOLOTOV`] = 'WEAPON_MOLOTOV',
[`WEAPON_RPG`] = 'WEAPON_RPG',
[`WEAPON_GRENADELAUNCHER`] = 'WEAPON_GRENADELAUNCHER',
[`WEAPON_MINIGUN`] = 'WEAPON_MINIGUN',
-- Sonstiges
[`WEAPON_STUNGUN`] = 'WEAPON_STUNGUN',
[`WEAPON_PETROLCAN`] = 'WEAPON_PETROLCAN',
[`WEAPON_FIREEXTINGUISHER`] = 'WEAPON_FIREEXTINGUISHER',
-- Todesursachen
[`WEAPON_FALL`] = 'WEAPON_FALL',
[`WEAPON_DROWNING`] = 'WEAPON_DROWNING',
[`WEAPON_DROWNING_IN_VEHICLE`] = 'WEAPON_DROWNING',
[`WEAPON_BLEEDING`] = 'WEAPON_BLEEDING',
[`WEAPON_FIRE`] = 'WEAPON_FIRE',
[`WEAPON_ELECTRIC_FENCE`] = 'WEAPON_ELECTRIC',
[`WEAPON_EXPLOSION`] = 'WEAPON_EXPLOSION',
[`WEAPON_RAMMED_BY_CAR`] = 'WEAPON_VEHICLE',
[`WEAPON_RUN_OVER_BY_CAR`] = 'WEAPON_VEHICLE',
[`WEAPON_VEHICLE_ROCKET`] = 'WEAPON_VEHICLE',
}
-- Todesursache aus Waffe ableiten
local function getCause(weaponHash)
if weaponHash == `WEAPON_FALL` then return 'fall' end
if weaponHash == `WEAPON_DROWNING` or weaponHash == `WEAPON_DROWNING_IN_VEHICLE` then return 'drown' end
if weaponHash == `WEAPON_FIRE` or weaponHash == `WEAPON_MOLOTOV` then return 'fire' end
if weaponHash == `WEAPON_EXPLOSION` or weaponHash == `WEAPON_RPG` or weaponHash == `WEAPON_GRENADE` or weaponHash == `WEAPON_STICKYBOMB` then return 'explosion' end
if weaponHash == `WEAPON_RAMMED_BY_CAR` or weaponHash == `WEAPON_RUN_OVER_BY_CAR` then return 'vehicle' end
return nil
end
-- Waffen-Name aus Hash holen
local function getWeaponName(weaponHash)
return WeaponNames[weaponHash] or ('WEAPON_UNKNOWN_' .. tostring(weaponHash))
end
-- Kill Log an API senden
local function sendKillLog(victim, killer, weaponHash, coords)
local victimName = GetPlayerName(victim) or 'Unbekannt'
local killerName = killer and GetPlayerName(killer) or nil
local weaponName = getWeaponName(weaponHash)
local cause = getCause(weaponHash)
-- Selbstmord prüfen
if killer and killer == victim then
cause = 'suicide'
killerName = nil
end
local payload = json.encode({
victim = victimName,
killer = killerName,
weapon = weaponName,
location = coords and {
x = coords.x,
y = coords.y,
z = coords.z
} or nil,
cause = cause
})
PerformHttpRequest(API_URL, function(errorCode, resultData, resultHeaders)
if errorCode ~= 200 then
print('[mercyv-killlogs] API Error: ' .. tostring(errorCode))
end
end, 'POST', payload, {
['Content-Type'] = 'application/json',
['Authorization'] = 'Bearer ' .. API_SECRET,
['X-User-ID'] = 'fivem-server'
})
end
-- ESX Death Event (für ESX Legacy)
AddEventHandler('esx:onPlayerDeath', function(data)
local victim = data.victim
local killer = data.killer
local weaponHash = data.deathCause or `WEAPON_UNARMED`
-- Koordinaten vom Opfer holen
local victimPed = GetPlayerPed(victim)
local coords = victimPed and GetEntityCoords(victimPed) or nil
sendKillLog(victim, killer, weaponHash, coords)
end)
-- Alternative: baseevents (falls esx:onPlayerDeath nicht funktioniert)
RegisterNetEvent('baseevents:onPlayerDied')
AddEventHandler('baseevents:onPlayerDied', function(killerType, coords)
local victim = source
sendKillLog(victim, nil, `WEAPON_UNARMED`, coords)
end)
RegisterNetEvent('baseevents:onPlayerKilled')
AddEventHandler('baseevents:onPlayerKilled', function(killerId, data)
local victim = source
local killer = killerId
local weaponHash = data.weaponhash or `WEAPON_UNARMED`
local coords = data.killerpos or nil
sendKillLog(victim, killer, weaponHash, coords)
end)
print('[mercyv-killlogs] Kill Logs Resource gestartet')