forked from Simnation/Main
60 lines
2.3 KiB
Lua
60 lines
2.3 KiB
Lua
![]() |
local QBCore = exports['qb-core']:GetCoreObject()
|
||
|
|
||
|
-- Klingel Event Handler
|
||
|
RegisterNetEvent('qb-doorbell:server:ringDoorbell', function(doorbellData)
|
||
|
local src = source
|
||
|
local Player = QBCore.Functions.GetPlayer(src)
|
||
|
|
||
|
if not Player then return end
|
||
|
|
||
|
local senderName = Player.PlayerData.charinfo.firstname .. " " .. Player.PlayerData.charinfo.lastname
|
||
|
|
||
|
-- Alle Spieler durchgehen
|
||
|
local players = QBCore.Functions.GetPlayers()
|
||
|
local notificationsSent = 0
|
||
|
|
||
|
for _, playerId in pairs(players) do
|
||
|
local targetPlayer = QBCore.Functions.GetPlayer(playerId)
|
||
|
if targetPlayer then
|
||
|
local targetCoords = GetEntityCoords(GetPlayerPed(playerId))
|
||
|
local distance = #(targetCoords - doorbellData.notification.coords)
|
||
|
|
||
|
-- Prüfen ob Spieler im Radius ist
|
||
|
if distance <= doorbellData.notification.radius then
|
||
|
local canReceive = false
|
||
|
|
||
|
-- Job-Prüfung
|
||
|
if doorbellData.notification.requireJob then
|
||
|
-- Prüfen ob Spieler einen der erlaubten Jobs hat
|
||
|
for _, allowedJob in pairs(doorbellData.notification.allowedJobs) do
|
||
|
if targetPlayer.PlayerData.job.name == allowedJob then
|
||
|
canReceive = true
|
||
|
break
|
||
|
end
|
||
|
end
|
||
|
else
|
||
|
-- Keine Job-Anforderung, jeder kann Benachrichtigung erhalten
|
||
|
canReceive = true
|
||
|
end
|
||
|
|
||
|
-- Benachrichtigung senden
|
||
|
if canReceive then
|
||
|
TriggerClientEvent('qb-doorbell:client:receiveNotification', playerId,
|
||
|
doorbellData.notification.message, senderName)
|
||
|
notificationsSent = notificationsSent + 1
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
-- Feedback an den Klingelnden wenn niemand erreicht wurde
|
||
|
if notificationsSent == 0 then
|
||
|
TriggerClientEvent('ox_lib:notify', src, {
|
||
|
title = 'Klingel',
|
||
|
description = 'Niemand scheint in der Nähe zu sein...',
|
||
|
type = 'error',
|
||
|
duration = 4000
|
||
|
})
|
||
|
end
|
||
|
end)
|