mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-31 10:18:54 +00:00
Use async to limit paying rent
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
# esx_property
|
||||
|
||||
### Requirements
|
||||
|
||||
- [async](https://github.com/ESX-Org/async)
|
||||
- [instance](https://github.com/ESX-Org/instance)
|
||||
- [cron](https://github.com/ESX-Org/cron)
|
||||
- [esx_addonaccount](https://github.com/ESX-Org/esx_addonaccount)
|
||||
@@ -37,7 +39,7 @@ start esx_property
|
||||
### License
|
||||
esx_property - own a property!
|
||||
|
||||
Copyright (C) 2015-2018 Jérémie N'gadi
|
||||
Copyright (C) 2015-2020 Jérémie N'gadi
|
||||
|
||||
This program Is free software: you can redistribute it And/Or modify it under the terms Of the GNU General Public License As published by the Free Software Foundation, either version 3 Of the License, Or (at your option) any later version.
|
||||
|
||||
|
||||
+2
-4
@@ -4,9 +4,7 @@ Config.MarkerSize = {x = 1.5, y = 1.5, z = 1.0}
|
||||
Config.MarkerColor = {r = 102, g = 102, b = 204}
|
||||
Config.RoomMenuMarkerColor = {r = 102, g = 204, b = 102}
|
||||
Config.MarkerType = 1
|
||||
Config.Zones = {}
|
||||
Config.Properties = {}
|
||||
Config.EnablePlayerManagement = false -- If set to true you need esx_realestateagentjob
|
||||
Config.Locale = 'fr'
|
||||
|
||||
Config.Properties = {}
|
||||
Config.EnablePlayerManagement = false -- If set to true you use esx_realestateagentjob
|
||||
Config.Locale = 'fr'
|
||||
|
||||
+3
-1
@@ -7,8 +7,9 @@ description 'ESX Property'
|
||||
version '1.0.4'
|
||||
|
||||
server_scripts {
|
||||
'@es_extended/locale.lua',
|
||||
'@async/async.lua',
|
||||
'@mysql-async/lib/MySQL.lua',
|
||||
'@es_extended/locale.lua',
|
||||
'locales/de.lua',
|
||||
'locales/br.lua',
|
||||
'locales/en.lua',
|
||||
@@ -36,6 +37,7 @@ client_scripts {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
'async',
|
||||
'es_extended',
|
||||
'instance',
|
||||
'cron',
|
||||
|
||||
+26
-14
@@ -416,25 +416,37 @@ AddEventHandler('esx_property:removeOutfit', function(label)
|
||||
end)
|
||||
|
||||
function PayRent(d, h, m)
|
||||
MySQL.Async.fetchAll('SELECT * FROM owned_properties WHERE rented = 1', {}, function (result)
|
||||
local tasks, timeStart = {}, os.clock()
|
||||
print('[esx_property] [^2INFO^7] Paying rent cron job started')
|
||||
|
||||
MySQL.Async.fetchAll('SELECT * FROM owned_properties WHERE rented = 1', {}, function(result)
|
||||
for i=1, #result, 1 do
|
||||
local xPlayer = ESX.GetPlayerFromIdentifier(result[i].owner)
|
||||
table.insert(tasks, function(cb)
|
||||
local xPlayer = ESX.GetPlayerFromIdentifier(result[i].owner)
|
||||
|
||||
-- message player if connected
|
||||
if xPlayer then
|
||||
xPlayer.removeAccountMoney('bank', result[i].price)
|
||||
xPlayer.showNotification(_U('paid_rent', ESX.Math.GroupDigits(result[i].price)))
|
||||
else -- pay rent either way
|
||||
MySQL.Sync.execute('UPDATE users SET bank = bank - @bank WHERE identifier = @identifier', {
|
||||
['@bank'] = result[i].price,
|
||||
['@identifier'] = result[i].owner
|
||||
})
|
||||
end
|
||||
-- message player if connected
|
||||
if xPlayer then
|
||||
xPlayer.removeAccountMoney('bank', result[i].price)
|
||||
xPlayer.showNotification(_U('paid_rent', ESX.Math.GroupDigits(result[i].price)))
|
||||
else -- pay rent either way
|
||||
MySQL.Sync.execute('UPDATE users SET bank = bank - @bank WHERE identifier = @identifier', {
|
||||
['@bank'] = result[i].price,
|
||||
['@identifier'] = result[i].owner
|
||||
})
|
||||
end
|
||||
|
||||
TriggerEvent('esx_addonaccount:getSharedAccount', 'society_realestateagent', function(account)
|
||||
account.addMoney(result[i].price)
|
||||
TriggerEvent('esx_addonaccount:getSharedAccount', 'society_realestateagent', function(account)
|
||||
account.addMoney(result[i].price)
|
||||
end)
|
||||
|
||||
cb()
|
||||
end)
|
||||
end
|
||||
|
||||
Async.parallelLimit(tasks, 5, function(results) end)
|
||||
|
||||
local elapsedTime = os.clock() - timeStart
|
||||
print(('[esx_property] [^2INFO^7] Paying rent cron job took %s seconds'):format(elapsedTime))
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user