refactor(vehicleKey): enhance key management functions with assertions, improved documentation and remove vehicle keys where they was missing

This commit is contained in:
XenoS-ITA committed 2025-08-21 01:23:58 +02:00
1 parent 3289711297
commit 9e810d4b24
13 files changed
+271 -44

No files matched your search

@@ -1,15 +1,39 @@
---@diagnostic disable: duplicate-set-field
local resourceName = "F_RealCarKeysSystem"
if GetResourceState(resourceName) == 'missing' then return end
VehicleKey = VehicleKey or {}
---Gives the player (self) the keys of the specified vehicle.
---@param vehicle number The vehicle entity handle.
---@param plate? string The plate of the vehicle.
---@return nil
VehicleKey.GiveKeys = function(vehicle, plate)
if not plate then return false end
assert(vehicle, "vehicle is nil")
assert(DoesEntityExist(vehicle), "vehicle does not exist")
if not plate then
plate = GetVehicleNumberPlateText(vehicle)
end
TriggerServerEvent('F_RealCarKeysSystem:generateVehicleKeys', plate)
end
-- TODO: Test, documentation of the script is missing
---Removes the keys of the specified vehicle from the player (self).
---@param vehicle number The vehicle entity handle.
---@param plate? string The plate of the vehicle.
---@return nil
VehicleKey.RemoveKeys = function(vehicle, plate)
return true
assert(vehicle, "vehicle is nil")
assert(DoesEntityExist(vehicle), "vehicle does not exist")
if not plate then
plate = GetVehicleNumberPlateText(vehicle)
end
TriggerServerEvent('F_RealCarKeysSystem:removeVehicleKeysByPlate', plate)
end
return VehicleKey
@@ -4,13 +4,33 @@ if GetResourceState(resourceName) == 'missing' then return end
VehicleKey = VehicleKey or {}
---Gives the player (self) the keys of the specified vehicle.
---@param vehicle number The vehicle entity handle.
---@param plate? string The plate of the vehicle.
---@return nil
VehicleKey.GiveKeys = function(vehicle, plate)
if not plate then return false end
assert(vehicle, "vehicle is nil")
assert(DoesEntityExist(vehicle), "vehicle does not exist")
if not plate then
plate = GetVehicleNumberPlateText(vehicle)
end
return exports.MrNewbVehicleKeys:GiveKeysByPlate(plate)
end
---Removes the keys of the specified vehicle from the player (self).
---@param vehicle number The vehicle entity handle.
---@param plate? string The plate of the vehicle.
---@return nil
VehicleKey.RemoveKeys = function(vehicle, plate)
if not plate then return false end
assert(vehicle, "vehicle is nil")
assert(DoesEntityExist(vehicle), "vehicle does not exist")
if not plate then
plate = GetVehicleNumberPlateText(vehicle)
end
return exports.MrNewbVehicleKeys:RemoveKeysByPlate(plate)
end
@@ -4,13 +4,33 @@ if GetResourceState(resourceName) == 'missing' then return end
VehicleKey = VehicleKey or {}
---Gives the player (self) the keys of the specified vehicle.
---@param vehicle number The vehicle entity handle.
---@param plate? string The plate of the vehicle.
---@return nil
VehicleKey.GiveKeys = function(vehicle, plate)
if not plate then return false end
assert(vehicle, "vehicle is nil")
assert(DoesEntityExist(vehicle), "vehicle does not exist")
if not plate then
plate = GetVehicleNumberPlateText(vehicle)
end
return exports['Renewed-Vehiclekeys']:addKey(plate)
end
---Removes the keys of the specified vehicle from the player (self).
---@param vehicle number The vehicle entity handle.
---@param plate? string The plate of the vehicle.
---@return nil
VehicleKey.RemoveKeys = function(vehicle, plate)
if not plate then return false end
assert(vehicle, "vehicle is nil")
assert(DoesEntityExist(vehicle), "vehicle does not exist")
if not plate then
plate = GetVehicleNumberPlateText(vehicle)
end
return exports['Renewed-Vehiclekeys']:removeKey(plate)
end
+10 -9
View File
@@ -1,19 +1,20 @@
---@diagnostic disable: duplicate-set-field
VehicleKey = VehicleKey or {}
---This will give keys to the specifed vehicle/plate.
---@param vehicle number The vehicle entity ID.
---@param plate string The plate of the vehicle.
---Gives the player (self) the keys of the specified vehicle.
---@param vehicle number The vehicle entity handle.
---@param plate? string The plate of the vehicle.
---@return nil
VehicleKey.GiveKeys = function(vehicle, plate)
return true, Prints.Error("There Is No Vehicle Key System Installed")
Prints.Info("There is no compatible vehicle key resource.")
end
---This will remove keys from the specifed vehicle/plate.
---@param vehicle number The vehicle entity ID.
---@param plate string The plate of the vehicle.
---@return boolean | nil
---Removes the keys of the specified vehicle from the player (self).
---@param vehicle number The vehicle entity handle.
---@param plate? string The plate of the vehicle.
---@return nil
VehicleKey.RemoveKeys = function(vehicle, plate)
return true, Prints.Error("There Is No Vehicle Key System Installed")
Prints.Info("There is no compatible vehicle key resource.")
end
return VehicleKey
+16 -2
View File
@@ -4,13 +4,27 @@ if GetResourceState(resourceName) == 'missing' then return end
VehicleKey = VehicleKey or {}
---Gives the player (self) the keys of the specified vehicle.
---@param vehicle number The vehicle entity handle.
---@param plate? string The plate of the vehicle.
---@return nil
VehicleKey.GiveKeys = function(vehicle, plate)
if not plate then return false end
assert(vehicle, "vehicle is nil")
assert(DoesEntityExist(vehicle), "vehicle does not exist")
if not plate then
plate = GetVehicleNumberPlateText(vehicle)
end
TriggerEvent('cd_garage:AddKeys', plate)
end
---Removes the keys of the specified vehicle from the player (self).
---@param vehicle number The vehicle entity handle.
---@param plate? string The plate of the vehicle.
---@return nil
VehicleKey.RemoveKeys = function(vehicle, plate)
return true
Prints.Info("cd_garage doesnt support removing keys.")
end
return VehicleKey
+24 -4
View File
@@ -4,14 +4,34 @@ if GetResourceState(resourceName) == 'missing' then return end
VehicleKey = VehicleKey or {}
---Gives the player (self) the keys of the specified vehicle.
---@param vehicle number The vehicle entity handle.
---@param plate? string The plate of the vehicle.
---@return nil
VehicleKey.GiveKeys = function(vehicle, plate)
if not plate then return false end
return TriggerServerEvent("vehicles_keys:selfGiveVehicleKeys", plate)
assert(vehicle, "vehicle is nil")
assert(DoesEntityExist(vehicle), "vehicle does not exist")
if not plate then
plate = GetVehicleNumberPlateText(vehicle)
end
TriggerServerEvent("vehicles_keys:selfGiveVehicleKeys", plate)
end
---Removes the keys of the specified vehicle from the player (self).
---@param vehicle number The vehicle entity handle.
---@param plate? string The plate of the vehicle.
---@return nil
VehicleKey.RemoveKeys = function(vehicle, plate)
if not plate then return false end
return TriggerServerEvent("vehicles_keys:selfRemoveKeys", plate)
assert(vehicle, "vehicle is nil")
assert(DoesEntityExist(vehicle), "vehicle does not exist")
if not plate then
plate = GetVehicleNumberPlateText(vehicle)
end
TriggerServerEvent("vehicles_keys:selfRemoveKeys", plate)
end
return VehicleKey
@@ -1,16 +1,29 @@
---@diagnostic disable: duplicate-set-field
local resourceName = "mk_vehiclekeys"
if GetResourceState(resourceName) == 'missing' then return end
VehicleKey = VehicleKey or {}
---Gives the player (self) the keys of the specified vehicle.
---@param vehicle number The vehicle entity handle.
---@param plate? string The plate of the vehicle.
---@return nil
VehicleKey.GiveKeys = function(vehicle, plate)
if not vehicle and not DoesEntityExist(vehicle) then return false end
return exports["mk_vehiclekeys"]:AddKey(vehicle)
assert(vehicle, "vehicle is nil")
assert(DoesEntityExist(vehicle), "vehicle does not exist")
exports["mk_vehiclekeys"]:AddKey(vehicle)
end
---Removes the keys of the specified vehicle from the player (self).
---@param vehicle number The vehicle entity handle.
---@param plate? string The plate of the vehicle.
---@return nil
VehicleKey.RemoveKeys = function(vehicle, plate)
if not vehicle and not DoesEntityExist(vehicle) then return false end
return exports["mk_vehiclekeys"]:RemoveKey(vehicle)
assert(vehicle, "vehicle is nil")
assert(DoesEntityExist(vehicle), "vehicle does not exist")
exports["mk_vehiclekeys"]:RemoveKey(vehicle)
end
return VehicleKey
@@ -4,13 +4,35 @@ if GetResourceState(resourceName) == 'missing' then return end
VehicleKey = VehicleKey or {}
---Gives the player (self) the keys of the specified vehicle.
---@param vehicle number The vehicle entity handle.
---@param plate? string The plate of the vehicle.
---@return nil
VehicleKey.GiveKeys = function(vehicle, plate)
if not plate then return false end
assert(vehicle, "vehicle is nil")
assert(DoesEntityExist(vehicle), "vehicle does not exist")
if not plate then
plate = GetVehicleNumberPlateText(vehicle)
end
TriggerServerEvent('okokGarage:GiveKeys', plate)
end
---Removes the keys of the specified vehicle from the player (self).
---@param vehicle number The vehicle entity handle.
---@param plate? string The plate of the vehicle.
---@return nil
VehicleKey.RemoveKeys = function(vehicle, plate)
return true
assert(vehicle, "vehicle is nil")
assert(DoesEntityExist(vehicle), "vehicle does not exist")
if not plate then
plate = GetVehicleNumberPlateText(vehicle)
end
local source = GetPlayerServerId(PlayerId())
TriggerServerEvent("okokGarage:RemoveKeys", plate, source)
end
return VehicleKey
@@ -4,13 +4,33 @@ if GetResourceState(resourceName) == 'missing' then return end
VehicleKey = VehicleKey or {}
---Gives the player (self) the keys of the specified vehicle.
---@param vehicle number The vehicle entity handle.
---@param plate? string The plate of the vehicle.
---@return nil
VehicleKey.GiveKeys = function(vehicle, plate)
if not plate then return false end
assert(vehicle, "vehicle is nil")
assert(DoesEntityExist(vehicle), "vehicle does not exist")
if not plate then
plate = GetVehicleNumberPlateText(vehicle)
end
TriggerServerEvent("qb-vehiclekeys:server:AcquireVehicleKeys", plate)
end
---Removes the keys of the specified vehicle from the player (self).
---@param vehicle number The vehicle entity handle.
---@param plate? string The plate of the vehicle.
---@return nil
VehicleKey.RemoveKeys = function(vehicle, plate)
if not plate then return false end
assert(vehicle, "vehicle is nil")
assert(DoesEntityExist(vehicle), "vehicle does not exist")
if not plate then
plate = GetVehicleNumberPlateText(vehicle)
end
TriggerEvent("qb-vehiclekeys:client:RemoveKeys", plate)
end
@@ -4,13 +4,34 @@ if GetResourceState(resourceName) == 'missing' then return end
VehicleKey = VehicleKey or {}
---Gives the player (self) the keys of the specified vehicle.
---@param vehicle number The vehicle entity handle.
---@param plate? string The plate of the vehicle.
---@return nil
VehicleKey.GiveKeys = function(vehicle, plate)
if not plate then return false end
TriggerServerEvent('qb-vehiclekeys:server:AcquireVehicleKeys', plate)
assert(vehicle, "vehicle is nil")
assert(DoesEntityExist(vehicle), "vehicle does not exist")
if not plate then
plate = GetVehicleNumberPlateText(vehicle)
end
TriggerServerEvent("qb-vehiclekeys:server:AcquireVehicleKeys", plate)
end
---Removes the keys of the specified vehicle from the player (self).
---@param vehicle number The vehicle entity handle.
---@param plate? string The plate of the vehicle.
---@return nil
VehicleKey.RemoveKeys = function(vehicle, plate)
return true
assert(vehicle, "vehicle is nil")
assert(DoesEntityExist(vehicle), "vehicle does not exist")
if not plate then
plate = GetVehicleNumberPlateText(vehicle)
end
TriggerEvent("qb-vehiclekeys:client:RemoveKeys", plate)
end
return VehicleKey
@@ -4,18 +4,36 @@ if GetResourceState(resourceName) == 'missing' then return end
VehicleKey = VehicleKey or {}
---Gives the player (self) the keys of the specified vehicle.
---@param vehicle number The vehicle entity handle.
---@param plate? string The plate of the vehicle.
---@return nil
VehicleKey.GiveKeys = function(vehicle, plate)
if not vehicle then return false end
assert(vehicle, "vehicle is nil")
assert(DoesEntityExist(vehicle), "vehicle does not exist")
if not plate then
plate = GetVehicleNumberPlateText(vehicle)
end
local model = GetDisplayNameFromVehicleModel(GetEntityModel(vehicle))
local verifiedPlate = GetVehicleNumberPlateText(vehicle)
return exports['qs-vehiclekeys']:GiveKeys(verifiedPlate, model, true)
return exports['qs-vehiclekeys']:GiveKeys(plate, model, true)
end
---Removes the keys of the specified vehicle from the player (self).
---@param vehicle number The vehicle entity handle.
---@param plate? string The plate of the vehicle.
---@return nil
VehicleKey.RemoveKeys = function(vehicle, plate)
if not vehicle then return false end
assert(vehicle, "vehicle is nil")
assert(DoesEntityExist(vehicle), "vehicle does not exist")
if not plate then
plate = GetVehicleNumberPlateText(vehicle)
end
local model = GetDisplayNameFromVehicleModel(GetEntityModel(vehicle))
local verifiedPlate = GetVehicleNumberPlateText(vehicle)
return exports['qs-vehiclekeys']:RemoveKeys(verifiedPlate, model)
return exports['qs-vehiclekeys']:RemoveKeys(plate, model)
end
return VehicleKey
@@ -4,14 +4,28 @@ if GetResourceState(resourceName) == 'missing' then return end
VehicleKey = VehicleKey or {}
---Gives the player (self) the keys of the specified vehicle.
---@param vehicle number The vehicle entity handle.
---@param plate? string The plate of the vehicle.
---@return nil
VehicleKey.GiveKeys = function(vehicle, plate)
if not DoesEntityExist(vehicle) then return false end
local vehicle_display_name = GetDisplayNameFromVehicleModel(GetEntityModel(vehicle))
return exports['t1ger_keys']:GiveTemporaryKeys(plate, vehicle_display_name, 'some_keys')
assert(vehicle, "vehicle is nil")
assert(DoesEntityExist(vehicle), "vehicle does not exist")
if not plate then
plate = GetVehicleNumberPlateText(vehicle)
end
local model = GetDisplayNameFromVehicleModel(GetEntityModel(vehicle))
return exports['t1ger_keys']:GiveTemporaryKeys(plate, model, '')
end
---Removes the keys of the specified vehicle from the player (self).
---@param vehicle number The vehicle entity handle.
---@param plate? string The plate of the vehicle.
---@return nil
VehicleKey.RemoveKeys = function(vehicle, plate)
Prints.Info("t1ger_keys doesnt support removing keys.")
end
return VehicleKey
@@ -4,13 +4,33 @@ if GetResourceState(resourceName) == 'missing' then return end
VehicleKey = VehicleKey or {}
---Gives the player (self) the keys of the specified vehicle.
---@param vehicle number The vehicle entity handle.
---@param plate? string The plate of the vehicle.
---@return nil
VehicleKey.GiveKeys = function(vehicle, plate)
if not plate and vehicle then plate = GetVehicleNumberPlateText(vehicle) end
assert(vehicle, "vehicle is nil")
assert(DoesEntityExist(vehicle), "vehicle does not exist")
if not plate then
plate = GetVehicleNumberPlateText(vehicle)
end
exports.wasabi_carlock:GiveKey(plate)
end
---Removes the keys of the specified vehicle from the player (self).
---@param vehicle number The vehicle entity handle.
---@param plate? string The plate of the vehicle.
---@return nil
VehicleKey.RemoveKeys = function(vehicle, plate)
if not plate and vehicle then plate = GetVehicleNumberPlateText(vehicle) end
assert(vehicle, "vehicle is nil")
assert(DoesEntityExist(vehicle), "vehicle does not exist")
if not plate then
plate = GetVehicleNumberPlateText(vehicle)
end
exports.wasabi_carlock:RemoveKey(plate)
end