Skip to content

Commit

Permalink
refactor(es_extended/server/classes/vehicle): better variable naming
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenshiin13 committed Dec 21, 2024
1 parent efc9117 commit 9c7d7ea
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions [core]/es_extended/server/classes/vehicle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
---@field getEntity fun(self:VehicleClass):number?
---@field getModelHash fun(self:VehicleClass):number?
---@field getOwner fun(self:VehicleClass):string?
---@field setPlate fun(self:VehicleClass, plate:string):boolean
---@field setPlate fun(self:VehicleClass, newPlate:string):boolean
---@field setProps fun(self:VehicleClass, props:table):boolean
---@field setOwner fun(self:VehicleClass, owner:string):boolean
---@field delete fun(self:VehicleClass, garageName:string?, impound:boolean?):nil
---@field setOwner fun(self:VehicleClass, newOwner:string):boolean
---@field delete fun(self:VehicleClass, garageName:string?, isImpound:boolean?):nil
Core.vehicleClass = {
plate = "",
new = function(owner, plate, coords)
Expand Down Expand Up @@ -133,26 +133,26 @@ Core.vehicleClass = {

return Core.vehicles[self.plate].owner
end,
setPlate = function(self, plate)
setPlate = function(self, newPlate)
if not self:isValid() then
return false
end
assert(type(plate) == "string", "Expected 'plate' to be a string")
assert(type(newPlate) == "string", "Expected 'plate' to be a string")

local xVehicle = Core.vehicles[self.plate]
local affectedRows = MySQL.update.await("UPDATE `owned_vehicles` SET `plate` = ? WHERE `plate` = ? AND `owner` = ?", { plate, xVehicle.plate, xVehicle.owner })
local affectedRows = MySQL.update.await("UPDATE `owned_vehicles` SET `plate` = ? WHERE `plate` = ? AND `owner` = ?", { newPlate, xVehicle.plate, xVehicle.owner })
if affectedRows <= 0 then
self:delete()
return false
end

Entity(xVehicle.entity).state:set("plate", plate, false)
SetVehicleNumberPlateText(xVehicle.entity, plate)
Entity(xVehicle.entity).state:set("plate", newPlate, false)
SetVehicleNumberPlateText(xVehicle.entity, newPlate)

local oldPlate = xVehicle.plate
xVehicle.plate = plate
Core.vehicles[plate] = table.clone(xVehicle)
Core.vehicles[self.plate] = nil
xVehicle.plate = newPlate
Core.vehicles[newPlate] = table.clone(xVehicle)
Core.vehicles[oldPlate] = nil

TriggerEvent("esx:changedExtendedVehiclePlate", xVehicle.plate, oldPlate)
Wait(0)
Expand All @@ -176,34 +176,34 @@ Core.vehicleClass = {

return true
end,
setOwner = function(self, owner)
setOwner = function(self, newOwner)
if not self:isValid() then
return false
end
assert(type(owner) == "string", "Expected 'owner' to be a string")
assert(type(newOwner) == "string", "Expected 'owner' to be a string")

local xVehicle = Core.vehicles[self.plate]
if xVehicle.owner == owner then
if xVehicle.owner == newOwner then
return true
end

local affectedRows = MySQL.update.await("UPDATE `owned_vehicles` SET `owner` = ? WHERE owner = ? AND `plate` = ?", { owner, xVehicle.owner, xVehicle.plate })
local affectedRows = MySQL.update.await("UPDATE `owned_vehicles` SET `owner` = ? WHERE owner = ? AND `plate` = ?", { newOwner, xVehicle.owner, xVehicle.plate })
if affectedRows <= 0 then
self:delete()
return false
end

Entity(xVehicle.entity).state:set("owner", owner, false)
xVehicle.owner = owner
Entity(xVehicle.entity).state:set("owner", newOwner, false)
xVehicle.owner = newOwner

return true
end,
delete = function(self, garageName, impound)
delete = function(self, garageName, isImpound)
if type(garageName) ~= "string" then
garageName = nil
end
if type(impound) ~= "boolean" then
impound = false
if type(isImpound) ~= "boolean" then
isImpound = false
end

local xVehicle = Core.vehicles[self.plate]
Expand All @@ -219,7 +219,7 @@ Core.vehicleClass = {
local query = "UPDATE `owned_vehicles` SET `stored` = true WHERE `plate` = ? AND `owner` = ?"
local queryParams = { xVehicle.plate, xVehicle.owner }
if garageName then
if impound then
if isImpound then
query = "UPDATE `owned_vehicles` SET `stored` = true, `parking` = NULL, `pound` = ? WHERE `plate` = ? AND `owner` = ?"
else
query = "UPDATE `owned_vehicles` SET `stored` = true, `pound` = NULL, `parking` = ? WHERE `plate` = ? AND `owner` = ?"
Expand Down

0 comments on commit 9c7d7ea

Please sign in to comment.