forked from Simnation/Main
416 lines
12 KiB
Lua
416 lines
12 KiB
Lua
local QBCore = exports['qb-core']:GetCoreObject()
|
|
local playerLicenses = {}
|
|
local nearbyPlayers = {}
|
|
|
|
-- Keybind registrieren
|
|
RegisterKeyMapping(Config.Command, 'Lizenz-Menü öffnen', 'keyboard', Config.OpenKey)
|
|
|
|
-- Events
|
|
RegisterNetEvent('license-system:client:openMenu', function()
|
|
TriggerServerEvent('license-system:server:getLicenses')
|
|
end)
|
|
|
|
RegisterNetEvent('license-system:client:receiveLicenses', function(licenses)
|
|
playerLicenses = licenses
|
|
openMainMenu()
|
|
end)
|
|
|
|
RegisterNetEvent('license-system:client:receiveNearbyPlayers', function(players)
|
|
nearbyPlayers = {}
|
|
local playerPed = PlayerPedId()
|
|
local playerCoords = GetEntityCoords(playerPed)
|
|
|
|
for _, playerId in ipairs(players) do
|
|
if playerId ~= GetPlayerServerId(PlayerId()) then
|
|
local targetPed = GetPlayerPed(GetPlayerFromServerId(playerId))
|
|
if targetPed and targetPed ~= 0 then
|
|
local targetCoords = GetEntityCoords(targetPed)
|
|
local distance = #(playerCoords - targetCoords)
|
|
|
|
if distance <= 5.0 then
|
|
local targetPlayer = QBCore.Functions.GetPlayerData(playerId)
|
|
table.insert(nearbyPlayers, {
|
|
id = playerId,
|
|
name = targetPlayer and (targetPlayer.charinfo.firstname .. ' ' .. targetPlayer.charinfo.lastname) or 'Unbekannt'
|
|
})
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end)
|
|
|
|
RegisterNetEvent('license-system:client:viewLicense', function(licenseData, issuerName)
|
|
showLicenseOverlay(licenseData, issuerName)
|
|
end)
|
|
|
|
-- Hauptmenü
|
|
function openMainMenu()
|
|
local options = {
|
|
{
|
|
title = 'Meine Lizenzen anzeigen',
|
|
description = 'Zeige alle deine Lizenzen an',
|
|
icon = 'fas fa-eye',
|
|
onSelect = function()
|
|
showMyLicenses()
|
|
end
|
|
},
|
|
{
|
|
title = 'Lizenz zeigen',
|
|
description = 'Zeige jemandem in der Nähe eine Lizenz',
|
|
icon = 'fas fa-share',
|
|
onSelect = function()
|
|
showLicenseToPlayer()
|
|
end
|
|
}
|
|
}
|
|
|
|
-- Admin-Optionen hinzufügen
|
|
local PlayerData = QBCore.Functions.GetPlayerData()
|
|
if PlayerData.job and Config.AuthorizedJobs[PlayerData.job.name] then
|
|
table.insert(options, {
|
|
title = 'Lizenz ausstellen',
|
|
description = 'Stelle eine neue Lizenz aus',
|
|
icon = 'fas fa-plus',
|
|
onSelect = function()
|
|
issueLicenseMenu()
|
|
end
|
|
})
|
|
|
|
table.insert(options, {
|
|
title = 'Lizenz verwalten',
|
|
description = 'Entziehe oder stelle Lizenzen wieder her',
|
|
icon = 'fas fa-cog',
|
|
onSelect = function()
|
|
manageLicensesMenu()
|
|
end
|
|
})
|
|
end
|
|
|
|
lib.registerContext({
|
|
id = 'license_main_menu',
|
|
title = 'Lizenz-System',
|
|
options = options
|
|
})
|
|
|
|
lib.showContext('license_main_menu')
|
|
end
|
|
|
|
-- Meine Lizenzen anzeigen
|
|
function showMyLicenses()
|
|
local options = {}
|
|
|
|
for _, license in ipairs(playerLicenses) do
|
|
local licenseConfig = Config.Licenses[license.license_type]
|
|
if licenseConfig then
|
|
local statusText = license.is_active and "✅ Aktiv" or "❌ Entzogen"
|
|
table.insert(options, {
|
|
title = licenseConfig.label,
|
|
description = 'Status: ' .. statusText .. ' | Ausgestellt: ' .. license.issue_date,
|
|
icon = licenseConfig.icon,
|
|
onSelect = function()
|
|
showLicenseOverlay(license)
|
|
end
|
|
})
|
|
end
|
|
end
|
|
|
|
if #options == 0 then
|
|
options = {{
|
|
title = 'Keine Lizenzen vorhanden',
|
|
description = 'Du besitzt derzeit keine Lizenzen',
|
|
icon = 'fas fa-exclamation-triangle'
|
|
}}
|
|
end
|
|
|
|
lib.registerContext({
|
|
id = 'my_licenses_menu',
|
|
title = 'Meine Lizenzen',
|
|
menu = 'license_main_menu',
|
|
options = options
|
|
})
|
|
|
|
lib.showContext('my_licenses_menu')
|
|
end
|
|
|
|
-- Lizenz jemandem zeigen
|
|
function showLicenseToPlayer()
|
|
TriggerServerEvent('license-system:server:getNearbyPlayers')
|
|
|
|
Wait(500) -- Kurz warten für die Antwort
|
|
|
|
if #nearbyPlayers == 0 then
|
|
lib.notify({
|
|
title = 'Lizenz-System',
|
|
description = 'Keine Spieler in der Nähe gefunden',
|
|
type = 'error'
|
|
})
|
|
return
|
|
end
|
|
|
|
local licenseOptions = {}
|
|
for _, license in ipairs(playerLicenses) do
|
|
if license.is_active then
|
|
local licenseConfig = Config.Licenses[license.license_type]
|
|
if licenseConfig then
|
|
table.insert(licenseOptions, {
|
|
title = licenseConfig.label,
|
|
description = 'Ausgestellt: ' .. license.issue_date,
|
|
icon = licenseConfig.icon,
|
|
onSelect = function()
|
|
selectPlayerToShow(license)
|
|
end
|
|
})
|
|
end
|
|
end
|
|
end
|
|
|
|
if #licenseOptions == 0 then
|
|
lib.notify({
|
|
title = 'Lizenz-System',
|
|
description = 'Du hast keine aktiven Lizenzen zum Zeigen',
|
|
type = 'error'
|
|
})
|
|
return
|
|
end
|
|
|
|
lib.registerContext({
|
|
id = 'select_license_to_show',
|
|
title = 'Lizenz auswählen',
|
|
menu = 'license_main_menu',
|
|
options = licenseOptions
|
|
})
|
|
|
|
lib.showContext('select_license_to_show')
|
|
end
|
|
|
|
function selectPlayerToShow(license)
|
|
local playerOptions = {}
|
|
|
|
for _, player in ipairs(nearbyPlayers) do
|
|
table.insert(playerOptions, {
|
|
title = player.name,
|
|
description = 'Zeige diesem Spieler deine Lizenz',
|
|
icon = 'fas fa-user',
|
|
onSelect = function()
|
|
TriggerServerEvent('license-system:server:showLicense', player.id, license)
|
|
lib.notify({
|
|
title = 'Lizenz-System',
|
|
description = 'Lizenz wurde ' .. player.name .. ' gezeigt',
|
|
type = 'success'
|
|
})
|
|
end
|
|
})
|
|
end
|
|
|
|
lib.registerContext({
|
|
id = 'select_player_to_show',
|
|
title = 'Spieler auswählen',
|
|
menu = 'select_license_to_show',
|
|
options = playerOptions
|
|
})
|
|
|
|
lib.showContext('select_player_to_show')
|
|
end
|
|
|
|
-- Lizenz ausstellen
|
|
function issueLicenseMenu()
|
|
local PlayerData = QBCore.Functions.GetPlayerData()
|
|
local authorizedLicenses = Config.AuthorizedJobs[PlayerData.job.name].canIssue
|
|
|
|
local options = {}
|
|
for _, licenseType in ipairs(authorizedLicenses) do
|
|
local licenseConfig = Config.Licenses[licenseType]
|
|
if licenseConfig then
|
|
table.insert(options, {
|
|
title = licenseConfig.label,
|
|
description = 'Stelle einen ' .. licenseConfig.label .. ' aus',
|
|
icon = licenseConfig.icon,
|
|
onSelect = function()
|
|
selectPlayerForLicense(licenseType)
|
|
end
|
|
})
|
|
end
|
|
end
|
|
|
|
lib.registerContext({
|
|
id = 'issue_license_menu',
|
|
title = 'Lizenz ausstellen',
|
|
menu = 'license_main_menu',
|
|
options = options
|
|
})
|
|
|
|
lib.showContext('issue_license_menu')
|
|
end
|
|
|
|
function selectPlayerForLicense(licenseType)
|
|
TriggerServerEvent('license-system:server:getNearbyPlayers')
|
|
|
|
Wait(500)
|
|
|
|
if #nearbyPlayers == 0 then
|
|
lib.notify({
|
|
title = 'Lizenz-System',
|
|
description = 'Keine Spieler in der Nähe gefunden',
|
|
type = 'error'
|
|
})
|
|
return
|
|
end
|
|
|
|
local playerOptions = {}
|
|
for _, player in ipairs(nearbyPlayers) do
|
|
table.insert(playerOptions, {
|
|
title = player.name,
|
|
description = 'Stelle diesem Spieler eine Lizenz aus',
|
|
icon = 'fas fa-user',
|
|
onSelect = function()
|
|
openLicenseForm(player.id, licenseType)
|
|
end
|
|
})
|
|
end
|
|
|
|
lib.registerContext({
|
|
id = 'select_player_for_license',
|
|
title = 'Spieler auswählen',
|
|
menu = 'issue_license_menu',
|
|
options = playerOptions
|
|
})
|
|
|
|
lib.showContext('select_player_for_license')
|
|
end
|
|
|
|
function openLicenseForm(targetId, licenseType)
|
|
local licenseConfig = Config.Licenses[licenseType]
|
|
local input = {}
|
|
|
|
if licenseConfig.fields.name then
|
|
table.insert(input, {
|
|
type = 'input',
|
|
isRequired = true,
|
|
label = 'Name',
|
|
placeholder = 'Vor- und Nachname'
|
|
})
|
|
end
|
|
|
|
if licenseConfig.fields.birthday then
|
|
table.insert(input, {
|
|
type = 'date',
|
|
isRequired = true,
|
|
label = 'Geburtsdatum'
|
|
})
|
|
end
|
|
|
|
if licenseConfig.fields.gender then
|
|
table.insert(input, {
|
|
type = 'select',
|
|
label = 'Geschlecht',
|
|
options = Config.Genders
|
|
})
|
|
end
|
|
|
|
if licenseConfig.fields.issue_date then
|
|
table.insert(input, {
|
|
type = 'date',
|
|
isRequired = true,
|
|
label = 'Ausstellungsdatum',
|
|
default = os.date('%Y-%m-%d')
|
|
})
|
|
end
|
|
|
|
if licenseConfig.fields.expire_date then
|
|
table.insert(input, {
|
|
type = 'date',
|
|
isRequired = true,
|
|
label = 'Ablaufdatum'
|
|
})
|
|
end
|
|
|
|
if licenseConfig.fields.classes then
|
|
local classOptions = {}
|
|
for _, class in ipairs(Config.LicenseClasses) do
|
|
table.insert(classOptions, {
|
|
value = class,
|
|
label = 'Klasse ' .. class
|
|
})
|
|
end
|
|
|
|
table.insert(input, {
|
|
type = 'multi-select',
|
|
label = 'Führerscheinklassen',
|
|
options = classOptions
|
|
})
|
|
end
|
|
|
|
local dialog = lib.inputDialog('Lizenz ausstellen - ' .. licenseConfig.label, input)
|
|
|
|
if dialog then
|
|
local licenseData = {
|
|
name = dialog[1],
|
|
birthday = dialog[2],
|
|
gender = dialog[3],
|
|
issue_date = dialog[4] or os.date('%Y-%m-%d'),
|
|
expire_date = dialog[5],
|
|
classes = dialog[6]
|
|
}
|
|
|
|
TriggerServerEvent('license-system:server:issueLicense', targetId, licenseType, licenseData)
|
|
end
|
|
end
|
|
|
|
-- Lizenz-Overlay anzeigen
|
|
function showLicenseOverlay(licenseData, issuerName)
|
|
local licenseConfig = Config.Licenses[licenseData.license_type]
|
|
if not licenseConfig then return end
|
|
|
|
-- NUI öffnen
|
|
SetNuiFocus(true, true)
|
|
SendNUIMessage({
|
|
action = 'showLicense',
|
|
data = {
|
|
license = licenseData,
|
|
config = licenseConfig,
|
|
issuer = issuerName
|
|
}
|
|
})
|
|
end
|
|
|
|
-- NUI Callbacks
|
|
RegisterNUICallback('closeLicense', function(data, cb)
|
|
SetNuiFocus(false, false)
|
|
cb('ok')
|
|
end)
|
|
|
|
-- Lizenz verwalten (für autorisierte Jobs)
|
|
function manageLicensesMenu()
|
|
-- Hier würde die Verwaltung für das Entziehen/Wiederherstellen von Lizenzen implementiert
|
|
-- Ähnlich wie die anderen Menüs, aber mit Suchfunktion nach Spielern
|
|
lib.notify({
|
|
title = 'Lizenz-System',
|
|
description = 'Lizenz-Verwaltung wird implementiert...',
|
|
type = 'info'
|
|
})
|
|
end
|
|
|
|
-- Foto vom Spieler machen
|
|
RegisterNetEvent('license-system:client:takePlayerPhoto', function(targetId)
|
|
local targetPed = GetPlayerPed(GetPlayerFromServerId(targetId))
|
|
|
|
if targetPed and targetPed ~= 0 then
|
|
-- Mugshot erstellen
|
|
local mugshot = RegisterPedheadshot(targetPed)
|
|
|
|
-- Warten bis Mugshot geladen ist
|
|
while not IsPedheadshotReady(mugshot) do
|
|
Wait(100)
|
|
end
|
|
|
|
-- Mugshot-Textur holen
|
|
local mugshotTxd = GetPedheadshotTxdString(mugshot)
|
|
|
|
-- An Server senden
|
|
TriggerServerEvent('license-system:server:savePlayerPhoto', QBCore.Functions.GetPlayerData().citizenid, mugshotTxd)
|
|
|
|
-- Mugshot wieder freigeben
|
|
UnregisterPedheadshot(mugshot)
|
|
end
|
|
end)
|
|
|