From 8b5f5b2b378890030a354e951ddd2f80b6cbb069 Mon Sep 17 00:00:00 2001 From: David Malchin Date: Fri, 22 Jul 2022 12:14:02 +0300 Subject: [PATCH 1/4] Fix styling, docs, and a possible bug (#762) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🎨 Fix spacing and indentation * 🎨 Use single quotes over backticks * 📝 Fix docs * 🐛 Make replace function clear and extend locales correctly * Revert "🎨 Use single quotes over backticks" * Update config.lua --- config.lua | 2 +- html/js/app.js | 1 - html/js/config.js | 4 ++-- shared/locale.lua | 11 +++++------ shared/main.lua | 40 ++++++++++++++++++++-------------------- 5 files changed, 28 insertions(+), 30 deletions(-) diff --git a/config.lua b/config.lua index 781b3db..70db402 100644 --- a/config.lua +++ b/config.lua @@ -6,7 +6,7 @@ QBConfig.UpdateInterval = 5 -- how often to update player data in minutes QBConfig.StatusInterval = 5000 -- how often to check hunger/thirst status in milliseconds QBConfig.Money = {} -QBConfig.Money.MoneyTypes = { ['cash'] = 500, ['bank'] = 5000, ['crypto'] = 0 } -- ['type'] = startamount - Add or remove money types for your server (for ex. ['blackmoney'] = 0), remember once added it will not be removed from the database! +QBConfig.Money.MoneyTypes = { cash = 500, bank = 5000, crypto = 0 } -- type = startamount - Add or remove money types for your server (for ex. blackmoney = 0), remember once added it will not be removed from the database! QBConfig.Money.DontAllowMinus = { 'cash', 'crypto' } -- Money that is not allowed going in minus QBConfig.Money.PayCheckTimeOut = 10 -- The time in minutes that it will give the paycheck QBConfig.Money.PayCheckSociety = false -- If true paycheck will come from the society account that the player is employed at, requires qb-management diff --git a/html/js/app.js b/html/js/app.js index 50ff2fb..d13562e 100644 --- a/html/js/app.js +++ b/html/js/app.js @@ -8,7 +8,6 @@ import { } from "./config.js"; const { useQuasar } = Quasar; - const { onMounted, onUnmounted } = Vue; const app = Vue.createApp({ diff --git a/html/js/config.js b/html/js/config.js index d21352a..32fa978 100644 --- a/html/js/config.js +++ b/html/js/config.js @@ -13,13 +13,13 @@ export const DEV_MODE = false; * Will hold config statically outside of Vue state * @property {Record} VariantDefinitions * @property {Record} NotificationStyling - * */ + **/ export let NOTIFY_CONFIG = null; /** * Pure function taking a notification type and returning an object * with style details - * @param variant {string} + * @param {string} variant * @returns NotiVariantData **/ export const determineStyleFromVariant = (variant) => { diff --git a/shared/locale.lua b/shared/locale.lua index 6b9510b..c24376c 100644 --- a/shared/locale.lua +++ b/shared/locale.lua @@ -44,7 +44,7 @@ end --- internally for initial population of phrases field. --- @param phrases table - Table of phrase definitions --- @param prefix string | nil - Optional prefix used for recursive calls ---- @return void +--- @return nil function Locale:extend(phrases, prefix) for key, phrase in pairs(phrases) do local prefixKey = prefix and ('%s.%s'):format(prefix, key) or key @@ -57,10 +57,9 @@ function Locale:extend(phrases, prefix) end end - --- Clear locale instance phrases --- Might be useful for memory management of large phrase maps. ---- @return void +--- @return nil function Locale:clear() self.phrases = {} end @@ -69,8 +68,8 @@ end --- @param phrases table function Locale:replace(phrases) phrases = phrases or {} - self.clear() - self.extend(phrases) + self:clear() + self:extend(phrases) end --- Gets & Sets a locale depending on if an argument is passed @@ -85,7 +84,7 @@ end --- Primary translation method for a phrase of given key --- @param key string - The phrase key to target ---- @param subs table +--- @param subs table | nil --- @return string function Locale:t(key, subs) local phrase, result diff --git a/shared/main.lua b/shared/main.lua index 2319bc9..3eb8f61 100644 --- a/shared/main.lua +++ b/shared/main.lua @@ -3,9 +3,9 @@ QBShared = QBShared or {} local StringCharset = {} local NumberCharset = {} -for i = 48, 57 do NumberCharset[#NumberCharset+1] = string.char(i) end -for i = 65, 90 do StringCharset[#StringCharset+1] = string.char(i) end -for i = 97, 122 do StringCharset[#StringCharset+1] = string.char(i) end +for i = 48, 57 do NumberCharset[#NumberCharset + 1] = string.char(i) end +for i = 65, 90 do StringCharset[#StringCharset + 1] = string.char(i) end +for i = 97, 122 do StringCharset[#StringCharset + 1] = string.char(i) end function QBShared.RandomStr(length) if length <= 0 then return '' end @@ -22,16 +22,16 @@ function QBShared.SplitStr(str, delimiter) local from = 1 local delim_from, delim_to = string.find(str, delimiter, from) while delim_from do - result[#result+1] = string.sub(str, from, delim_from - 1) + result[#result + 1] = string.sub(str, from, delim_from - 1) from = delim_to + 1 delim_from, delim_to = string.find(str, delimiter, from) end - result[#result+1] = string.sub(str, from) + result[#result + 1] = string.sub(str, from) return result end function QBShared.Trim(value) - if not value then return nil end + if not value then return nil end return (string.gsub(value, '^%s*(.-)%s*$', '%1')) end @@ -42,24 +42,24 @@ function QBShared.Round(value, numDecimalPlaces) end function QBShared.ChangeVehicleExtra(vehicle, extra, enable) - if DoesExtraExist(vehicle, extra) then - if enable then - SetVehicleExtra(vehicle, extra, false) - if not IsVehicleExtraTurnedOn(vehicle, extra) then - QBShared.ChangeVehicleExtra(vehicle, extra, enable) - end - else - SetVehicleExtra(vehicle, extra, true) - if IsVehicleExtraTurnedOn(vehicle, extra) then - QBShared.ChangeVehicleExtra(vehicle, extra, enable) - end - end - end + if DoesExtraExist(vehicle, extra) then + if enable then + SetVehicleExtra(vehicle, extra, false) + if not IsVehicleExtraTurnedOn(vehicle, extra) then + QBShared.ChangeVehicleExtra(vehicle, extra, enable) + end + else + SetVehicleExtra(vehicle, extra, true) + if IsVehicleExtraTurnedOn(vehicle, extra) then + QBShared.ChangeVehicleExtra(vehicle, extra, enable) + end + end + end end function QBShared.SetDefaultVehicleExtras(vehicle, config) -- Clear Extras - for i = 1,20 do + for i = 1, 20 do if DoesExtraExist(vehicle, i) then SetVehicleExtra(vehicle, i, 1) end From 1b2915a75f8b19c9dd163e66b2960753b40d1568 Mon Sep 17 00:00:00 2001 From: Kakarot <57848836+GhzGarage@users.noreply.github.com> Date: Fri, 22 Jul 2022 22:59:01 -0500 Subject: [PATCH 2/4] Vehicle server-spawning functions/callback --- server/events.lua | 11 +++++++++++ server/functions.lua | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/server/events.lua b/server/events.lua index ee8adfa..151d40a 100644 --- a/server/events.lua +++ b/server/events.lua @@ -244,3 +244,14 @@ QBCore.Functions.CreateCallback('QBCore:HasItem', function(source, cb, items, am end cb(retval) end) + +-- Vehicle server-side spawning callback (netId) +-- use the netid on the client with the NetworkGetEntityFromNetworkId native +-- convert it to a vehicle via the NetToVeh native +QBCore.Functions.CreateCallback('QBCore:Server:SpawnVehicle', function(source, cb, model, coords, warp) + if not coords then coords = GetEntityCoords(GetPlayerPed(source)) end + local veh = CreateVehicle(model, coords.x, coords.y, coords.z, coords.w, true, true) + while not DoesEntityExist(veh) do Wait(0) end + if warp then TaskWarpPedIntoVehicle(GetPlayerPed(source), veh, -1) end + cb(NetworkGetNetworkIdFromEntity(veh)) +end) \ No newline at end of file diff --git a/server/functions.lua b/server/functions.lua index eb2097a..cca2f8e 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -167,6 +167,30 @@ function QBCore.Functions.GetEntitiesInBucket(bucket --[[ int ]]) end end +-- Server side vehicle creation with optional callback +-- the CreateVehicle RPC still uses the client for creation so players must be near +function QBCore.Functions.SpawnVehicle(model, cb, coords, warp) + model = type(model) == 'string' and GetHashKey(model) or model + if not coords then coords = GetEntityCoords(GetPlayerPed(source)) end + local veh = CreateVehicle(model, coords.x, coords.y, coords.z, coords.w, true, true) + while not DoesEntityExist(veh) do Wait(0) end + if warp then TaskWarpPedIntoVehicle(GetPlayerPed(source), veh, -1) end + if cb then cb(veh) end +end + +-- Server side vehicle creation with optional callback +-- the CreateAutomobile native is still experimental but doesn't use client for creation +-- doesn't work for all vehicles! +function QBCore.Functions.CreateVehicle(model, cb, coords, warp) + model = type(model) == 'string' and GetHashKey(model) or model + if not coords then coords = GetEntityCoords(GetPlayerPed(source)) end + local CreateAutomobile = GetHashKey("CREATE_AUTOMOBILE") + local veh = Citizen.InvokeNative(CreateAutomobile, model, coords, coords.w, true, true) + while not DoesEntityExist(veh) do Wait(0) end + if warp then TaskWarpPedIntoVehicle(GetPlayerPed(source), veh, -1) end + if cb then cb(veh) end +end + -- Paychecks (standalone - don't touch) function PaycheckInterval() From 2b0e0c8edcfd1bb8f7fe4b1218e81f114fdf4ecc Mon Sep 17 00:00:00 2001 From: Kakarot <57848836+GhzGarage@users.noreply.github.com> Date: Sat, 23 Jul 2022 02:14:20 -0500 Subject: [PATCH 3/4] Model check --- server/events.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/events.lua b/server/events.lua index 151d40a..fff48ff 100644 --- a/server/events.lua +++ b/server/events.lua @@ -249,9 +249,10 @@ end) -- use the netid on the client with the NetworkGetEntityFromNetworkId native -- convert it to a vehicle via the NetToVeh native QBCore.Functions.CreateCallback('QBCore:Server:SpawnVehicle', function(source, cb, model, coords, warp) + model = type(model) == 'string' and GetHashKey(model) or model if not coords then coords = GetEntityCoords(GetPlayerPed(source)) end local veh = CreateVehicle(model, coords.x, coords.y, coords.z, coords.w, true, true) while not DoesEntityExist(veh) do Wait(0) end if warp then TaskWarpPedIntoVehicle(GetPlayerPed(source), veh, -1) end cb(NetworkGetNetworkIdFromEntity(veh)) -end) \ No newline at end of file +end) From 38ed80fed292243cacb40bbc5c2788be6468b221 Mon Sep 17 00:00:00 2001 From: NetOut <32980305+Maykellll1@users.noreply.github.com> Date: Sat, 23 Jul 2022 15:01:23 +0200 Subject: [PATCH 4/4] Fixed isnetworked (#764) With the above way, the condition was always true because (false or true) is true or (nil or true) is true. With this change it is fixed. --- client/functions.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/functions.lua b/client/functions.lua index db572c3..6292a46 100644 --- a/client/functions.lua +++ b/client/functions.lua @@ -396,7 +396,7 @@ function QBCore.Functions.SpawnVehicle(model, cb, coords, isnetworked, teleportI else coords = GetEntityCoords(ped) end - isnetworked = isnetworked or true + isnetworked = isnetworked == nil or isnetworked QBCore.Functions.LoadModel(model) local veh = CreateVehicle(model, coords.x, coords.y, coords.z, coords.w, isnetworked, false) local netid = NetworkGetNetworkIdFromEntity(veh)