-- ───────────────────────────────────────────────────────────────────────────── -- Bridge – ESX Legacy -- Nur aktiv, wenn Config.Framework == "esx" -- -- Angepasst an ESX Legacy 1.13+. Drei Dinge waren gegen aeltere ESX-Staende -- geschrieben und haetten hier nicht funktioniert: -- -- 1. Clientseitig wurde das Objekt ueber TriggerEvent('esx:getSharedObject') -- geholt. Dieses Event gibt es in ESX Legacy nicht mehr; ESX waere -- dauerhaft nil geblieben und der PC haette weder Namen noch Identifier -- gehabt. Richtig ist der Export. -- 2. Benachrichtigungen liefen ueber 'ESX:ShowNotification'. Das Event heisst -- 'esx:showNotification' (klein) – der Aufruf ging ins Leere. Serverseitig -- gibt es dafuer ohnehin xPlayer.showNotification. -- 3. HasPermission verglich die Gruppe auf Gleichheit, konnte also immer nur -- genau eine Gruppe zulassen. Jetzt sind Listen moeglich. -- ───────────────────────────────────────────────────────────────────────────── if not Bridge then Bridge = {} end if Config.Framework ~= "esx" then return end -- ESX erst bei Bedarf holen, nicht beim Laden der Datei. -- Beim Start ist es je nach Reihenfolge noch nicht bereit; ein einmal -- fehlgeschlagener Versuch haette die Bridge dauerhaft lahmgelegt. local ESX local function esx() if ESX then return ESX end local ok, obj = pcall(function() return exports['es_extended']:getSharedObject() end) if ok and obj then ESX = obj end return ESX end if IsDuplicityVersion() then -- ── SERVER ──────────────────────────────────────────────────────────────── local function player(source) local api = esx() return api and api.GetPlayerFromId(source) or nil end function Bridge.GetIdentifier(source) local xPlayer = player(source) if not xPlayer then return tostring(source) end return xPlayer.identifier end function Bridge.GetName(source) local xPlayer = player(source) if not xPlayer then return "Unknown" end if xPlayer.getName then return xPlayer.getName() end return xPlayer.name or "Unknown" end function Bridge.Notify(source, message, notifType) local xPlayer = player(source) if xPlayer and xPlayer.showNotification then xPlayer.showNotification(message, notifType) return end -- Rueckfall, falls der Spieler (noch) nicht geladen ist. TriggerClientEvent('esx:showNotification', source, message, notifType) end -- perm darf ein einzelner Gruppenname oder eine Liste sein. -- Vorher war nur Gleichheit moeglich, also genau eine erlaubte Gruppe. function Bridge.HasPermission(source, perm) local xPlayer = player(source) if not xPlayer or not xPlayer.getGroup then return false end local group = xPlayer.getGroup() if not group then return false end if type(perm) == "table" then -- Beide Schreibweisen: Liste { 'admin', 'superadmin' } -- und Menge { admin = true, superadmin = true }. if perm[group] == true then return true end for _, allowed in ipairs(perm) do if allowed == group then return true end end return false end return group == perm end function Bridge.GetMoney(source, moneyType) local xPlayer = player(source) if not xPlayer then return 0 end if moneyType == "cash" or moneyType == "money" then return xPlayer.getMoney() end local account = xPlayer.getAccount(moneyType) return account and account.money or 0 end function Bridge.RemoveMoney(source, moneyType, amount) local xPlayer = player(source) if not xPlayer then return false end amount = tonumber(amount) or 0 if amount <= 0 then return false end -- Deckung pruefen: ohne das erzeugt ESX negative Kontostaende. if Bridge.GetMoney(source, moneyType) < amount then return false end if moneyType == "cash" or moneyType == "money" then xPlayer.removeMoney(amount) else xPlayer.removeAccountMoney(moneyType, amount) end return true end function Bridge.AddMoney(source, moneyType, amount) local xPlayer = player(source) if not xPlayer then return false end amount = tonumber(amount) or 0 if amount <= 0 then return false end if moneyType == "cash" or moneyType == "money" then xPlayer.addMoney(amount) else xPlayer.addAccountMoney(moneyType, amount) end return true end function Bridge.GetJob(source) local xPlayer = player(source) if not xPlayer then return nil end return xPlayer.job and xPlayer.job.name or nil end -- Firmenzugehoerigkeit. -- -- Im Ursprungssystem war das eine numerische Firmen-ID aus einer eigenen -- Tabelle. ESX kennt so etwas nicht – dort ist die Zugehoerigkeit der Job. -- Ueber Config.CompanyJobs laesst sich eine ID auf einen ESX-Job abbilden; -- ohne Eintrag gibt es keine Zugehoerigkeit, statt sie zu erfinden. function Bridge.IsCompanyEmployee(source, companyId) if not companyId then return false end local map = Config.CompanyJobs or {} local wanted = map[companyId] or map[tostring(companyId)] if not wanted then return false end local job = Bridge.GetJob(source) return job ~= nil and job == wanted end else -- ── CLIENT ──────────────────────────────────────────────────────────────── function Bridge.GetLocalIdentifier() local api = esx() local data = api and api.GetPlayerData() return (data and data.identifier) or "" end function Bridge.GetLocalName() local api = esx() local data = api and api.GetPlayerData() if not data then return "Unknown" end -- ESX Legacy fuehrt den Namen je nach Aufbau unterschiedlich. if data.name and data.name ~= "" then return data.name end if data.firstName then return ("%s %s"):format(data.firstName, data.lastName or ""):gsub("%s+$", "") end return GetPlayerName(PlayerId()) or "Unknown" end -- pc-live sendet Benachrichtigungen teils ueber ein eigenes Event. -- Auf ESX wird daraus eine ESX-Notification. RegisterNetEvent('pc-live:notification', function(message, notifType) local api = esx() if api and api.ShowNotification then api.ShowNotification(message, notifType) else SetNotificationTextEntry("STRING") AddTextComponentString(tostring(message)) DrawNotification(false, true) end end) end