diff --git a/client/main.lua b/client/main.lua index 66c036d..cca5e02 100644 --- a/client/main.lua +++ b/client/main.lua @@ -15,14 +15,13 @@ local IsHotwiring = false ----------------------- ---- Threads ---- ----------------------- - CreateThread(function() while true do local sleep = 1000 if LocalPlayer.state.isLoggedIn then sleep = 100 - local ped = PlayerPedId() + local ped = cache.ped local entering = GetVehiclePedIsTryingToEnter(ped) local carIsImmune = false if entering ~= 0 and not isBlacklistedVehicle(entering) then @@ -88,7 +87,7 @@ CreateThread(function() local vehicle = GetVehiclePedIsIn(ped) local plate = QBCore.Functions.GetPlate(vehicle) - if GetPedInVehicleSeat(vehicle, -1) == PlayerPedId() and not HasKeys(plate) and not isBlacklistedVehicle(vehicle) and not AreKeysJobShared(vehicle) then + if GetPedInVehicleSeat(vehicle, -1) == cache.ped and not HasKeys(plate) and not isBlacklistedVehicle(vehicle) and not AreKeysJobShared(vehicle) then sleep = 0 local vehiclePos = GetOffsetFromEntityInWorldCoords(vehicle, 0.0, 1.0, 0.5) @@ -172,7 +171,7 @@ end) RegisterNetEvent('qb-vehiclekeys:client:AddKeys', function(plate) KeysList[plate] = true - local ped = PlayerPedId() + local ped = cache.ped if IsPedInAnyVehicle(ped, false) then local vehicle = GetVehiclePedIsIn(ped) local vehicleplate = QBCore.Functions.GetPlate(vehicle) @@ -188,8 +187,8 @@ RegisterNetEvent('qb-vehiclekeys:client:RemoveKeys', function(plate) end) RegisterNetEvent('qb-vehiclekeys:client:ToggleEngine', function() - local EngineOn = GetIsVehicleEngineRunning(GetVehiclePedIsIn(PlayerPedId())) - local vehicle = GetVehiclePedIsIn(PlayerPedId(), true) + local EngineOn = GetIsVehicleEngineRunning(GetVehiclePedIsIn(cache.ped)) + local vehicle = GetVehiclePedIsIn(cache.ped, true) if HasKeys(QBCore.Functions.GetPlate(vehicle)) then if EngineOn then SetVehicleEngineOn(vehicle, false, false, true) @@ -208,7 +207,7 @@ RegisterNetEvent('qb-vehiclekeys:client:GiveKeys', function(id) if id and type(id) == "number" then -- Give keys to specific ID GiveKeys(id, targetPlate) else - if IsPedSittingInVehicle(PlayerPedId(), targetVehicle) then -- Give keys to everyone in vehicle + if IsPedSittingInVehicle(cache.ped, targetVehicle) then -- Give keys to everyone in vehicle local otherOccupants = GetOtherPlayersInVehicle(targetVehicle) for p=1,#otherOccupants do TriggerServerEvent('qb-vehiclekeys:server:GiveVehicleKeys', GetPlayerServerId(NetworkGetPlayerIndexFromPed(otherOccupants[p])), targetPlate) @@ -218,7 +217,7 @@ RegisterNetEvent('qb-vehiclekeys:client:GiveKeys', function(id) end end else - lib.notify({ description = Lang:t("notify.no_keys"), type = 'error' }) + QBCore.Functions.NotifyV2({ description = Lang:t("notify.no_keys"), type = 'error' }) end end end) @@ -227,7 +226,6 @@ RegisterNetEvent('lockpicks:UseLockpick', function(isAdvanced) LockpickDoor(isAdvanced) end) - -- Backwards Compatibility ONLY -- Remove at some point -- RegisterNetEvent('vehiclekeys:client:SetOwner', function(plate) TriggerServerEvent('qb-vehiclekeys:server:AcquireVehicleKeys', plate) @@ -239,11 +237,11 @@ end) ----------------------- function GiveKeys(id, plate) - local distance = #(GetEntityCoords(PlayerPedId()) - GetEntityCoords(GetPlayerPed(GetPlayerFromServerId(id)))) + local distance = #(GetEntityCoords(cache.ped) - GetEntityCoords(GetPlayerPed(GetPlayerFromServerId(id)))) if distance < 1.5 and distance > 0.0 then TriggerServerEvent('qb-vehiclekeys:server:GiveVehicleKeys', id, plate) else - lib.notify({ description = Lang:t("notify.not_near"), type = 'error' }) + QBCore.Functions.NotifyV2({ description = Lang:t("notify.not_near"), type = 'error' }) end end @@ -266,11 +264,11 @@ function loadAnimDict(dict) end function GetVehicleInDirection(coordFromOffset, coordToOffset) - local ped = PlayerPedId() + local ped = cache.ped local coordFrom = GetOffsetFromEntityInWorldCoords(ped, coordFromOffset.x, coordFromOffset.y, coordFromOffset.z) local coordTo = GetOffsetFromEntityInWorldCoords(ped, coordToOffset.x, coordToOffset.y, coordToOffset.z) - local rayHandle = CastRayPointToPoint(coordFrom.x, coordFrom.y, coordFrom.z, coordTo.x, coordTo.y, coordTo.z, 10, PlayerPedId(), 0) + local rayHandle = CastRayPointToPoint(coordFrom.x, coordFrom.y, coordFrom.z, coordTo.x, coordTo.y, coordTo.z, 10, cache.ped, 0) local _, _, _, _, vehicle = GetShapeTestResult(rayHandle) return vehicle end @@ -278,7 +276,7 @@ end -- If in vehicle returns that, otherwise tries 3 different raycasts to get the vehicle they are facing. -- Raycasts picture: https://i.imgur.com/FRED0kV.png function GetVehicle() - local vehicle = GetVehiclePedIsIn(PlayerPedId()) + local vehicle = GetVehiclePedIsIn(cache.ped) local RaycastOffsetTable = { { ['fromOffset'] = vector3(0.0, 0.0, 0.0), ['toOffset'] = vector3(0.0, 20.0, -10.0) }, -- Waist to ground 45 degree angle @@ -321,7 +319,7 @@ function ToggleVehicleLocks(veh) if veh then if not isBlacklistedVehicle(veh) then if HasKeys(QBCore.Functions.GetPlate(veh)) or AreKeysJobShared(veh) then - local ped = PlayerPedId() + local ped = cache.ped local vehLockStatus = GetVehicleDoorLockStatus(veh) loadAnimDict("anim@mp_player_intmenu@key_fob@") @@ -332,10 +330,10 @@ function ToggleVehicleLocks(veh) NetworkRequestControlOfEntity(veh) if vehLockStatus == 1 then TriggerServerEvent('qb-vehiclekeys:server:setVehLockState', NetworkGetNetworkIdFromEntity(veh), 2) - lib.notify({ description = Lang:t("notify.vehicle_locked"), type = 'inform' }) + QBCore.Functions.NotifyV2({ description = Lang:t("notify.vehicle_locked"), type = 'inform' }) else TriggerServerEvent('qb-vehiclekeys:server:setVehLockState', NetworkGetNetworkIdFromEntity(veh), 1) - lib.notify({ description = Lang:t("notify.vehicle_unlocked"), type = 'inform' }) + QBCore.Functions.NotifyV2({ description = Lang:t("notify.vehicle_unlocked"), type = 'inform' }) end SetVehicleLights(veh, 2) @@ -346,7 +344,7 @@ function ToggleVehicleLocks(veh) Wait(300) ClearPedTasks(ped) else - lib.notify({ description = Lang:t("notify.no_keys"), type = 'error' }) + QBCore.Functions.NotifyV2({ description = Lang:t("notify.no_keys"), type = 'error' }) end else TriggerServerEvent('qb-vehiclekeys:server:setVehLockState', NetworkGetNetworkIdFromEntity(veh), 1) @@ -358,7 +356,7 @@ function GetOtherPlayersInVehicle(vehicle) local otherPeds = {} for seat=-1,GetVehicleModelNumberOfSeats(GetEntityModel(vehicle))-2 do local pedInSeat = GetPedInVehicleSeat(vehicle, seat) - if IsPedAPlayer(pedInSeat) and pedInSeat ~= PlayerPedId() then + if IsPedAPlayer(pedInSeat) and pedInSeat ~= cache.ped then otherPeds[#otherPeds+1] = pedInSeat end end @@ -377,7 +375,7 @@ function GetPedsInVehicle(vehicle) end function IsBlacklistedWeapon() - local weapon = GetSelectedPedWeapon(PlayerPedId()) + local weapon = GetSelectedPedWeapon(cache.ped) if weapon ~= nil then for _, v in pairs(Config.NoCarjackWeapons) do if weapon == GetHashKey(v) then @@ -389,7 +387,7 @@ function IsBlacklistedWeapon() end function LockpickDoor(isAdvanced) - local ped = PlayerPedId() + local ped = cache.ped local pos = GetEntityCoords(ped) local vehicle = QBCore.Functions.GetClosestVehicle() @@ -410,10 +408,10 @@ function LockpickFinishCallback(success) TriggerServerEvent('hud:server:GainStress', math.random(1, 4)) lastPickedVehicle = vehicle - if GetPedInVehicleSeat(vehicle, -1) == PlayerPedId() then + if GetPedInVehicleSeat(vehicle, -1) == cache.ped then TriggerServerEvent('qb-vehiclekeys:server:AcquireVehicleKeys', QBCore.Functions.GetPlate(vehicle)) else - lib.notify({ description = Lang:t("notify.vehicle_lockedpick"), type = 'success' }) + QBCore.Functions.NotifyV2({ description = Lang:t("notify.vehicle_lockedpick"), type = 'success' }) TriggerServerEvent('qb-vehiclekeys:server:setVehLockState', NetworkGetNetworkIdFromEntity(vehicle), 1) end @@ -435,7 +433,7 @@ end function Hotwire(vehicle, plate) local hotwireTime = math.random(Config.minHotwireTime, Config.maxHotwireTime) - local ped = PlayerPedId() + local ped = cache.ped IsHotwiring = true SetVehicleAlarm(vehicle, true) @@ -456,7 +454,7 @@ function Hotwire(vehicle, plate) if (math.random() <= Config.HotwireChance) then TriggerServerEvent('qb-vehiclekeys:server:AcquireVehicleKeys', plate) else - lib.notify({ description = Lang:t("notify.failed_lockedpick"), type = 'error' }) + QBCore.Functions.NotifyV2({ description = Lang:t("notify.failed_lockedpick"), type = 'error' }) end Wait(Config.TimeBetweenHotwires) IsHotwiring = false @@ -488,7 +486,7 @@ function CarjackVehicle(target) -- Cancel progress bar if: Ped dies during robbery, car gets too far away CreateThread(function() while isCarjacking do - local distance = #(GetEntityCoords(PlayerPedId()) - GetEntityCoords(target)) + local distance = #(GetEntityCoords(cache.ped) - GetEntityCoords(target)) if IsPedDeadOrDying(target) or distance > 7.5 then lib.cancelProgress() end @@ -506,7 +504,7 @@ function CarjackVehicle(target) car = true, }, }) then - local hasWeapon, weaponHash = GetCurrentPedWeapon(PlayerPedId(), true) + local hasWeapon, weaponHash = GetCurrentPedWeapon(cache.ped, true) if hasWeapon and isCarjacking then local carjackChance if Config.CarjackChance[tostring(GetWeapontypeGroup(weaponHash))] then @@ -530,7 +528,7 @@ function CarjackVehicle(target) TriggerServerEvent('hud:server:GainStress', math.random(1, 4)) TriggerServerEvent('qb-vehiclekeys:server:AcquireVehicleKeys', plate) else - lib.notify({ description = Lang:t("notify.carjack_failed"), type = 'error' }) + QBCore.Functions.NotifyV2({ description = Lang:t("notify.carjack_failed"), type = 'error' }) MakePedFlee(target) TriggerServerEvent('hud:server:GainStress', math.random(1, 4)) end @@ -566,7 +564,7 @@ end function MakePedFlee(ped) SetPedFleeAttributes(ped, 0, 0) - TaskReactAndFleePed(ped, PlayerPedId()) + TaskReactAndFleePed(ped, cache.ped) end function DrawText3D(x, y, z, text) diff --git a/config.lua b/config.lua index f60f398..16f0ce7 100644 --- a/config.lua +++ b/config.lua @@ -44,16 +44,16 @@ Config.SharedKeys = { -- Share keys amongst employees. Employees can lock/unlock ['police'] = { -- Job name requireOnduty = false, vehicles = { - 'police', -- Vehicle model - 'police2', -- Vehicle model - } + 'police', -- Vehicle model + 'police2', -- Vehicle model + } }, ['mechanic'] = { requireOnduty = false, vehicles = { 'towtruck', - } + } } } diff --git a/fxmanifest.lua b/fxmanifest.lua index 45afa61..60a4ce5 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -7,6 +7,7 @@ version '1.0.1' shared_scripts { '@qb-core/shared/locale.lua', 'locales/en.lua', + 'locales/*.lua', '@ox_lib/init.lua', 'config.lua', } diff --git a/locales/de.lua b/locales/de.lua index f14bbb0..bb7b56d 100644 --- a/locales/de.lua +++ b/locales/de.lua @@ -40,7 +40,10 @@ local Translations = { } -Lang = Locale:new({ - phrases = Translations, - warnOnMissing = true -}) +if GetConvar('qb_locale', 'en') == 'de' then + Lang = Locale:new({ + phrases = Translations, + warnOnMissing = true, + fallbackLang = Lang, + }) +end diff --git a/locales/en.lua b/locales/en.lua index 5bbbc27..5a1b082 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -40,7 +40,7 @@ local Translations = { } -Lang = Locale:new({ +Lang = Lang or Locale:new({ phrases = Translations, warnOnMissing = true }) diff --git a/locales/es.lua b/locales/es.lua index 191014b..6974241 100644 --- a/locales/es.lua +++ b/locales/es.lua @@ -40,7 +40,10 @@ local Translations = { } -Lang = Locale:new({ - phrases = Translations, - warnOnMissing = true -}) +if GetConvar('qb_locale', 'en') == 'es' then + Lang = Locale:new({ + phrases = Translations, + warnOnMissing = true, + fallbackLang = Lang, + }) +end diff --git a/locales/et.lua b/locales/et.lua index 1f8489d..ceb2720 100644 --- a/locales/et.lua +++ b/locales/et.lua @@ -40,7 +40,10 @@ local Translations = { } -Lang = Locale:new({ - phrases = Translations, - warnOnMissing = true -}) +if GetConvar('qb_locale', 'en') == 'et' then + Lang = Locale:new({ + phrases = Translations, + warnOnMissing = true, + fallbackLang = Lang, + }) +end diff --git a/locales/fr.lua b/locales/fr.lua index 7fd4bb8..f669912 100644 --- a/locales/fr.lua +++ b/locales/fr.lua @@ -40,7 +40,10 @@ local Translations = { } -Lang = Locale:new({ - phrases = Translations, - warnOnMissing = true -}) +if GetConvar('qb_locale', 'en') == 'fr' then + Lang = Locale:new({ + phrases = Translations, + warnOnMissing = true, + fallbackLang = Lang, + }) +end diff --git a/locales/ro.lua b/locales/ro.lua index 8f57b93..904909a 100644 --- a/locales/ro.lua +++ b/locales/ro.lua @@ -44,7 +44,10 @@ local Translations = { } -Lang = Locale:new({ - phrases = Translations, - warnOnMissing = true -}) +if GetConvar('qb_locale', 'en') == 'ro' then + Lang = Locale:new({ + phrases = Translations, + warnOnMissing = true, + fallbackLang = Lang, + }) +end diff --git a/server/main.lua b/server/main.lua index 490c1e4..a00b4a3 100644 --- a/server/main.lua +++ b/server/main.lua @@ -18,17 +18,7 @@ RegisterNetEvent('qb-vehiclekeys:server:GiveVehicleKeys', function(receiver, pla local giver = source if HasKeys(giver, plate) then - TriggerClientEvent('ox_lib:notify', giver, { - id = 'give_car_keys', - description = Lang:t("notify.gave_keys"), - duration = 5000, - style = { - backgroundColor = '#141517', - color = '#ffffff' - }, - icon = 'check', - iconColor = '#27AE60' - }) + TriggerClientEvent('QBCore:NotifyV2', giver, { id = 'give_car_keys', description = Lang:t("notify.gave_keys") }) if type(receiver) == 'table' then for _,r in ipairs(receiver) do GiveKeys(receiver[r], plate) @@ -37,17 +27,7 @@ RegisterNetEvent('qb-vehiclekeys:server:GiveVehicleKeys', function(receiver, pla GiveKeys(receiver, plate) end else - TriggerClientEvent('ox_lib:notify', giver, { - id = 'server_no_keys', - description = Lang:t("notify.no_keys"), - duration = 5000, - style = { - backgroundColor = '#141517', - color = '#ffffff' - }, - icon = 'xmark', - iconColor = '#C0392B' - }) + TriggerClientEvent('QBCore:NotifyV2', giver, { id = 'server_no_keys', description = Lang:t("notify.no_keys") }) end end) @@ -89,18 +69,8 @@ function GiveKeys(id, plate) if not VehicleList[plate] then VehicleList[plate] = {} end VehicleList[plate][citizenid] = true - - TriggerClientEvent('ox_lib:notify', id, { - id = 'server_id_get_keys', - description = Lang:t("notify.keys_taken"), - duration = 5000, - style = { - backgroundColor = '#141517', - color = '#ffffff' - }, - icon = 'circle-info', - iconColor = '#2980B9' - }) + + TriggerClientEvent('QBCore:NotifyV2', id, { id = 'server_id_get_keys', description = Lang:t("notify.keys_taken") }) TriggerClientEvent('qb-vehiclekeys:client:AddKeys', id, plate) end @@ -122,45 +92,60 @@ function HasKeys(id, plate) return false end -QBCore.Commands.Add("givekeys", Lang:t("addcom.givekeys"), {{name = Lang:t("addcom.givekeys_id"), help = Lang:t("addcom.givekeys_id_help")}}, false, function(source, args) - local src = source +lib.addCommand('givekeys', { + help = Lang:t("addcom.givekeys"), + params = { + { + name = Lang:t("addcom.givekeys_id"), + help = Lang:t("addcom.givekeys_id_help") + }, + }, + restricted = false, +}, function (source, args) + local src = source TriggerClientEvent('qb-vehiclekeys:client:GiveKeys', src, tonumber(args[1])) end) -QBCore.Commands.Add("addkeys", Lang:t("addcom.addkeys"), {{name = Lang:t("addcom.addkeys_id"), help = Lang:t("addcom.addkeys_id_help")}, {name = Lang:t("addcom.addkeys_plate"), help = Lang:t("addcom.addkeys_plate_help")}}, true, function(source, args) - local src = source +lib.addCommand('addkeys', { + help = Lang:t("addcom.addkeys"), + params = { + { + name = Lang:t("addcom.addkeys_id"), + help = Lang:t("addcom.addkeys_id_help") + }, + { + name = Lang:t("addcom.addkeys_plate"), + help = Lang:t("addcom.addkeys_plate_help") + }, + }, + restricted = 'group.admin', +}, function (source, args) + local src = source if not args[1] or not args[2] then - TriggerClientEvent('ox_lib:notify', src, { - id = 'server_notify_fpid', - description = Lang:t("notify.fpid"), - duration = 5000, - style = { - backgroundColor = '#141517', - color = '#ffffff' - }, - icon = 'xmark', - iconColor = '#C0392B' - }) + TriggerClientEvent('QBCore:NotifyV2', src, { id = 'server_notify_fpid', description = Lang:t("notify.fpid") }) return end GiveKeys(tonumber(args[1]), args[2]) -end, 'admin') +end) -QBCore.Commands.Add("removekeys", Lang:t("addcom.remove_keys"), {{name = Lang:t("addcom.remove_keys_id"), help = Lang:t("addcom.remove_keys_id_help")}, {name = Lang:t("addcom.remove_keys_plate"), help = Lang:t("addcom.remove_keys_plate_help")}}, true, function(source, args) - local src = source +lib.addCommand('removekeys', { + help = Lang:t("addcom.remove_keys"), + params = { + { + name = Lang:t("addcom.remove_keys_id"), + help = Lang:t("addcom.remove_keys_id_help") + }, + { + name = Lang:t("addcom.remove_keys_plate"), + help = Lang:t("addcom.remove_keys_plate_help") + } + }, + restricted = 'group.admin', +}, function (source, args) + local src = source if not args[1] or not args[2] then - TriggerClientEvent('ox_lib:notify', src, { - id = 'server_notify_fpid', - description = Lang:t("notify.fpid"), - duration = 5000, - style = { - backgroundColor = '#141517', - color = '#ffffff' - }, - icon = 'xmark', - iconColor = '#C0392B' - }) + TriggerClientEvent('QBCore:NotifyV2', src, { id = 'server_notify_fpid', description = Lang:t("notify.fpid") }) return end RemoveKeys(tonumber(args[1]), args[2]) -end, 'admin') +end)