mirror of
https://github.com/ND-Framework/ND_Core.git
synced 2026-08-17 05:56:01 +01:00
feat: esx backwards compatibility
This commit is contained in:
@@ -8,6 +8,7 @@ NDCore.Streaming = {}
|
|||||||
NDCore.UI = {}
|
NDCore.UI = {}
|
||||||
NDCore.UI.HUD = {}
|
NDCore.UI.HUD = {}
|
||||||
NDCore.UI.Menu = {}
|
NDCore.UI.Menu = {}
|
||||||
|
NDCore.PlayerData = {}
|
||||||
|
|
||||||
local uiMetatable = {
|
local uiMetatable = {
|
||||||
__index = function(table, key)
|
__index = function(table, key)
|
||||||
@@ -35,6 +36,7 @@ end)
|
|||||||
|
|
||||||
function NDCore.GetPlayerData()
|
function NDCore.GetPlayerData()
|
||||||
local player = NDCore.getPlayer()
|
local player = NDCore.getPlayer()
|
||||||
|
if not player then return {} end
|
||||||
|
|
||||||
player.Accounts = {
|
player.Accounts = {
|
||||||
Bank = player.bank,
|
Bank = player.bank,
|
||||||
@@ -42,7 +44,31 @@ function NDCore.GetPlayerData()
|
|||||||
Black = player.Cash
|
Black = player.Cash
|
||||||
}
|
}
|
||||||
|
|
||||||
-- add more here
|
if player.jobInfo then
|
||||||
|
player.job = {
|
||||||
|
id = player.job,
|
||||||
|
name = player.job,
|
||||||
|
label = player.jobInfo.label,
|
||||||
|
grade = player.jobInfo.rank,
|
||||||
|
grade_name = player.jobInfo.rankName,
|
||||||
|
grade_label = player.jobInfo.rankName,
|
||||||
|
grade_salary = 0,
|
||||||
|
skin_male = {},
|
||||||
|
skin_female = {}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
player.coords = GetEntityCoords(cache.ped)
|
||||||
|
player.loadout = {}
|
||||||
|
player.maxWeight = exports.ox_inventory:GetPlayerMaxWeight()
|
||||||
|
player.money = player.Accounts.Money
|
||||||
|
player.sex = player.gender
|
||||||
|
player.firstName = player.firstname
|
||||||
|
player.lastName = player.lastname
|
||||||
|
player.dateofbirth = player.dob
|
||||||
|
player.height = 120
|
||||||
|
player.dead = LocalPlayer.state.dead or false
|
||||||
|
NDCore.PlayerData = player
|
||||||
|
|
||||||
return player
|
return player
|
||||||
end
|
end
|
||||||
@@ -62,7 +88,7 @@ function NDCore.Progressbar(message, lenght, options)
|
|||||||
newOptions.anim = {}
|
newOptions.anim = {}
|
||||||
if options.animation.type == "anim" then
|
if options.animation.type == "anim" then
|
||||||
if options.animation.dict then
|
if options.animation.dict then
|
||||||
newOptions.anim.dict = options.animation.dict,
|
newOptions.anim.dict = options.animation.dict
|
||||||
end
|
end
|
||||||
if options.animation.lib then
|
if options.animation.lib then
|
||||||
newOptions.anim.clip = options.animation.lib
|
newOptions.anim.clip = options.animation.lib
|
||||||
@@ -319,11 +345,9 @@ function NDCore.Game.SpawnLocalObject(model, coords, cb)
|
|||||||
end
|
end
|
||||||
local entity = CreateObject(model, coords.x, coords.y, coords.z, false, false, false)
|
local entity = CreateObject(model, coords.x, coords.y, coords.z, false, false, false)
|
||||||
entity = lib.waitFor(function()
|
entity = lib.waitFor(function()
|
||||||
if DoesEntityExist(entity) end
|
if DoesEntityExist(entity) then return entity end
|
||||||
end)
|
end)
|
||||||
if cb then
|
if cb then cb(entity) end
|
||||||
cb(entity)
|
|
||||||
end
|
|
||||||
return entity
|
return entity
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -333,11 +357,9 @@ function NDCore.Game.SpawnLocalVehicle(model, coords, heading, cb)
|
|||||||
end
|
end
|
||||||
local entity = CreateVehicle(model, coords.x, coords.y, coords.z, heading, false, false, false)
|
local entity = CreateVehicle(model, coords.x, coords.y, coords.z, heading, false, false, false)
|
||||||
entity = lib.waitFor(function()
|
entity = lib.waitFor(function()
|
||||||
if DoesEntityExist(entity) end
|
if DoesEntityExist(entity) then return entity end
|
||||||
end)
|
end)
|
||||||
if cb then
|
if cb then cb(entity) end
|
||||||
cb(entity)
|
|
||||||
end
|
|
||||||
return entity
|
return entity
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -347,11 +369,9 @@ function NDCore.Game.SpawnObject(model, coords, cb)
|
|||||||
end
|
end
|
||||||
local entity = CreateObject(model, coords.x, coords.y, coords.z, true, false, false)
|
local entity = CreateObject(model, coords.x, coords.y, coords.z, true, false, false)
|
||||||
entity = lib.waitFor(function()
|
entity = lib.waitFor(function()
|
||||||
if DoesEntityExist(entity) end
|
if DoesEntityExist(entity) then return entity end
|
||||||
end)
|
end)
|
||||||
if cb then
|
if cb then cb(entity) end
|
||||||
cb(entity)
|
|
||||||
end
|
|
||||||
return entity
|
return entity
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -361,11 +381,9 @@ function NDCore.Game.SpawnVehicle(model, coords, heading, cb)
|
|||||||
end
|
end
|
||||||
local entity = CreateVehicle(model, coords.x, coords.y, coords.z, heading, true, false, false)
|
local entity = CreateVehicle(model, coords.x, coords.y, coords.z, heading, true, false, false)
|
||||||
entity = lib.waitFor(function()
|
entity = lib.waitFor(function()
|
||||||
if DoesEntityExist(entity) end
|
if DoesEntityExist(entity) then return entity end
|
||||||
end)
|
end)
|
||||||
if cb then
|
if cb then cb(entity) end
|
||||||
cb(entity)
|
|
||||||
end
|
|
||||||
return entity
|
return entity
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -384,3 +402,11 @@ function NDCore.Game.Teleport(entity, coords, cb)
|
|||||||
cb()
|
cb()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
AddEventHandler("ND:characterLoaded", function()
|
||||||
|
NDCore.GetPlayerData()
|
||||||
|
end)
|
||||||
|
|
||||||
|
AddEventHandler("ND:updateCharacter", function()
|
||||||
|
NDCore.GetPlayerData()
|
||||||
|
end)
|
||||||
|
|||||||
29
compatibility/esx/locale.lua
Normal file
29
compatibility/esx/locale.lua
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
local config_locale = "en"
|
||||||
|
Locales = {}
|
||||||
|
|
||||||
|
function Translate(str, ...) -- Translate string
|
||||||
|
if not str then
|
||||||
|
print(("[^1ERROR^7] Resource ^5%s^7 You did not specify a parameter for the Translate function or the value is nil!"):format(GetInvokingResource() or GetCurrentResourceName()))
|
||||||
|
return 'Given translate function parameter is nil!'
|
||||||
|
end
|
||||||
|
if Locales[config_locale] then
|
||||||
|
if Locales[config_locale][str] then
|
||||||
|
return string.format(Locales[config_locale][str], ...)
|
||||||
|
elseif config_locale ~= 'en' and Locales['en'] and Locales['en'][str] then
|
||||||
|
return string.format(Locales['en'][str], ...)
|
||||||
|
else
|
||||||
|
return 'Translation [' .. config_locale .. '][' .. str .. '] does not exist'
|
||||||
|
end
|
||||||
|
elseif config_locale ~= 'en' and Locales['en'] and Locales['en'][str] then
|
||||||
|
return string.format(Locales['en'][str], ...)
|
||||||
|
else
|
||||||
|
return 'Locale [' .. config_locale .. '] does not exist'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function TranslateCap(str, ...) -- Translate string first char uppercase
|
||||||
|
return _(str, ...):gsub("^%l", string.upper)
|
||||||
|
end
|
||||||
|
|
||||||
|
_ = Translate
|
||||||
|
_U = TranslateCap
|
||||||
@@ -4,14 +4,50 @@ local itemNames
|
|||||||
local registeredItems = {}
|
local registeredItems = {}
|
||||||
|
|
||||||
local function getAmmoFromWeapon(weapon)
|
local function getAmmoFromWeapon(weapon)
|
||||||
|
if not weapon then return end
|
||||||
for item, data in pairs(exports.ox_inventory:Items()) do
|
for item, data in pairs(exports.ox_inventory:Items()) do
|
||||||
if data.weapon and data.model:lower() == weapon:lower then
|
if data.weapon and data.model and data.model:lower() == weapon:lower() then
|
||||||
return data.ammoname
|
return data.ammoname
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function createPlayerFunctions(self)
|
local function createPlayerFunctions(self)
|
||||||
|
self.Accounts = {
|
||||||
|
Bank = self.bank,
|
||||||
|
Money = self.Cash,
|
||||||
|
Black = self.Cash
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.jobInfo then
|
||||||
|
self.job = {
|
||||||
|
id = self.job,
|
||||||
|
name = self.job,
|
||||||
|
label = self.jobInfo.label,
|
||||||
|
grade = self.jobInfo.rank,
|
||||||
|
grade_name = self.jobInfo.rankName,
|
||||||
|
grade_label = self.jobInfo.rankName,
|
||||||
|
grade_salary = 0,
|
||||||
|
skin_male = {},
|
||||||
|
skin_female = {}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
local ped = GetPlayerPed(self.source)
|
||||||
|
if DoesEntityExist(ped) then
|
||||||
|
self.coords = GetEntityCoords()
|
||||||
|
end
|
||||||
|
|
||||||
|
self.loadout = {}
|
||||||
|
self.maxWeight = 30000
|
||||||
|
self.money = self.Accounts.Money
|
||||||
|
self.sex = self.gender
|
||||||
|
self.firstName = self.firstname
|
||||||
|
self.lastName = self.lastname
|
||||||
|
self.dateofbirth = self.dob
|
||||||
|
self.height = 120
|
||||||
|
self.dead = self.getMetadata("dead")
|
||||||
|
|
||||||
function self.addAccountMoney(account, amount)
|
function self.addAccountMoney(account, amount)
|
||||||
local amount = tonumber(amount)
|
local amount = tonumber(amount)
|
||||||
if not amount or amount <= 0 or account ~= "bank" and account ~= "cash" then return end
|
if not amount or amount <= 0 or account ~= "bank" and account ~= "cash" then return end
|
||||||
@@ -326,20 +362,10 @@ function NDCore.OneSync.SpawnPedInVehicle(model, vehicle, seat, cb)
|
|||||||
cb(value)
|
cb(value)
|
||||||
end
|
end
|
||||||
|
|
||||||
AddEventHandler("esx:playerDropped", function(src)
|
|
||||||
TriggerEvent("ND:characterUnloaded", src, NDCore.getPlayer(src))
|
|
||||||
end
|
|
||||||
|
|
||||||
AddEventHandler("esx:playerLoaded", function(src)
|
|
||||||
TriggerEvent("ND:characterLoaded", NDCore.getPlayer(src))
|
|
||||||
end
|
|
||||||
|
|
||||||
AddEventHandler("ND:characterUnloaded", function(src, character)
|
AddEventHandler("ND:characterUnloaded", function(src, character)
|
||||||
TriggerEvent("esx:playerDropped", src, "")
|
TriggerEvent("esx:playerDropped", src, "")
|
||||||
end
|
end)
|
||||||
|
|
||||||
AddEventHandler("ND:characterLoaded", function(character)
|
AddEventHandler("ND:characterLoaded", function(character)
|
||||||
TriggerEvent("esx:playerLoaded", character.source, createPlayerFunctions(character))
|
TriggerEvent("esx:playerLoaded", character.source, createPlayerFunctions(character))
|
||||||
end
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,9 @@ server_scripts {
|
|||||||
|
|
||||||
files {
|
files {
|
||||||
"init.lua",
|
"init.lua",
|
||||||
"client/vehicle/data.lua"
|
"client/vehicle/data.lua",
|
||||||
|
"compatibility/**/locale.lua"
|
||||||
}
|
}
|
||||||
|
|
||||||
dependency "oxmysql"
|
dependency "oxmysql"
|
||||||
|
provide "es_extended"
|
||||||
|
|||||||
Reference in New Issue
Block a user