From fb4cc3e11376788be11f0b5c23e50cb68bd744b0 Mon Sep 17 00:00:00 2001 From: MoskalykA <100430077+MoskalykA@users.noreply.github.com> Date: Thu, 21 Dec 2023 20:17:32 +0100 Subject: [PATCH] refactor: small optimization --- client/events.lua | 2 +- client/functions.lua | 4 ++-- server/exports.lua | 3 ++- server/player.lua | 11 ++++++----- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/client/events.lua b/client/events.lua index 2f15b57..f492bdd 100644 --- a/client/events.lua +++ b/client/events.lua @@ -120,7 +120,7 @@ end) RegisterNetEvent('QBCore:Command:SpawnVehicle', function(vehName) local ped = PlayerPedId() - local hash = GetHashKey(vehName) + local hash = joaat(vehName) local veh = GetVehiclePedIsUsing(ped) if not IsModelInCdimage(hash) then return end RequestModel(hash) diff --git a/client/functions.lua b/client/functions.lua index edba745..aac5d4e 100644 --- a/client/functions.lua +++ b/client/functions.lua @@ -343,7 +343,7 @@ function QBCore.Functions.GetBoneDistance(entity, boneType, boneIndex) end function QBCore.Functions.AttachProp(ped, model, boneId, x, y, z, xR, yR, zR, vertex) - local modelHash = type(model) == 'string' and GetHashKey(model) or model + local modelHash = type(model) == 'string' and joaat(model) or model local bone = GetPedBoneIndex(ped, boneId) QBCore.Functions.LoadModel(modelHash) local prop = CreateObject(modelHash, 1.0, 1.0, 1.0, 1, 1, 0) @@ -356,7 +356,7 @@ end function QBCore.Functions.SpawnVehicle(model, cb, coords, isnetworked, teleportInto) local ped = PlayerPedId() - model = type(model) == 'string' and GetHashKey(model) or model + model = type(model) == 'string' and joaat(model) or model if not IsModelInCdimage(model) then return end if coords then coords = type(coords) == 'table' and vec3(coords.x, coords.y, coords.z) or coords diff --git a/server/exports.lua b/server/exports.lua index bada8e8..d02518c 100644 --- a/server/exports.lua +++ b/server/exports.lua @@ -306,8 +306,9 @@ end QBCore.Functions.UpdateGang = UpdateGang exports('UpdateGang', UpdateGang) +local resourceName = GetCurrentResourceName() local function GetCoreVersion(InvokingResource) - local resourceVersion = GetResourceMetadata(GetCurrentResourceName(), 'version') + local resourceVersion = GetResourceMetadata(resourceName, 'version') if InvokingResource and InvokingResource ~= '' then print(('%s called qbcore version check: %s'):format(InvokingResource or 'Unknown Resource', resourceVersion)) end diff --git a/server/player.lua b/server/player.lua index 4d3c213..b8c846b 100644 --- a/server/player.lua +++ b/server/player.lua @@ -5,6 +5,7 @@ QBCore.Player = {} -- Don't touch any of this unless you know what you are doing -- Will cause major issues! +local resourceName = GetCurrentResourceName() function QBCore.Player.Login(source, citizenid, newData) if source and source ~= '' then if citizenid then @@ -31,7 +32,7 @@ function QBCore.Player.Login(source, citizenid, newData) end return true else - QBCore.ShowError(GetCurrentResourceName(), 'ERROR QBCORE.PLAYER.LOGIN - NO SOURCE GIVEN!') + QBCore.ShowError(resourceName, 'ERROR QBCORE.PLAYER.LOGIN - NO SOURCE GIVEN!') return false end end @@ -520,9 +521,9 @@ function QBCore.Player.Save(source) metadata = json.encode(PlayerData.metadata) }) if GetResourceState('qb-inventory') ~= 'missing' then exports['qb-inventory']:SaveInventory(source) end - QBCore.ShowSuccess(GetCurrentResourceName(), PlayerData.name .. ' PLAYER SAVED!') + QBCore.ShowSuccess(resourceName, PlayerData.name .. ' PLAYER SAVED!') else - QBCore.ShowError(GetCurrentResourceName(), 'ERROR QBCORE.PLAYER.SAVE - PLAYERDATA IS EMPTY!') + QBCore.ShowError(resourceName, 'ERROR QBCORE.PLAYER.SAVE - PLAYERDATA IS EMPTY!') end end @@ -541,9 +542,9 @@ function QBCore.Player.SaveOffline(PlayerData) metadata = json.encode(PlayerData.metadata) }) if GetResourceState('qb-inventory') ~= 'missing' then exports['qb-inventory']:SaveInventory(PlayerData, true) end - QBCore.ShowSuccess(GetCurrentResourceName(), PlayerData.name .. ' OFFLINE PLAYER SAVED!') + QBCore.ShowSuccess(resourceName, PlayerData.name .. ' OFFLINE PLAYER SAVED!') else - QBCore.ShowError(GetCurrentResourceName(), 'ERROR QBCORE.PLAYER.SAVEOFFLINE - PLAYERDATA IS EMPTY!') + QBCore.ShowError(resourceName, 'ERROR QBCORE.PLAYER.SAVEOFFLINE - PLAYERDATA IS EMPTY!') end end