tweak: all resources - replace GetHashKey with backticks and joaat

improves performance :)
This commit is contained in:
Mycroft
2022-08-30 14:50:18 +01:00
parent 025ed89da5
commit 1906306df1
18 changed files with 50 additions and 50 deletions
+5 -5
View File
@@ -140,7 +140,7 @@ ESX.HashString = function(str)
local format = string.format
local upper = string.upper
local gsub = string.gsub
local hash = GetHashKey(str)
local hash = joaat(str)
local input_map = format("~INPUT_%s~", upper(format("%x", hash)))
input_map = string.gsub(input_map, "FFFFFFFF", "")
@@ -446,7 +446,7 @@ function ESX.Game.SpawnObject(object, coords, cb, networked)
end
end, object, coords, 0.0)
else
local model = type(object) == 'number' and object or GetHashKey(object)
local model = type(object) == 'number' and object or joaat(object)
local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z)
CreateThread(function()
ESX.Streaming.RequestModel(model)
@@ -474,7 +474,7 @@ function ESX.Game.DeleteObject(object)
end
function ESX.Game.SpawnVehicle(vehicle, coords, heading, cb, networked)
local model = (type(vehicle) == 'number' and vehicle or GetHashKey(vehicle))
local model = (type(vehicle) == 'number' and vehicle or joaat(vehicle))
local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z)
networked = networked == nil and true or networked
if networked then
@@ -1136,7 +1136,7 @@ function ESX.ShowInventory()
end
for k, v in ipairs(Config.Weapons) do
local weaponHash = GetHashKey(v.name)
local weaponHash = joaat(v.name)
if HasPedGotWeapon(playerPed, weaponHash, false) then
local ammo, label = GetAmmoInPedWeapon(playerPed, weaponHash)
@@ -1332,7 +1332,7 @@ function ESX.ShowInventory()
elseif data1.current.action == 'give_ammo' then
local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer()
local closestPed = GetPlayerPed(closestPlayer)
local pedAmmo = GetAmmoInPedWeapon(playerPed, GetHashKey(item))
local pedAmmo = GetAmmoInPedWeapon(playerPed, joaat(item))
if IsPedOnFoot(closestPed) and not IsPedFalling(closestPed) then
if closestPlayer ~= -1 and closestDistance < 3.0 then
+11 -11
View File
@@ -28,7 +28,7 @@ AddEventHandler('esx:playerLoaded', function(xPlayer, isNew, skin)
y = ESX.PlayerData.coords.y,
z = ESX.PlayerData.coords.z + 0.25,
heading = ESX.PlayerData.coords.heading,
model = GetHashKey("mp_m_freemode_01"),
model = `mp_m_freemode_01`,
skipFade = false
}, function()
TriggerServerEvent('esx:onPlayerSpawn')
@@ -165,7 +165,7 @@ AddEventHandler('esx:restoreLoadout', function()
for k,v in ipairs(ESX.PlayerData.loadout) do
local weaponName = v.name
local weaponHash = GetHashKey(weaponName)
local weaponHash = joaat(weaponName)
GiveWeaponToPed(ESX.PlayerData.ped, weaponHash, 0, false, false)
SetPedWeaponTintIndex(ESX.PlayerData.ped, weaponHash, v.tintIndex)
@@ -244,36 +244,36 @@ if not Config.OxInventory then
RegisterNetEvent('esx:addWeapon')
AddEventHandler('esx:addWeapon', function(weapon, ammo)
GiveWeaponToPed(ESX.PlayerData.ped, GetHashKey(weapon), ammo, false, false)
GiveWeaponToPed(ESX.PlayerData.ped, joaat(weapon), ammo, false, false)
end)
RegisterNetEvent('esx:addWeaponComponent')
AddEventHandler('esx:addWeaponComponent', function(weapon, weaponComponent)
local componentHash = ESX.GetWeaponComponent(weapon, weaponComponent).hash
GiveWeaponComponentToPed(ESX.PlayerData.ped, GetHashKey(weapon), componentHash)
GiveWeaponComponentToPed(ESX.PlayerData.ped, joaat(weapon), componentHash)
end)
RegisterNetEvent('esx:setWeaponAmmo')
AddEventHandler('esx:setWeaponAmmo', function(weapon, weaponAmmo)
SetPedAmmo(ESX.PlayerData.ped, GetHashKey(weapon), weaponAmmo)
SetPedAmmo(ESX.PlayerData.ped, joaat(weapon), weaponAmmo)
end)
RegisterNetEvent('esx:setWeaponTint')
AddEventHandler('esx:setWeaponTint', function(weapon, weaponTintIndex)
SetPedWeaponTintIndex(ESX.PlayerData.ped, GetHashKey(weapon), weaponTintIndex)
SetPedWeaponTintIndex(ESX.PlayerData.ped, joaat(weapon), weaponTintIndex)
end)
RegisterNetEvent('esx:removeWeapon')
AddEventHandler('esx:removeWeapon', function(weapon)
local playerPed = ESX.PlayerData.ped
RemoveWeaponFromPed(ESX.PlayerData.ped, GetHashKey(weapon))
SetPedAmmo(ESX.PlayerData.ped, GetHashKey(weapon), 0)
RemoveWeaponFromPed(ESX.PlayerData.ped, joaat(weapon))
SetPedAmmo(ESX.PlayerData.ped, joaat(weapon), 0)
end)
RegisterNetEvent('esx:removeWeaponComponent')
AddEventHandler('esx:removeWeaponComponent', function(weapon, weaponComponent)
local componentHash = ESX.GetWeaponComponent(weapon, weaponComponent).hash
RemoveWeaponComponentFromPed(ESX.PlayerData.ped, GetHashKey(weapon), componentHash)
RemoveWeaponComponentFromPed(ESX.PlayerData.ped, joaat(weapon), componentHash)
end)
end
@@ -294,7 +294,7 @@ RegisterNetEvent('esx:spawnVehicle')
AddEventHandler('esx:spawnVehicle', function(vehicle)
ESX.TriggerServerCallback("esx:isUserAdmin", function(admin)
if admin then
local model = (type(vehicle) == 'number' and vehicle or GetHashKey(vehicle))
local model = (type(vehicle) == 'number' and vehicle or joaat(vehicle))
if IsModelInCdimage(model) then
local playerCoords, playerHeading = GetEntityCoords(ESX.PlayerData.ped), GetEntityHeading(ESX.PlayerData.ped)
@@ -352,7 +352,7 @@ if not Config.OxInventory then
end
if type == 'item_weapon' then
local weaponHash = GetHashKey(name)
local weaponHash = joaat(name)
ESX.Streaming.RequestWeaponAsset(weaponHash)
local pickupObject = CreateWeaponObject(weaponHash, 50, coords.x, coords.y, coords.z, true, 1.0, 0)
SetWeaponObjectTintIndex(pickupObject, tintIndex)
@@ -1,5 +1,5 @@
function ESX.Streaming.RequestModel(modelHash, cb)
modelHash = (type(modelHash) == 'number' and modelHash or GetHashKey(modelHash))
modelHash = (type(modelHash) == 'number' and modelHash or joaat(modelHash))
if not HasModelLoaded(modelHash) and IsModelInCdimage(modelHash) then
RequestModel(modelHash)
+1 -1
View File
@@ -30,7 +30,7 @@ end
function ESX.GetWeaponFromHash(weaponHash)
for k,v in ipairs(Config.Weapons) do
if GetHashKey(v.name) == weaponHash then
if joaat(v.name) == weaponHash then
return v
end
end
+4 -4
View File
@@ -61,7 +61,7 @@ end
---@param heading number
---@param cb function
function ESX.OneSync.SpawnVehicle(model, coords, heading, autoMobile, cb)
if type(model) == 'string' then model = GetHashKey(model) end
if type(model) == 'string' then model = joaat(model) end
local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z)
if type(autoMobile) ~= 'boolean' then
return
@@ -81,7 +81,7 @@ end
---@param heading number
---@param cb function
function ESX.OneSync.SpawnObject(model, coords, heading, cb)
if type(model) == 'string' then model = GetHashKey(model) end
if type(model) == 'string' then model = joaat(model) end
local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z)
CreateThread(function()
local entity = CreateObject(model, coords, true, true)
@@ -96,7 +96,7 @@ end
---@param heading number
---@param cb function
function ESX.OneSync.SpawnPed(model, coords, heading, cb)
if type(model) == 'string' then model = GetHashKey(model) end
if type(model) == 'string' then model = joaat(model) end
CreateThread(function()
local entity = CreatePed(0, model, coords.x, coords.y, coords.z, heading, true, true)
while not DoesEntityExist(entity) do Wait(50) end
@@ -109,7 +109,7 @@ end
---@param seat number
---@param cb function
function ESX.OneSync.SpawnPedInVehicle(model, vehicle, seat, cb)
if type(model) == 'string' then model = GetHashKey(model) end
if type(model) == 'string' then model = joaat(model) end
CreateThread(function()
local entity = CreatePedInsideVehicle(vehicle, 1, model, seat, true, true)
while not DoesEntityExist(entity) do Wait(50) end
@@ -300,7 +300,7 @@ function DeleteSpawnedVehicles()
end
function WaitForVehicleToLoad(modelHash)
modelHash = (type(modelHash) == 'number' and modelHash or GetHashKey(modelHash))
modelHash = (type(modelHash) == 'number' and modelHash or joaat(modelHash))
if not HasModelLoaded(modelHash) then
RequestModel(modelHash)
@@ -254,7 +254,7 @@ function getPriceFromHash(vehicleHash, jobGrade, type)
for i = 1, #vehicles do
local vehicle = vehicles[i]
if GetHashKey(vehicle.model) == vehicleHash then
if joaat(vehicle.model) == vehicleHash then
return vehicle.price
end
end
+2 -2
View File
@@ -83,7 +83,7 @@ AddEventHandler('esx_basicneeds:onEat', function(prop_name)
CreateThread(function()
local playerPed = PlayerPedId()
local x,y,z = table.unpack(GetEntityCoords(playerPed))
local prop = CreateObject(GetHashKey(prop_name), x, y, z + 0.2, true, true, true)
local prop = CreateObject(joaat(prop_name), x, y, z + 0.2, true, true, true)
local boneIndex = GetPedBoneIndex(playerPed, 18905)
AttachEntityToEntity(prop, playerPed, boneIndex, 0.12, 0.028, 0.001, 10.0, 175.0, 0.0, true, true, false, true, 1, true)
@@ -110,7 +110,7 @@ AddEventHandler('esx_basicneeds:onDrink', function(prop_name)
CreateThread(function()
local playerPed = PlayerPedId()
local x,y,z = table.unpack(GetEntityCoords(playerPed))
local prop = CreateObject(GetHashKey(prop_name), x, y, z + 0.2, true, true, true)
local prop = CreateObject(joaat(prop_name), x, y, z + 0.2, true, true, true)
local boneIndex = GetPedBoneIndex(playerPed, 18905)
AttachEntityToEntity(prop, playerPed, boneIndex, 0.12, 0.028, 0.001, 10.0, 175.0, 0.0, true, true, false, true, 1, true)
+1 -1
View File
@@ -104,7 +104,7 @@ end)
function getPriceFromModel(model)
for k,v in ipairs(Config.Vehicles) do
if GetHashKey(v.model) == model then
if joaat(v.model) == model then
return v.price
end
end
+2 -2
View File
@@ -77,7 +77,7 @@ function OpenLSMenu(elems, menuName, menuTitle, parent)
local vehiclePrice = 50000
for i = 1, #Vehicles, 1 do
if GetEntityModel(vehicle) == GetHashKey(Vehicles[i].model) then
if GetEntityModel(vehicle) == joaat(Vehicles[i].model) then
vehiclePrice = Vehicles[i].price
break
end
@@ -187,7 +187,7 @@ function GetAction(data)
local vehiclePrice = 50000
for i = 1, #Vehicles, 1 do
if GetEntityModel(vehicle) == GetHashKey(Vehicles[i].model) then
if GetEntityModel(vehicle) == joaat(Vehicles[i].model) then
vehiclePrice = Vehicles[i].price
break
end
+4 -4
View File
@@ -397,7 +397,7 @@ function OpenMobileMechanicActionsMenu()
local playerPed = PlayerPedId()
local vehicle = GetVehiclePedIsIn(playerPed, true)
local towmodel = GetHashKey("flatbed")
local towmodel = `flatbed`
local isVehicleTow = IsVehicleModel(vehicle, towmodel)
if isVehicleTow then
@@ -890,7 +890,7 @@ CreateThread(function()
local closestEntity = nil
for i=1, #trackedEntities, 1 do
local object = GetClosestObjectOfType(coords, 3.0, GetHashKey(trackedEntities[i]), false, false, false)
local object = GetClosestObjectOfType(coords, 3.0, joaat(trackedEntities[i]), false, false, false)
if DoesEntityExist(object) then
local objCoords = GetEntityCoords(object)
@@ -940,7 +940,7 @@ CreateThread(function()
else
local entityModel = GetEntityModel(CurrentActionData.vehicle)
if entityModel == GetHashKey("flatbed") or entityModel == GetHashKey("towtruck2") or entityModel == GetHashKey("slamvan3") then
if entityModel == `flatbed` or entityModel == `towtruck2` or entityModel == `slamvan3` then
TriggerServerEvent('esx_service:disableService', 'mechanic')
end
end
@@ -974,7 +974,7 @@ RegisterCommand('mechanicjob', function()
ESX.ShowNotification(_U('wait_five'), "error")
end
else
if IsPedInAnyVehicle(playerPed, false) and IsVehicleModel(GetVehiclePedIsIn(playerPed, false), GetHashKey('flatbed')) then
if IsPedInAnyVehicle(playerPed, false) and IsVehicleModel(GetVehiclePedIsIn(playerPed, false), `flatbed`) then
StartNPCJob()
else
ESX.ShowNotification(_U('must_in_flatbed'), "error")
+8 -8
View File
@@ -180,9 +180,9 @@ function OpenCloakroomMenu()
ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin, jobSkin)
if skin.sex == 0 then
modelHash = GetHashKey(data.current.maleModel)
modelHash = joaat(data.current.maleModel)
else
modelHash = GetHashKey(data.current.femaleModel)
modelHash = joaat(data.current.femaleModel)
end
ESX.Streaming.RequestModel(modelHash, function()
@@ -707,7 +707,7 @@ function OpenPutWeaponMenu()
local weaponList = ESX.GetWeaponList()
for i=1, #weaponList, 1 do
local weaponHash = GetHashKey(weaponList[i].name)
local weaponHash = joaat(weaponList[i].name)
if HasPedGotWeapon(playerPed, weaponHash, false) and weaponList[i].name ~= 'WEAPON_UNARMED' then
table.insert(elements, {
@@ -739,13 +739,13 @@ function OpenBuyWeaponsMenu()
for k,v in ipairs(Config.AuthorizedWeapons[ESX.PlayerData.job.grade_name]) do
local weaponNum, weapon = ESX.GetWeapon(v.weapon)
local components, label = {}
local hasWeapon = HasPedGotWeapon(playerPed, GetHashKey(v.weapon), false)
local hasWeapon = HasPedGotWeapon(playerPed, joaat(v.weapon), false)
if v.components then
for i=1, #v.components do
if v.components[i] then
local component = weapon.components[i]
local hasComponent = HasPedGotWeaponComponent(playerPed, GetHashKey(v.weapon), component.hash)
local hasComponent = HasPedGotWeaponComponent(playerPed, joaat(v.weapon), component.hash)
if hasComponent then
label = ('%s: <span style="color:green;">%s</span>'):format(component.label, _U('armory_owned'))
@@ -1008,7 +1008,7 @@ AddEventHandler('esx_policejob:hasEnteredEntityZone', function(entity)
CurrentActionData = {entity = entity}
end
if GetEntityModel(entity) == GetHashKey("p_ld_stinger_s") then
if GetEntityModel(entity) == `p_ld_stinger_s` then
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
@@ -1044,7 +1044,7 @@ AddEventHandler('esx_policejob:handcuff', function()
SetEnableHandcuffs(playerPed, true)
DisablePlayerFiring(playerPed, true)
SetCurrentPedWeapon(playerPed, GetHashKey('WEAPON_UNARMED'), true) -- unarm player
SetCurrentPedWeapon(playerPed, `WEAPON_UNARMED`, true) -- unarm player
SetPedCanPlayGestureAnims(playerPed, false)
FreezeEntityPosition(playerPed, true)
DisplayRadar(false)
@@ -1373,7 +1373,7 @@ CreateThread(function()
local closestEntity = nil
for i=1, #trackedEntities, 1 do
local object = GetClosestObjectOfType(playerCoords, 3.0, GetHashKey(trackedEntities[i]), false, false, false)
local object = GetClosestObjectOfType(playerCoords, 3.0, joaat(trackedEntities[i]), false, false, false)
if DoesEntityExist(object) then
local objCoords = GetEntityCoords(object)
@@ -308,7 +308,7 @@ function DeleteSpawnedVehicles()
end
function WaitForVehicleToLoad(modelHash)
modelHash = (type(modelHash) == 'number' and modelHash or GetHashKey(modelHash))
modelHash = (type(modelHash) == 'number' and modelHash or joaat(modelHash))
if not HasModelLoaded(modelHash) then
RequestModel(modelHash)
+2 -2
View File
@@ -539,13 +539,13 @@ function AttemptHouseEntry(PropertyId)
DoScreenFadeOut(1500)
Wait(1500)
if Interior.type == "shell" then
ESX.Streaming.RequestModel(GetHashKey(Property.Interior), function()
ESX.Streaming.RequestModel(joaat(Property.Interior), function()
if Shell then
DeleteObject(Shell)
Shell = nil
end
local Pos = vector3(Property.Entrance.x, Property.Entrance.y, 2000)
Shell = CreateObjectNoOffset(GetHashKey(Property.Interior), Pos + Interior.pos, false, false, false)
Shell = CreateObjectNoOffset(joaat(Property.Interior), Pos + Interior.pos, false, false, false)
SetEntityHeading(Shell, 0.0)
while not DoesEntityExist(Shell) do
Wait(1)
+3 -3
View File
@@ -16,7 +16,7 @@ if Config.Debug then
for i=1, #Config.Interactables, 1 do
local seat = Config.Interactables[i]
if hash == GetHashKey(seat) then
if hash == joaat(seat) then
model = seat
break
end
@@ -65,7 +65,7 @@ RegisterCommand('sit', function()
local hash = GetEntityModel(object)
for k,v in pairs(Config.Sitable) do
if GetHashKey(k) == hash then
if joaat(k) == hash then
sit(object, k, v)
break
end
@@ -81,7 +81,7 @@ function GetNearChair()
local object, distance
local coords = GetEntityCoords(PlayerPedId())
for i=1, #Config.Interactables do
object = GetClosestObjectOfType(coords, 3.0, GetHashKey(Config.Interactables[i]), false, false, false)
object = GetClosestObjectOfType(coords, 3.0, joaat(Config.Interactables[i]), false, false, false)
distance = #(coords - GetEntityCoords(object))
if distance < 1.6 then
return object, distance
+1 -1
View File
@@ -362,7 +362,7 @@ function IsInAuthorizedVehicle()
local vehModel = GetEntityModel(GetVehiclePedIsIn(playerPed, false))
for i = 1, #Config.AuthorizedVehicles, 1 do
if vehModel == GetHashKey(Config.AuthorizedVehicles[i].model) then
if vehModel == joaat(Config.AuthorizedVehicles[i].model) then
return true
end
end
+1 -1
View File
@@ -668,7 +668,7 @@ AddEventHandler('esx_vehicleshop:hasEnteredMarker', function(zone)
if GetPedInVehicleSeat(vehicle, -1) == playerPed then
for i=1, #Vehicles, 1 do
if GetHashKey(Vehicles[i].model) == GetEntityModel(vehicle) then
if joaat(Vehicles[i].model) == GetEntityModel(vehicle) then
vehicleData = Vehicles[i]
break
end
+1 -1
View File
@@ -80,7 +80,7 @@ function DisplayBoughtScaleform(weaponName, price)
ScaleformMovieMethodAddParamTextureNameString(_U('weapon_bought', ESX.Math.GroupDigits(price)))
ScaleformMovieMethodAddParamTextureNameString(ESX.GetWeaponLabel(weaponName))
ScaleformMovieMethodAddParamInt(GetHashKey(weaponName))
ScaleformMovieMethodAddParamInt(joaat(weaponName))
ScaleformMovieMethodAddParamTextureNameString('')
ScaleformMovieMethodAddParamInt(100)
EndScaleformMovieMethod()