forked from Simnation/Main
ed
This commit is contained in:
parent
354019affc
commit
7932af55cb
3 changed files with 1311 additions and 715 deletions
|
@ -1,416 +1,595 @@
|
|||
local QBCore = exports['qb-core']:GetCoreObject()
|
||||
local playerLicenses = {}
|
||||
|
||||
-- Lokale Variablen
|
||||
local isMenuOpen = false
|
||||
local currentTarget = nil
|
||||
local nearbyPlayers = {}
|
||||
|
||||
-- Keybind registrieren
|
||||
RegisterKeyMapping(Config.Command, 'Lizenz-Menü öffnen', 'keyboard', Config.OpenKey)
|
||||
-- Hilfsfunktionen
|
||||
local function debugPrint(message)
|
||||
if Config.Debug then
|
||||
print("^3[License-System Client] " .. message .. "^7")
|
||||
end
|
||||
end
|
||||
|
||||
-- Events
|
||||
RegisterNetEvent('license-system:client:openMenu', function()
|
||||
TriggerServerEvent('license-system:server:getLicenses')
|
||||
end)
|
||||
local function safeCallback(cb, ...)
|
||||
if cb and type(cb) == "function" then
|
||||
cb(...)
|
||||
else
|
||||
debugPrint("^1Callback ist keine Funktion!^7")
|
||||
end
|
||||
end
|
||||
|
||||
RegisterNetEvent('license-system:client:receiveLicenses', function(licenses)
|
||||
playerLicenses = licenses
|
||||
openMainMenu()
|
||||
end)
|
||||
local function showNotification(message, type)
|
||||
QBCore.Functions.Notify(message, type or 'primary')
|
||||
end
|
||||
|
||||
RegisterNetEvent('license-system:client:receiveNearbyPlayers', function(players)
|
||||
nearbyPlayers = {}
|
||||
-- Nearby Players abrufen
|
||||
local function getNearbyPlayers(radius)
|
||||
radius = radius or 5.0
|
||||
local players = {}
|
||||
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)
|
||||
for _, playerId in ipairs(GetActivePlayers()) do
|
||||
local targetPed = GetPlayerPed(playerId)
|
||||
if targetPed ~= playerPed then
|
||||
local targetCoords = GetEntityCoords(targetPed)
|
||||
local distance = #(playerCoords - targetCoords)
|
||||
|
||||
if distance <= radius then
|
||||
local serverId = GetPlayerServerId(playerId)
|
||||
local playerName = GetPlayerName(playerId)
|
||||
|
||||
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
|
||||
table.insert(players, {
|
||||
id = serverId,
|
||||
name = playerName,
|
||||
distance = math.floor(distance * 100) / 100,
|
||||
ped = targetPed
|
||||
})
|
||||
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')
|
||||
-- Nach Entfernung sortieren
|
||||
table.sort(players, function(a, b)
|
||||
return a.distance < b.distance
|
||||
end)
|
||||
|
||||
return players
|
||||
end
|
||||
|
||||
-- Lizenz ausstellen
|
||||
function issueLicenseMenu()
|
||||
-- Berechtigung prüfen
|
||||
local function hasPermission()
|
||||
local PlayerData = QBCore.Functions.GetPlayerData()
|
||||
local authorizedLicenses = Config.AuthorizedJobs[PlayerData.job.name].canIssue
|
||||
if not PlayerData or not PlayerData.job then return false end
|
||||
|
||||
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')
|
||||
return Config.AuthorizedJobs[PlayerData.job.name] or false
|
||||
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'
|
||||
})
|
||||
-- Lizenz anzeigen
|
||||
local function showLicense(licenseData)
|
||||
if not licenseData then
|
||||
showNotification(Config.Notifications.license_not_found.message, Config.Notifications.license_not_found.type)
|
||||
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)
|
||||
debugPrint("Zeige Lizenz: " .. licenseData.license.license_type)
|
||||
|
||||
SendNUIMessage({
|
||||
action = 'showLicense',
|
||||
data = {
|
||||
license = licenseData,
|
||||
config = licenseConfig,
|
||||
issuer = issuerName
|
||||
data = licenseData
|
||||
})
|
||||
|
||||
SetNuiFocus(true, true)
|
||||
isMenuOpen = true
|
||||
end
|
||||
|
||||
-- Lizenz schließen
|
||||
local function closeLicense()
|
||||
SendNUIMessage({
|
||||
action = 'hideLicense'
|
||||
})
|
||||
|
||||
SetNuiFocus(false, false)
|
||||
isMenuOpen = false
|
||||
debugPrint("Lizenz geschlossen")
|
||||
end
|
||||
|
||||
-- Spieler-Lizenz-Menü
|
||||
local function openPlayerLicenseMenu(targetId, targetName)
|
||||
debugPrint("Öffne Lizenz-Menü für Spieler: " .. targetName)
|
||||
|
||||
QBCore.Functions.TriggerCallback('license-system:server:getPlayerLicenses', function(licenses)
|
||||
local menuOptions = {}
|
||||
|
||||
if licenses and #licenses > 0 then
|
||||
for _, license in ipairs(licenses) do
|
||||
local licenseConfig = Config.LicenseTypes[license.license_type] or {
|
||||
label = license.license_type,
|
||||
icon = 'fas fa-id-card'
|
||||
}
|
||||
|
||||
local statusIcon = license.is_active and '✅' or '❌'
|
||||
local statusText = license.is_active and 'Gültig' or 'Ungültig'
|
||||
local expireText = license.expire_date or 'Unbegrenzt'
|
||||
|
||||
table.insert(menuOptions, {
|
||||
title = licenseConfig.label,
|
||||
description = 'Status: ' .. statusText .. ' | Gültig bis: ' .. expireText,
|
||||
icon = licenseConfig.icon,
|
||||
onSelect = function()
|
||||
-- Lizenz anzeigen
|
||||
local licenseData = {
|
||||
license = license,
|
||||
config = licenseConfig
|
||||
}
|
||||
showLicense(licenseData)
|
||||
end,
|
||||
metadata = {
|
||||
{label = 'Status', value = statusText},
|
||||
{label = 'Ausgestellt', value = license.issue_date or 'Unbekannt'},
|
||||
{label = 'Gültig bis', value = expireText},
|
||||
{label = 'Aussteller', value = license.issued_by_name or 'System'}
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
-- Aktionen hinzufügen
|
||||
table.insert(menuOptions, {
|
||||
title = '─────────────────',
|
||||
disabled = true
|
||||
})
|
||||
|
||||
-- Neue Lizenz ausstellen
|
||||
table.insert(menuOptions, {
|
||||
title = 'Neue Lizenz ausstellen',
|
||||
description = 'Eine neue Lizenz für diesen Spieler ausstellen',
|
||||
icon = 'fas fa-plus',
|
||||
onSelect = function()
|
||||
openIssueLicenseMenu(targetId, targetName)
|
||||
end
|
||||
})
|
||||
|
||||
-- Lizenz entziehen
|
||||
table.insert(menuOptions, {
|
||||
title = 'Lizenz entziehen',
|
||||
description = 'Eine bestehende Lizenz entziehen',
|
||||
icon = 'fas fa-minus',
|
||||
onSelect = function()
|
||||
openRevokeLicenseMenu(targetId, targetName, licenses)
|
||||
end
|
||||
})
|
||||
|
||||
else
|
||||
table.insert(menuOptions, {
|
||||
title = 'Keine Lizenzen gefunden',
|
||||
description = 'Dieser Spieler hat keine Lizenzen',
|
||||
icon = 'fas fa-exclamation-triangle',
|
||||
disabled = true
|
||||
})
|
||||
|
||||
table.insert(menuOptions, {
|
||||
title = 'Neue Lizenz ausstellen',
|
||||
description = 'Eine neue Lizenz für diesen Spieler ausstellen',
|
||||
icon = 'fas fa-plus',
|
||||
onSelect = function()
|
||||
openIssueLicenseMenu(targetId, targetName)
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
-- Zurück-Option
|
||||
table.insert(menuOptions, {
|
||||
title = '← Zurück',
|
||||
icon = 'fas fa-arrow-left',
|
||||
onSelect = function()
|
||||
openLicenseMenu()
|
||||
end
|
||||
})
|
||||
|
||||
lib.registerContext({
|
||||
id = 'player_licenses',
|
||||
title = 'Lizenzen: ' .. targetName,
|
||||
options = menuOptions
|
||||
})
|
||||
|
||||
lib.showContext('player_licenses')
|
||||
|
||||
end, targetId)
|
||||
end
|
||||
|
||||
-- Lizenz ausstellen Menü
|
||||
local function openIssueLicenseMenu(targetId, targetName)
|
||||
local menuOptions = {}
|
||||
|
||||
for licenseType, config in pairs(Config.LicenseTypes) do
|
||||
table.insert(menuOptions, {
|
||||
title = config.label,
|
||||
description = config.description or 'Keine Beschreibung verfügbar',
|
||||
icon = config.icon,
|
||||
onSelect = function()
|
||||
if licenseType == 'drivers_license' and config.classes then
|
||||
openDriversLicenseClassMenu(targetId, targetName, licenseType)
|
||||
else
|
||||
confirmIssueLicense(targetId, targetName, licenseType, nil)
|
||||
end
|
||||
end,
|
||||
metadata = {
|
||||
{label = 'Preis', value = config.price .. ' $'},
|
||||
{label = 'Gültigkeitsdauer', value = config.validity_days and (config.validity_days .. ' Tage') or 'Unbegrenzt'}
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
table.insert(menuOptions, {
|
||||
title = '← Zurück',
|
||||
icon = 'fas fa-arrow-left',
|
||||
onSelect = function()
|
||||
openPlayerLicenseMenu(targetId, targetName)
|
||||
end
|
||||
})
|
||||
|
||||
lib.registerContext({
|
||||
id = 'issue_license',
|
||||
title = 'Lizenz ausstellen: ' .. targetName,
|
||||
options = menuOptions
|
||||
})
|
||||
|
||||
lib.showContext('issue_license')
|
||||
end
|
||||
|
||||
-- Führerschein-Klassen Menü
|
||||
local function openDriversLicenseClassMenu(targetId, targetName, licenseType)
|
||||
local config = Config.LicenseTypes[licenseType]
|
||||
local selectedClasses = {}
|
||||
|
||||
local function updateMenu()
|
||||
local menuOptions = {}
|
||||
|
||||
for _, class in ipairs(config.classes) do
|
||||
local isSelected = false
|
||||
for _, selected in ipairs(selectedClasses) do
|
||||
if selected == class then
|
||||
isSelected = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
local classDescriptions = {
|
||||
['A'] = 'Motorräder',
|
||||
['A1'] = 'Leichte Motorräder (bis 125ccm)',
|
||||
['A2'] = 'Mittlere Motorräder (bis 35kW)',
|
||||
['B'] = 'PKW (bis 3,5t)',
|
||||
['BE'] = 'PKW mit Anhänger',
|
||||
['C'] = 'LKW (über 3,5t)',
|
||||
['CE'] = 'LKW mit Anhänger',
|
||||
['D'] = 'Bus (über 8 Personen)',
|
||||
['DE'] = 'Bus mit Anhänger'
|
||||
}
|
||||
|
||||
table.insert(menuOptions, {
|
||||
title = 'Klasse ' .. class .. (isSelected and ' ✅' or ''),
|
||||
description = classDescriptions[class] or 'Keine Beschreibung',
|
||||
icon = isSelected and 'fas fa-check-square' or 'far fa-square',
|
||||
onSelect = function()
|
||||
if isSelected then
|
||||
-- Klasse entfernen
|
||||
for i, selected in ipairs(selectedClasses) do
|
||||
if selected == class then
|
||||
table.remove(selectedClasses, i)
|
||||
break
|
||||
end
|
||||
end
|
||||
else
|
||||
-- Klasse hinzufügen
|
||||
table.insert(selectedClasses, class)
|
||||
end
|
||||
updateMenu()
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
table.insert(menuOptions, {
|
||||
title = '─────────────────',
|
||||
disabled = true
|
||||
})
|
||||
|
||||
table.insert(menuOptions, {
|
||||
title = 'Bestätigen (' .. #selectedClasses .. ' Klassen)',
|
||||
description = 'Führerschein mit ausgewählten Klassen ausstellen',
|
||||
icon = 'fas fa-check',
|
||||
disabled = #selectedClasses == 0,
|
||||
onSelect = function()
|
||||
confirmIssueLicense(targetId, targetName, licenseType, selectedClasses)
|
||||
end
|
||||
})
|
||||
|
||||
table.insert(menuOptions, {
|
||||
title = '← Zurück',
|
||||
icon = 'fas fa-arrow-left',
|
||||
onSelect = function()
|
||||
openIssueLicenseMenu(targetId, targetName)
|
||||
end
|
||||
})
|
||||
|
||||
lib.registerContext({
|
||||
id = 'drivers_license_classes',
|
||||
title = 'Führerschein-Klassen: ' .. targetName,
|
||||
options = menuOptions
|
||||
})
|
||||
|
||||
lib.showContext('drivers_license_classes')
|
||||
end
|
||||
|
||||
updateMenu()
|
||||
end
|
||||
|
||||
-- Lizenz-Ausstellung bestätigen
|
||||
local function confirmIssueLicense(targetId, targetName, licenseType, classes)
|
||||
local config = Config.LicenseTypes[licenseType]
|
||||
local classText = classes and table.concat(classes, ', ') or 'Keine'
|
||||
|
||||
lib.registerContext({
|
||||
id = 'confirm_issue_license',
|
||||
title = 'Lizenz ausstellen bestätigen',
|
||||
options = {
|
||||
{
|
||||
title = 'Spieler: ' .. targetName,
|
||||
disabled = true
|
||||
},
|
||||
{
|
||||
title = 'Lizenztyp: ' .. config.label,
|
||||
disabled = true
|
||||
},
|
||||
{
|
||||
title = 'Klassen: ' .. classText,
|
||||
disabled = true
|
||||
},
|
||||
{
|
||||
title = 'Kosten: ' .. config.price .. ' $',
|
||||
disabled = true
|
||||
},
|
||||
{
|
||||
title = '─────────────────',
|
||||
disabled = true
|
||||
},
|
||||
{
|
||||
title = '✅ Bestätigen',
|
||||
description = 'Lizenz jetzt ausstellen',
|
||||
icon = 'fas fa-check',
|
||||
onSelect = function()
|
||||
TriggerServerEvent('license-system:server:issueLicense', targetId, licenseType, classes)
|
||||
lib.hideContext()
|
||||
end
|
||||
},
|
||||
{
|
||||
title = '❌ Abbrechen',
|
||||
description = 'Vorgang abbrechen',
|
||||
icon = 'fas fa-times',
|
||||
onSelect = function()
|
||||
openIssueLicenseMenu(targetId, targetName)
|
||||
end
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
lib.showContext('confirm_issue_license')
|
||||
end
|
||||
|
||||
-- Lizenz entziehen Menü
|
||||
local function openRevokeLicenseMenu(targetId, targetName, licenses)
|
||||
local menuOptions = {}
|
||||
|
||||
for _, license in ipairs(licenses) do
|
||||
if license.is_active then
|
||||
local config = Config.LicenseTypes[license.license_type] or {
|
||||
label = license.license_type,
|
||||
icon = 'fas fa-id-card'
|
||||
}
|
||||
|
||||
table.insert(menuOptions, {
|
||||
title = config.label,
|
||||
description = 'Diese Lizenz entziehen',
|
||||
icon = config.icon,
|
||||
onSelect = function()
|
||||
lib.registerContext({
|
||||
id = 'confirm_revoke_license',
|
||||
title = 'Lizenz entziehen bestätigen',
|
||||
options = {
|
||||
{
|
||||
title = 'Spieler: ' .. targetName,
|
||||
disabled = true
|
||||
},
|
||||
{
|
||||
title = 'Lizenztyp: ' .. config.label,
|
||||
disabled = true
|
||||
},
|
||||
{
|
||||
title = '─────────────────',
|
||||
disabled = true
|
||||
},
|
||||
{
|
||||
title = '✅ Bestätigen',
|
||||
description = 'Lizenz jetzt entziehen',
|
||||
icon = 'fas fa-check',
|
||||
onSelect = function()
|
||||
TriggerServerEvent('license-system:server:revokeLicense', targetId, license.license_type)
|
||||
lib.hideContext()
|
||||
end
|
||||
},
|
||||
{
|
||||
title = '❌ Abbrechen',
|
||||
description = 'Vorgang abbrechen',
|
||||
icon = 'fas fa-times',
|
||||
onSelect = function()
|
||||
openRevokeLicenseMenu(targetId, targetName, licenses)
|
||||
end
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
lib.showContext('confirm_revoke_license')
|
||||
end
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
if #menuOptions == 0 then
|
||||
table.insert(menuOptions, {
|
||||
title = 'Keine aktiven Lizenzen',
|
||||
description = 'Dieser Spieler hat keine aktiven Lizenzen',
|
||||
icon = 'fas fa-exclamation-triangle',
|
||||
disabled = true
|
||||
})
|
||||
end
|
||||
|
||||
table.insert(menuOptions, {
|
||||
title = '← Zurück',
|
||||
icon = 'fas fa-arrow-left',
|
||||
onSelect = function()
|
||||
openPlayerLicenseMenu(targetId, targetName)
|
||||
end
|
||||
})
|
||||
|
||||
lib.registerContext({
|
||||
id = 'revoke_license',
|
||||
title = 'Lizenz entziehen: ' .. targetName,
|
||||
options = menuOptions
|
||||
})
|
||||
|
||||
lib.showContext('revoke_license')
|
||||
end
|
||||
|
||||
-- Hauptmenü für Lizenz-System
|
||||
local function openLicenseMenu()
|
||||
if not hasPermission() then
|
||||
showNotification(Config.Notifications.no_permission.message, Config.Notifications.no_permission.type)
|
||||
return
|
||||
end
|
||||
|
||||
nearbyPlayers = getNearbyPlayers(5.0)
|
||||
|
||||
if #nearbyPlayers == 0 then
|
||||
showNotification(Config.Notifications.no_players_nearby.message, Config.Notifications.no_players_nearby.type)
|
||||
return
|
||||
end
|
||||
|
||||
local menuOptions = {}
|
||||
|
||||
for _, player in ipairs(nearbyPlayers) do
|
||||
table.insert(menuOptions, {
|
||||
title = player.name,
|
||||
description = 'Entfernung: ' .. player.distance .. 'm',
|
||||
icon = 'fas fa-user',
|
||||
onSelect = function()
|
||||
openPlayerLicenseMenu(player.id, player.name)
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
lib.registerContext({
|
||||
id = 'license_nearby_players',
|
||||
title = 'Spieler in der Nähe (' .. #nearbyPlayers .. ')',
|
||||
options = menuOptions
|
||||
})
|
||||
|
||||
lib.showContext('license_nearby_players')
|
||||
end
|
||||
|
||||
-- Eigene Lizenzen anzeigen
|
||||
local function showMyLicenses()
|
||||
local menuOptions = {}
|
||||
|
||||
for licenseType, config in pairs(Config.LicenseTypes) do
|
||||
table.insert(menuOptions, {
|
||||
title = config.label,
|
||||
description = 'Deine ' .. config.label .. ' anzeigen',
|
||||
icon = config.icon,
|
||||
onSelect = function()
|
||||
QBCore.Functions.TriggerCallback('license-system:server:getMyLicense', function(licenseData)
|
||||
if licenseData then
|
||||
showLicense(licenseData)
|
||||
else
|
||||
showNotification('Du hast keine ' .. config.label .. '!', 'error')
|
||||
end
|
||||
end, licenseType)
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
lib.registerContext({
|
||||
id = 'my_licenses',
|
||||
title = 'Meine Lizenzen',
|
||||
options = menuOptions
|
||||
})
|
||||
|
||||
lib.showContext('my_licenses')
|
||||
end
|
||||
|
||||
-- Events
|
||||
RegisterNetEvent('license-system:client:showLicense', function(targetId)
|
||||
QBCore.Functions.TriggerCallback('license-system:server:getLicense', function(licenseData)
|
||||
showLicense(licenseData)
|
||||
end, targetId)
|
||||
end)
|
||||
|
||||
RegisterNetEvent('license-system:client:showMyLicense', function(licenseType)
|
||||
QBCore.Functions.TriggerCallback('license-system:server:getMyLicense', function(licenseData)
|
||||
showLicense(licenseData)
|
||||
end, licenseType)
|
||||
end)
|
||||
|
||||
RegisterNetEvent('license-system:client:openCamera', function()
|
||||
SendNUIMessage({
|
||||
action = 'openCamera'
|
||||
})
|
||||
end)
|
||||
|
||||
-- NUI Callbacks
|
||||
RegisterNUICallback('closeLicense', function(data, cb)
|
||||
SetNuiFocus(false, false)
|
||||
cb('ok')
|
||||
closeLicense()
|
||||
safeCallback(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)
|
||||
RegisterNUICallback('savePhoto', function(data, cb)
|
||||
if data.photo and data.citizenid then
|
||||
TriggerServerEvent('license-system:server:savePhoto', data.citizenid, data.photo)
|
||||
safeCallback(cb, 'ok')
|
||||
else
|
||||
safeCallback(cb, 'error')
|
||||
end
|
||||
end)
|
||||
|
||||
-- Commands
|
||||
RegisterCommand(Config.Commands.license.name, function()
|
||||
openLicenseMenu()
|
||||
end, Config.Commands.license.restricted)
|
||||
|
||||
RegisterCommand(Config.Commands.mylicense.name, function()
|
||||
showMyLicenses()
|
||||
end, Config.Commands.mylicense.restricted)
|
||||
|
||||
-- Keybinds
|
||||
if Config.Keybinds.open_license_menu then
|
||||
RegisterKeyMapping(Config.Commands.license.name, Config.Keybinds.open_license_menu.description, 'keyboard', Config.Keybinds.open_license_menu.key)
|
||||
end
|
||||
|
||||
if Config.Keybinds.show_my_licenses then
|
||||
RegisterKeyMapping(Config.Commands.mylicense.name, Config.Keybinds.show_my_licenses.description, 'keyboard', Config.Keybinds.show_my_licenses.key)
|
||||
end
|
||||
|
||||
-- Cleanup
|
||||
AddEventHandler('onResourceStop', function(resourceName)
|
||||
if GetCurrentResourceName() == resourceName then
|
||||
if isMenuOpen then
|
||||
closeLicense()
|
||||
end
|
||||
debugPrint("License-System Client gestoppt")
|
||||
end
|
||||
end)
|
||||
|
||||
-- Initialisierung
|
||||
CreateThread(function()
|
||||
debugPrint("License-System Client gestartet")
|
||||
end)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue