From 1b5c7405a580c74bee3af7e6b94e3320f4f79f08 Mon Sep 17 00:00:00 2001 From: ElPumpo Date: Fri, 4 May 2018 18:08:03 +0200 Subject: [PATCH] Fixed paying rent (fixes #30), fixed #33 --- client/main.lua | 5 +-- locales/br.lua | 2 +- locales/de.lua | 2 +- locales/en.lua | 2 +- locales/fr.lua | 2 +- locales/sv.lua | 2 +- server/main.lua | 86 +++++++++++++++---------------------------------- 7 files changed, 34 insertions(+), 67 deletions(-) diff --git a/client/main.lua b/client/main.lua index 18a6b1ab..aee80467 100644 --- a/client/main.lua +++ b/client/main.lua @@ -420,6 +420,7 @@ function OpenResellerMenu () if closestPlayer == -1 or closestDistance > 3.0 then ESX.ShowNotification(_U('no_players')) else + SetVehicleNumberPlateText(LastVehicles[#LastVehicles], string.upper(ESX.GetRandomString(8))) local vehicleProps = ESX.Game.GetVehicleProperties(LastVehicles[#LastVehicles]) local model = CurrentVehicleData.model @@ -441,6 +442,7 @@ function OpenResellerMenu () ESX.ShowNotification(_U('no_players')) else ESX.TriggerServerCallback('esx:getOtherPlayerData', function (xPlayer) + SetVehicleNumberPlateText(LastVehicles[#LastVehicles], string.upper(ESX.GetRandomString(8))) local vehicleProps = ESX.Game.GetVehicleProperties(LastVehicles[#LastVehicles]) local model = CurrentVehicleData.model @@ -475,8 +477,7 @@ function OpenResellerMenu () if closestPlayer == -1 or closestDistance > 5.0 then ESX.ShowNotification(_U('no_players')) else - SetVehicleNumberPlateText(LastVehicles[#LastVehicles], 'LOC ' .. ESX.GetRandomString(5)) - + SetVehicleNumberPlateText(LastVehicles[#LastVehicles], 'RENT' .. string.upper(ESX.GetRandomString(4))) local vehicleProps = ESX.Game.GetVehicleProperties(LastVehicles[#LastVehicles]) local model = CurrentVehicleData.model diff --git a/locales/br.lua b/locales/br.lua index d2cc5dde..072268bd 100644 --- a/locales/br.lua +++ b/locales/br.lua @@ -22,7 +22,7 @@ Locales['br'] = { ['not_enough_money'] = 'você não tem dinheiro suficiente', ['not_rental'] = 'isso não é um ~r~veículo de aluguel~s~', ['not_yours'] = 'este veículo não pertence a você', - ['paid_rental'] = 'Você tem ~g~pago~s~ para o seu aluguel de veiculos : ~g~$', + ['paid_rental'] = 'Você tem ~g~pago~s~ para o seu aluguel de veiculos: ~g~$%s~s~', ['personal_vehicle'] = 'veículo pessoal', ['pop_vehicle'] = 'sai do veiculo', ['recruit'] = 'Recrutar', diff --git a/locales/de.lua b/locales/de.lua index ff94f59b..ca5369dd 100644 --- a/locales/de.lua +++ b/locales/de.lua @@ -22,7 +22,7 @@ Locales['de'] = { ['not_enough_money'] = 'du hast nicht genug Geld', ['not_rental'] = 'dies ist kein ~r~Mietwagen~s~', ['not_yours'] = 'dieses Fahrzeug gehört dir nicht', - ['paid_rental'] = 'du ~g~bezahlst~s~ für den Mietwagen : ~g~$', + ['paid_rental'] = 'du ~g~bezahlst~s~ für den Mietwagen: ~g~$%s~s~', ['personal_vehicle'] = 'Persönliches Fahrzeug', ['pop_vehicle'] = 'Fahrzeug holen', ['recruit'] = 'Neuling', diff --git a/locales/en.lua b/locales/en.lua index 4b218d62..be11c973 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -27,7 +27,7 @@ Locales['en'] = { ['not_enough_money'] = 'you do not have enough money', ['not_rental'] = 'this is not a ~r~rental vehicle~s~', ['not_yours'] = 'this vehicle does not belong to you', - ['paid_rental'] = 'you have ~g~payed~s~ for your vehicle rental : ~g~$', + ['paid_rental'] = 'you have ~g~payed~s~ for your vehicle rental: ~g~$%s~s~', ['personal_vehicle'] = 'personal vehicle', ['pop_vehicle'] = 'put out vehicle for sale', ['recruit'] = 'recruit', diff --git a/locales/fr.lua b/locales/fr.lua index ad4edc79..80ab37f3 100644 --- a/locales/fr.lua +++ b/locales/fr.lua @@ -25,7 +25,7 @@ Locales['fr'] = { ['not_enough_money'] = 'Vous n\'avez pas assez d\'argent', ['not_rental'] = 'Ce n\'est pas un ~r~véhicule de location~s~', ['not_yours'] = 'Ce véhicule ne vous appartient pas', - ['paid_rental'] = 'Vous avez ~g~payé~s~ votre location de véhicule : ~g~$', + ['paid_rental'] = 'Vous avez ~g~payé~s~ votre location de véhicule: ~g~$%s~s~', ['personal_vehicle'] = 'Véhicule personnel', ['pop_vehicle'] = 'Sortir véhicule', ['recruit'] = 'Recrue', diff --git a/locales/sv.lua b/locales/sv.lua index 0ac2339e..21f1d590 100644 --- a/locales/sv.lua +++ b/locales/sv.lua @@ -27,7 +27,7 @@ Locales['sv'] = { ['not_enough_money'] = 'Du har inte tillräckligt mycket pengar', ['not_rental'] = 'Detta är inte ett~r~uthyrt fordon~s~', ['not_yours'] = 'Det här fordonet tillhör inte dig', - ['paid_rental'] = 'Du har ~g~betalat~s~ för din hyrning : ~g~$', + ['paid_rental'] = 'du har ~y~betalat~s~ ditt hyrda fordon: ~g~$%s~s~', ['personal_vehicle'] = 'Privat fordon', ['pop_vehicle'] = 'Ställ ut fordon till salu', ['recruit'] = 'Anställ', diff --git a/server/main.lua b/server/main.lua index 82eaa36e..9fb3e8fd 100644 --- a/server/main.lua +++ b/server/main.lua @@ -423,70 +423,36 @@ ESX.RegisterServerCallback('esx_vehicleshop:getPlayerInventory', function (sourc end) if Config.EnablePvCommand then - TriggerEvent('es:addCommand', 'pv', function (source, args, user) - TriggerClientEvent('esx_vehicleshop:openPersonnalVehicleMenu', source) - end, {help = _U('leaving')}) + TriggerEvent('es:addGroupCommand', 'pv', 'user', function(source, args, user) + TriggerClientEvent('esx_vehicleshop:openPersonnalVehicleMenu', source) + end, {help = _U('leaving')}) end -function PayRent (d, h, m) - MySQL.Async.fetchAll( - 'SELECT * FROM users', - {}, - function (_users) - local prevMoney = {} - local newMoney = {} +function PayRent() + MySQL.Async.fetchAll( + 'SELECT * FROM rented_vehicles', {}, + function (result) + for i=1, #result, 1 do + local xPlayer = ESX.GetPlayerFromIdentifier(result[i].owner) - for i=1, #_users, 1 do - prevMoney[_users[i].identifier] = _users[i].money - newMoney[_users[i].identifier] = _users[i].money - end + -- message player if connected + if xPlayer ~= nil then + xPlayer.removeBank(result[i].rent_price) + TriggerClientEvent('esx:showNotification', xPlayer.source, _U('paid_rental', result[i].rent_price)) + else -- pay rent either way + MySQL.Sync.execute( + 'UPDATE users SET bank = bank - @bank WHERE identifier = @identifier', + { + ['@bank'] = result[i].rent_price, + ['@identifier'] = result[i].owner + }) + end - MySQL.Async.fetchAll( - 'SELECT * FROM rented_vehicles', - {}, - function (result) - local xPlayers = ESX.GetPlayers() - - for i=1, #result, 1 do - local foundPlayer = false - local xPlayer = nil - - for i=1, #xPlayers, 1 do - local xPlayer2 = ESX.GetPlayerFromId(xPlayers[i]) - - if xPlayer2.identifier == result[i].owner then - foundPlayer = true - xPlayer = xPlayer2 - end - end - - if foundPlayer then - xPlayer.removeMoney(result[i].rent_price) - TriggerClientEvent('esx:showNotification', xPlayer.source, _U('paid_rental') .. result[i].rent_price) - else - newMoney[result[i].owner] = newMoney[result[i].owner] - result[i].rent_price - end - - TriggerEvent('esx_addonaccount:getSharedAccount', 'society_cardealer', function(account) - account.addMoney(result[i].rent_price) - end) - end - - for k,v in pairs(prevMoney) do - if v ~= newMoney[k] then - MySQL.Async.execute( - 'UPDATE users SET money = @money WHERE identifier = @identifier', - { - ['@money'] = newMoney[k], - ['@identifier'] = k, - } - ) - end - end - end - ) - end - ) + TriggerEvent('esx_addonaccount:getSharedAccount', 'society_cardealer', function(account) + account.addMoney(result[i].rent_price) + end) + end + end) end TriggerEvent('cron:runAt', 22, 00, PayRent)