Skip to content

Commit

Permalink
refactor: more ox caching and string formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mafewtm authored Oct 22, 2024
1 parent 48cbc6b commit 8ebc8c1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion bridge/qb/client/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ function functions.SetVehicleProperties(vehicle, props)
props.modRoofLivery = props.modRoofLivery or props.liveryRoof

--- lib.setVehicleProperties copied and pasted from Overextended below so that we can remove the error so that setting properties is best effort
assert(DoesEntityExist(vehicle), string.format('Unable to set vehicle properties for "%s" (entity does not exist)', vehicle))
assert(DoesEntityExist(vehicle), ('Unable to set vehicle properties for "%s" (entity does not exist)'):format(vehicle))

if NetworkGetEntityIsNetworked(vehicle) and NetworkGetEntityOwner(vehicle) ~= cache.playerId then
lib.print.warn('setting vehicle properties on non entity owner client. This may cause certain properties to fail to set. entity:', vehicle)
Expand Down
2 changes: 1 addition & 1 deletion client/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ end)
---@param val PlayerData
RegisterNetEvent('QBCore:Player:SetPlayerData', function(val)
local invokingResource = GetInvokingResource()
if invokingResource and invokingResource ~= GetCurrentResourceName() then return end
if invokingResource and invokingResource ~= cache.resource then return end
QBX.PlayerData = val
end)

Expand Down
2 changes: 1 addition & 1 deletion server/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ exports('Notify', Notify)
---@return string version
local function GetCoreVersion(InvokingResource)
---@diagnostic disable-next-line: missing-parameter
local resourceVersion = GetResourceMetadata(GetCurrentResourceName(), 'version')
local resourceVersion = GetResourceMetadata(cache.resource, 'version')
if InvokingResource and InvokingResource ~= '' then
lib.print.debug(('%s called qbcore version check: %s'):format(InvokingResource or 'Unknown Resource', resourceVersion))
end
Expand Down
32 changes: 16 additions & 16 deletions server/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,27 +90,27 @@ function SetPlayerPrimaryJob(citizenid, jobName)
if not player then
return false, {
code = 'player_not_found',
message = string.format('player not found with citizenid %s', citizenid)
message = ('player not found with citizenid %s'):format(citizenid)
}
end

local grade = jobName == 'unemployed' and 0 or player.PlayerData.jobs[jobName]
if not grade then
return false, {
code = 'player_not_in_job',
message = string.format('player %s does not have job %s', citizenid, jobName)
message = ('player %s does not have job %s'):format(citizenid, jobName)
}
end

local job = GetJob(jobName)
if not job then
return false, {
code = 'job_not_found',
message = jobName .. ' does not exist in core memory'
message = ('%s does not exist in core memory'):format(jobName)
}
end

assert(job.grades[grade] ~= nil, string.format('job %s does not have grade %s', jobName, grade))
assert(job.grades[grade] ~= nil, ('job %s does not have grade %s'):format(jobName, grade))

player.PlayerData.job = toPlayerJob(jobName, job, grade)
player.Functions.Save()
Expand Down Expand Up @@ -145,22 +145,22 @@ function AddPlayerToJob(citizenid, jobName, grade)
if not job then
return false, {
code = 'job_not_found',
message = jobName .. ' does not exist in core memory'
message = ('%s does not exist in core memory'):format(jobName)
}
end

if not job.grades[grade] then
return false, {
code = 'job_missing_grade',
message = string.format('job %s does not have grade %s', jobName, grade),
message = ('job %s does not have grade %s'):format(jobName, grade),
}
end

local player = GetPlayerByCitizenId(citizenid) or GetOfflinePlayer(citizenid)
if not player then
return false, {
code = 'player_not_found',
message = string.format('player not found with citizenid %s', citizenid)
message = ('player not found with citizenid %s'):format(citizenid)
}
end

Expand Down Expand Up @@ -210,7 +210,7 @@ function RemovePlayerFromJob(citizenid, jobName)
if not player then
return false, {
code = 'player_not_found',
message = string.format('player not found with citizenid %s', citizenid)
message = ('player not found with citizenid %s'):format(citizenid)
}
end

Expand Down Expand Up @@ -249,27 +249,27 @@ local function setPlayerPrimaryGang(citizenid, gangName)
if not player then
return false, {
code = 'player_not_found',
message = string.format('player not found with citizenid %s', citizenid)
message = ('player not found with citizenid %s'):format(citizenid)
}
end

local grade = gangName == 'none' and 0 or player.PlayerData.gangs[gangName]
if not grade then
return false, {
code = 'player_not_in_gang',
message = string.format('player %s does not have gang %s', citizenid, gangName)
message = ('player %s does not have gang %s'):format(citizenid, gangName)
}
end

local gang = GetGang(gangName)
if not gang then
return false, {
code = 'gang_not_found',
message = gangName .. ' does not exist in core memory'
message = ('%s does not exist in core memory'):format(gangName)
}
end

assert(gang.grades[grade] ~= nil, string.format('gang %s does not have grade %s', gangName, grade))
assert(gang.grades[grade] ~= nil, ('gang %s does not have grade %s'):format(gangName, grade))

player.PlayerData.gang = {
name = gangName,
Expand Down Expand Up @@ -312,22 +312,22 @@ function AddPlayerToGang(citizenid, gangName, grade)
if not gang then
return false, {
code = 'gang_not_found',
message = gangName .. ' does not exist in core memory'
message = ('%s does not exist in core memory'):format(gangName)
}
end

if not gang.grades[grade] then
return false, {
code = 'gang_missing_grade',
message = string.format('gang %s does not have grade %s', gangName, grade)
message = ('gang %s does not have grade %s'):format(gangName, grade)
}
end

local player = GetPlayerByCitizenId(citizenid) or GetOfflinePlayer(citizenid)
if not player then
return false, {
code = 'player_not_found',
message = string.format('player not found with citizenid %s', citizenid)
message = ('player not found with citizenid %s'):format(citizenid)
}
end

Expand Down Expand Up @@ -377,7 +377,7 @@ local function removePlayerFromGang(citizenid, gangName)
if not player then
return false, {
code = 'player_not_found',
message = string.format('player not found with citizenid %s', citizenid)
message = ('player not found with citizenid %s'):format(citizenid)
}
end

Expand Down
2 changes: 1 addition & 1 deletion server/storage/players.lua
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ local function handleSearchFilters(filters)
end
end
end
return string.format(' WHERE %s', table.concat(clauses, ' AND ')), holders
return (' WHERE %s'):format(table.concat(clauses, ' AND ')), holders
end

---@param filters table <string, any>
Expand Down

0 comments on commit 8ebc8c1

Please sign in to comment.