Skip to content

Commit

Permalink
Merge pull request #34 from MoskalykA/main
Browse files Browse the repository at this point in the history
refactor: caching fines
  • Loading branch information
Gellipapa authored Oct 16, 2023
2 parents 7c16a04 + 752f703 commit 66cb1bb
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 84 deletions.
55 changes: 32 additions & 23 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -521,35 +521,44 @@ function OpenFineMenu(player)
end)
end

local fineList = {}
function OpenFineCategoryMenu(player, category)
ESX.TriggerServerCallback('esx_policejob:getFineList', function(fines)
local elements = {
{unselectable = true, icon = "fas fa-scroll", title = TranslateCap('fine')}
if not fineList[category] then
local p = promise.new()

ESX.TriggerServerCallback('esx_policejob:getFineList', function(fines)
p:resolve(fines)
end, category)

fineList[category] = Citizen.Await(p)
end

local elements = {
{unselectable = true, icon = "fas fa-scroll", title = TranslateCap('fine')}
}

for k,fine in ipairs(fineList[category]) do
elements[#elements+1] = {
icon = "fas fa-scroll",
title = ('%s <span style="color:green;">%s</span>'):format(fine.label, TranslateCap('armory_item', ESX.Math.GroupDigits(fine.amount))),
value = fine.id,
amount = fine.amount,
fineLabel = fine.label
}
end

for k,fine in ipairs(fines) do
elements[#elements+1] = {
icon = "fas fa-scroll",
title = ('%s <span style="color:green;">%s</span>'):format(fine.label, TranslateCap('armory_item', ESX.Math.GroupDigits(fine.amount))),
value = fine.id,
amount = fine.amount,
fineLabel = fine.label
}
ESX.OpenContext("right", elements, function(menu,element)
local data = {current = element}
if Config.EnablePlayerManagement then
TriggerServerEvent('esx_billing:sendBill', GetPlayerServerId(player), 'society_police', TranslateCap('fine_total', data.current.fineLabel), data.current.amount)
else
TriggerServerEvent('esx_billing:sendBill', GetPlayerServerId(player), '', TranslateCap('fine_total', data.current.fineLabel), data.current.amount)
end

ESX.OpenContext("right", elements, function(menu,element)
local data = {current = element}
if Config.EnablePlayerManagement then
TriggerServerEvent('esx_billing:sendBill', GetPlayerServerId(player), 'society_police', TranslateCap('fine_total', data.current.fineLabel), data.current.amount)
else
TriggerServerEvent('esx_billing:sendBill', GetPlayerServerId(player), '', TranslateCap('fine_total', data.current.fineLabel), data.current.amount)
end

ESX.SetTimeout(300, function()
OpenFineCategoryMenu(player, category)
end)
ESX.SetTimeout(300, function()
OpenFineCategoryMenu(player, category)
end)
end, category)
end)
end

function LookupVehicle(elementF)
Expand Down
114 changes: 57 additions & 57 deletions esx_policejob.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ INSERT INTO `addon_inventory` (name, label, shared) VALUES
;

INSERT INTO `jobs` (name, label) VALUES
('police', 'LSPD')
('police', 'Police')
;

INSERT INTO `job_grades` (job_name, grade, name, label, salary, skin_male, skin_female) VALUES
('police',0,'recruit','Recrue',20,'{}','{}'),
('police',1,'officer','Officier',40,'{}','{}'),
('police',2,'sergeant','Sergent',60,'{}','{}'),
('police',0,'recruit','Recruit',20,'{}','{}'),
('police',1,'officer','Officer',40,'{}','{}'),
('police',2,'sergeant','Sergeant',60,'{}','{}'),
('police',3,'lieutenant','Lieutenant',85,'{}','{}'),
('police',4,'boss','Commandant',100,'{}','{}')
('police',4,'boss','Chief',100,'{}','{}')
;

CREATE TABLE `fine_types` (
Expand All @@ -33,56 +33,56 @@ CREATE TABLE `fine_types` (


INSERT INTO `fine_types` (label, amount, category) VALUES
('Usage abusif du klaxon',30,0),
('Franchir une ligne continue',40,0),
('Circulation à contresens',250,0),
('Demi-tour non autorisé',250,0),
('Circulation hors-route',170,0),
('Non-respect des distances de sécurité',30,0),
('Arrêt dangereux / interdit',150,0),
('Stationnement gênant / interdit',70,0),
('Non respect de la priorité à droite',70,0),
('Non-respect à un véhicule prioritaire',90,0),
('Non-respect d\'un stop',105,0),
('Non-respect d\'un feu rouge',130,0),
('Dépassement dangereux',100,0),
('Véhicule non en état',100,0),
('Conduite sans permis',1500,0),
('Délit de fuite',800,0),
('Excès de vitesse < 5 kmh',90,0),
('Excès de vitesse 5-15 kmh',120,0),
('Excès de vitesse 15-30 kmh',180,0),
('Excès de vitesse > 30 kmh',300,0),
('Entrave de la circulation',110,1),
('Dégradation de la voie publique',90,1),
('Trouble à l\'ordre publique',90,1),
('Entrave opération de police',130,1),
('Insulte envers / entre civils',75,1),
('Outrage à agent de police',110,1),
('Menace verbale ou intimidation envers civil',90,1),
('Menace verbale ou intimidation envers policier',150,1),
('Manifestation illégale',250,1),
('Tentative de corruption',1500,1),
('Arme blanche sortie en ville',120,2),
('Arme léthale sortie en ville',300,2),
('Port d\'arme non autorisé (défaut de license)',600,2),
('Port d\'arme illégal',700,2),
('Pris en flag lockpick',300,2),
('Vol de voiture',1800,2),
('Vente de drogue',1500,2),
('Fabriquation de drogue',1500,2),
('Possession de drogue',650,2),
('Prise d\'ôtage civil',1500,2),
('Prise d\'ôtage agent de l\'état',2000,2),
('Braquage particulier',650,2),
('Braquage magasin',650,2),
('Braquage de banque',1500,2),
('Tir sur civil',2000,3),
('Tir sur agent de l\'état',2500,3),
('Tentative de meurtre sur civil',3000,3),
('Tentative de meurtre sur agent de l\'état',5000,3),
('Meurtre sur civil',10000,3),
('Meurte sur agent de l\'état',30000,3),
('Meurtre involontaire',1800,3),
('Escroquerie à l\'entreprise',2000,2)
('Misuse of a horn', 30, 0),
('Illegally Crossing a continuous Line', 40, 0),
('Driving on the wrong side of the road', 250, 0),
('Illegal U-Turn', 250, 0),
('Illegally Driving Off-road', 170, 0),
('Refusing a Lawful Command', 30, 0),
('Illegally Stopping a Vehicle', 150, 0),
('Illegal Parking', 70, 0),
('Failing to Yield to the right', 70, 0),
('Failure to comply with Vehicle Information', 90, 0),
('Failing to stop at a Stop Sign ', 105, 0),
('Failing to stop at a Red Light', 130, 0),
('Illegal Passing', 100, 0),
('Driving an illegal Vehicle', 100, 0),
('Driving without a License', 1500, 0),
('Hit and Run', 800, 0),
('Exceeding Speeds Over < 5 mph', 90, 0),
('Exceeding Speeds Over 5-15 mph', 120, 0),
('Exceeding Speeds Over 15-30 mph', 180, 0),
('Exceeding Speeds Over > 30 mph', 300, 0),
('Impeding traffic flow', 110, 1),
('Public Intoxication', 90, 1),
('Disorderly conduct', 90, 1),
('Obstruction of Justice', 130, 1),
('Insults towards Civilans', 75, 1),
('Disrespecting of an LEO', 110, 1),
('Verbal Threat towards a Civilan', 90, 1),
('Verbal Threat towards an LEO', 150, 1),
('Providing False Information', 250, 1),
('Attempt of Corruption', 1500, 1),
('Brandishing a weapon in city Limits', 120, 2),
('Brandishing a Lethal Weapon in city Limits', 300, 2),
('No Firearms License', 600, 2),
('Possession of an Illegal Weapon', 700, 2),
('Possession of Burglary Tools', 300, 2),
('Grand Theft Auto', 1800, 2),
('Intent to Sell/Distrube of an illegal Substance', 1500, 2),
('Frabrication of an Illegal Substance', 1500, 2),
('Possession of an Illegal Substance ', 650, 2),
('Kidnapping of a Civilan', 1500, 2),
('Kidnapping of an LEO', 2000, 2),
('Robbery', 650, 2),
('Armed Robbery of a Store', 650, 2),
('Armed Robbery of a Bank', 1500, 2),
('Assault on a Civilian', 2000, 3),
('Assault of an LEO', 2500, 3),
('Attempt of Murder of a Civilian', 3000, 3),
('Attempt of Murder of an LEO', 5000, 3),
('Murder of a Civilian', 10000, 3),
('Murder of an LEO', 30000, 3),
('Involuntary manslaughter', 1800, 3),
('Fraud', 2000, 2);
;
15 changes: 11 additions & 4 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,18 @@ ESX.RegisterServerCallback('esx_policejob:getOtherPlayerData', function(source,
end
end)

local fineList = {}
ESX.RegisterServerCallback('esx_policejob:getFineList', function(source, cb, category)
MySQL.query('SELECT * FROM fine_types WHERE category = ?', {category},
function(fines)
cb(fines)
end)
if not fineList[category] then
MySQL.query('SELECT * FROM fine_types WHERE category = ?', {category},
function(fines)
fineList[category] = fines

cb(fines)
end)
else
cb(fineList[category])
end
end)

ESX.RegisterServerCallback('esx_policejob:getVehicleInfos', function(source, cb, plate)
Expand Down

0 comments on commit 66cb1bb

Please sign in to comment.