Skip to content

Commit

Permalink
feat: commands translations, restore optional arguments and remove ke…
Browse files Browse the repository at this point in the history
…yLista state on server fix: lock of packend vehicles refactor: move server function to separate file
  • Loading branch information
artur-michalak committed May 13, 2024
1 parent 51be3c9 commit 6d1c201
Show file tree
Hide file tree
Showing 16 changed files with 248 additions and 214 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"cache",
"QBX",
"locale",
"qbx"
"qbx",
"MySQL"
]
}
2 changes: 1 addition & 1 deletion client/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,4 @@ function public.getVehicleByPlate(plate)
end
end

return public
return public
77 changes: 36 additions & 41 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,46 +87,45 @@ local function areKeysJobShared(veh)
return false
end

local function setVehicleDoorLock(veh, state, anim)
if veh then
if not isBlacklistedVehicle(veh) then
if hasKeys(qbx.getVehiclePlate(veh)) or areKeysJobShared(veh) then
local vehLockStatus = GetVehicleDoorLockStatus(veh)

if anim then
lib.requestAnimDict('anim@mp_player_intmenu@key_fob@')
TaskPlayAnim(cache.ped, 'anim@mp_player_intmenu@key_fob@', 'fob_click', 3.0, 3.0, -1, 49, 0, false, false, false)
end
---manages the opening of locks
---@param vehicle number? The entity number of the vehicle.
---@param state boolean? State of the vehicle lock.
---@param anim any Aniation
local function setVehicleDoorLock(vehicle, state, anim)
if not vehicle then return end
if not isBlacklistedVehicle(vehicle) then
if hasKeys(qbx.getVehiclePlate(vehicle)) or areKeysJobShared(vehicle) then

if anim then
lib.requestAnimDict('anim@mp_player_intmenu@key_fob@')
TaskPlayAnim(cache.ped, 'anim@mp_player_intmenu@key_fob@', 'fob_click', 3.0, 3.0, -1, 49, 0, false, false, false)
end

TriggerServerEvent('InteractSound_SV:PlayWithinDistance', 5, 'lock', 0.3)
NetworkRequestControlOfEntity(veh)
if state then
state = state and 2 or 1
TriggerServerEvent('qb-vehiclekeys:server:setVehLockState', NetworkGetNetworkIdFromEntity(veh), state)
exports.qbx_core:Notify(state == 2 and locale('notify.vehicle_locked') or locale('notify.vehicle_unlocked'), 'inform')
else
if vehLockStatus == 1 then
TriggerServerEvent('qb-vehiclekeys:server:setVehLockState', NetworkGetNetworkIdFromEntity(veh), 2)
exports.qbx_core:Notify(locale('notify.vehicle_locked'), 'inform')
else
TriggerServerEvent('qb-vehiclekeys:server:setVehLockState', NetworkGetNetworkIdFromEntity(veh), 1)
exports.qbx_core:Notify(locale('notify.vehicle_unlocked'), 'inform')
end
end
TriggerServerEvent('InteractSound_SV:PlayWithinDistance', 5, 'lock', 0.3)
NetworkRequestControlOfEntity(vehicle)

SetVehicleLights(veh, 2)
Wait(250)
SetVehicleLights(veh, 1)
Wait(200)
SetVehicleLights(veh, 0)
Wait(300)
ClearPedTasks(cache.ped)
local lockstate
if state then
lockstate = state == true and 2 or 1
else
exports.qbx_core:Notify(locale('notify.no_keys'), 'error')
lockstate = (GetVehicleDoorLockStatus(vehicle) % 2) + 1 -- (1 % 2) + 1 -> 2 (2 % 2) + 1 -> 1
end

TriggerServerEvent('qb-vehiclekeys:server:setVehLockState', NetworkGetNetworkIdFromEntity(vehicle), lockstate)
exports.qbx_core:Notify(locale(lockstate == 2 and 'notify.vehicle_locked' or 'notify.vehicle_unlocked'))

SetVehicleLights(vehicle, 2)
Wait(250)
SetVehicleLights(vehicle, 1)
Wait(200)
SetVehicleLights(vehicle, 0)
Wait(300)
ClearPedTasks(cache.ped)
else
TriggerServerEvent('qb-vehiclekeys:server:setVehLockState', NetworkGetNetworkIdFromEntity(veh), 1)
exports.qbx_core:Notify(locale('notify.no_keys'), 'error')
end
else
TriggerServerEvent('qb-vehiclekeys:server:setVehLockState', NetworkGetNetworkIdFromEntity(vehicle), 1)
end
end

Expand Down Expand Up @@ -333,12 +332,8 @@ CreateThread(function()
end
end
-- Parked car logic
elseif driver == 0 and Entity(entering).state.isOpen == false and not hasKeys(plate) and not isTakingKeys and not Entity(entering).state.vehicleid then
if config.lockNPCParkedCars then
TriggerServerEvent('qb-vehiclekeys:server:setVehLockState', NetworkGetNetworkIdFromEntity(entering), 2)
else
TriggerServerEvent('qb-vehiclekeys:server:setVehLockState', NetworkGetNetworkIdFromEntity(entering), 1)
end
elseif driver == 0 and not Entity(entering).state.isOpen and not hasKeys(plate) and not isTakingKeys and not Entity(entering).state.vehicleid then
TriggerServerEvent('qb-vehiclekeys:server:setVehLockState', NetworkGetNetworkIdFromEntity(entering), config.lockNPCParkedCars and 2 or 1)
end
end

Expand Down Expand Up @@ -451,4 +446,4 @@ end)
RegisterNetEvent('vehiclekeys:client:SetOwner', function(plate)
TriggerServerEvent('qb-vehiclekeys:server:AcquireVehicleKeys', plate)
end)
--#endregion Backwards Compatibility ONLY -- Remove at some point --
--#endregion Backwards Compatibility ONLY -- Remove at some point --
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ dependencies {
}

lua54 'yes'
use_experimental_fxv2_oal 'yes'
use_experimental_fxv2_oal 'yes'
2 changes: 1 addition & 1 deletion locales/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@
"searching_keys": "Hledání klíčů od auta...",
"takekeys": "Odebírání klíčů z těla..."
}
}
}
2 changes: 1 addition & 1 deletion locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@
"searching_keys": "Suche nach Fahrzeugschlüssel...",
"takekeys": "Fahrzeugschlüssel abnehmen..."
}
}
}
19 changes: 11 additions & 8 deletions locales/en.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
{
"addcom": {
"addkeys": "Adds keys to a vehicle for someone.",
"addkeys": "addkeys",
"addkeys_help": "Adds keys to a vehicle for someone.",
"addkeys_id": "id",
"addkeys_id_help": "Player ID",
"addkeys_plate": "plate",
"addkeys_plate_help": "Plate",
"givekeys": "Hand over the keys to someone. If no ID, gives to closest person or everyone in the vehicle.",
"givekeys": "givekeys",
"givekeys_help": "Hand over the keys to someone. If no ID, gives to closest person or everyone in the vehicle.",
"givekeys_id": "id",
"givekeys_id_help": "Player ID",
"givekeys_plate": "plate",
"givekeys_plate_help": "Plate",
"remove_keys": "Remove keys to a vehicle for someone.",
"remove_keys_id": "id",
"remove_keys_id_help": "Player ID",
"remove_keys_plate": "plate",
"remove_keys_plate_help": "Plate"
"removekeys": "removekeys",
"removekeys_help": "Remove keys to a vehicle for someone.",
"removekeys_id": "id",
"removekeys_id_help": "Player ID",
"removekeys_plate": "plate",
"removekeys_plate_help": "Plate"
},
"info": {
"engine": "Toggle Engine",
Expand Down Expand Up @@ -45,4 +48,4 @@
"searching_keys": "Searching for the car keys...",
"takekeys": "Taking keys from body..."
}
}
}
2 changes: 1 addition & 1 deletion locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@
"searching_keys": "Buscando las llaves del carro...",
"takekeys": "Obteniendo las llaves del cuerpo..."
}
}
}
2 changes: 1 addition & 1 deletion locales/et.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@
"searching_keys": "Autovõtmete otsimine...",
"takekeys": "Võtmete kehast võtmine..."
}
}
}
2 changes: 1 addition & 1 deletion locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@
"searching_keys": "Cherche les clés du véhicule..",
"takekeys": "Prend les clés du corps.."
}
}
}
2 changes: 1 addition & 1 deletion locales/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@
"searching_keys": "Sleutels Zoeken...",
"takekeys": "Sleutels van lichaam af halen..."
}
}
}
2 changes: 1 addition & 1 deletion locales/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@
"searching_keys": "Procurando pelas chaves do carro...",
"takekeys": "Tirando as chaves do corpo..."
}
}
}
1 change: 1 addition & 0 deletions locales/ro.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@
"takekeys": "Iei chile de la vehicul..."
}
}

44 changes: 30 additions & 14 deletions server/commands.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
lib.addCommand('givekeys', {
help = locale('addcom.givekeys'),
-----------------------
---- Imports ----
-----------------------

local functions = require 'server.functions'

local removeKeys = functions.removeKeys
local giveKeys = functions.giveKeys

-----------------------
---- Commands ----
-----------------------

lib.addCommand(locale('addcom.givekeys'), {
help = locale('addcom.givekeys_help'),
params = {
{
name = locale('addcom.givekeys_id'),
Expand All @@ -18,8 +31,7 @@ lib.addCommand('givekeys', {
}, function (source, args)
local id = args[locale('addcom.givekeys_id')]
if id and not exports.qbx_core:GetPlayer(id) then
exports.qbx_core:Notify(source, locale('notify.player_offline'), 'error')
return
return exports.qbx_core:Notify(source, locale('notify.player_offline'), 'error')
end

TriggerClientEvent('qb-vehiclekeys:client:GiveKeys', source, id, args[locale('addcom.givekeys_plate')])
Expand All @@ -41,18 +53,20 @@ local function getPlayersVehiclePlate(source, plate)
return plate
end

lib.addCommand('addkeys', {
help = locale('addcom.addkeys'),
lib.addCommand(locale('addcom.addkeys'), {
help = locale('addcom.addkeys_help'),
params = {
{
name = locale('addcom.addkeys_id'),
type = 'playerId',
help = locale('addcom.addkeys_id_help')
help = locale('addcom.addkeys_id_help'),
optional = true
},
{
name = locale('addcom.addkeys_plate'),
type = 'string',
help = locale('addcom.addkeys_plate_help')
help = locale('addcom.addkeys_plate_help'),
optional = true
},
},
restricted = 'group.admin',
Expand All @@ -64,25 +78,27 @@ lib.addCommand('addkeys', {
return exports.qbx_core:Notify(source, locale('notify.fpid'), 'error')
end

if GiveKeys(playerId, plate) then
if giveKeys(playerId, plate) then
return exports.qbx_core:Notify(source, locale('notify.added_keys', plate, playerId), 'success')
end

exports.qbx_core:Notify(source, locale('notify.player_offline'), 'error')
end)

lib.addCommand('removekeys', {
help = locale('addcom.remove_keys'),
lib.addCommand(locale('addcom.removekeys'), {
help = locale('addcom.removekeys_help'),
params = {
{
name = locale('addcom.removekeys_id'),
type = 'playerId',
help = locale('addcom.remove_keys_id_help')
help = locale('addcom.removekeys_id_help'),
optional = true
},
{
name = locale('addcom.removekeys_plate'),
type = 'string',
help = locale('addcom.remove_keys_plate_help')
help = locale('addcom.removekeys_plate_help'),
optional = true
}
},
restricted = 'group.admin',
Expand All @@ -94,7 +110,7 @@ lib.addCommand('removekeys', {
return exports.qbx_core:Notify(source, locale('notify.fpid'), 'error')
end

if RemoveKeys(playerId, plate) then
if removeKeys(playerId, plate) then
return exports.qbx_core:Notify(source, locale('notify.removed_keys', plate, playerId), 'success')
end

Expand Down
Loading

0 comments on commit 6d1c201

Please sign in to comment.