diff --git a/locales/br.lua b/locales/br.lua index 98d5e412..0ff61d99 100644 --- a/locales/br.lua +++ b/locales/br.lua @@ -30,7 +30,8 @@ Locales['br'] = { ['press_to_exit'] = 'Pressione ~INPUT_CONTEXT~ para sair da propriedade', ['not_enough'] = 'Você não tem dinheiro suficiente', ['invalid_quantity'] = 'Quantidade inválida', - ['paid_rent'] = 'Você ~g~pagou~s~ seu aluguel: ~g~$%s~s~', + ['paid_rent'] = 'you paid your rent at ~g~$%s~s~ for ~y~%s~s~', + ['paid_rent_evicted'] = 'you have been ~o~evicted~s~ from ~y~%s~s~ for not affording rent at ~g~$%s~s~', ['not_enough_in_property'] = 'não há o suficiente de que esse item esteja na propriedade!', ['player_cannot_hold'] = 'você não tem espaço suficiente em seu inventário!', } diff --git a/locales/de.lua b/locales/de.lua index 9373025a..c50ebd84 100644 --- a/locales/de.lua +++ b/locales/de.lua @@ -28,11 +28,10 @@ Locales['de'] = { ['amount'] = 'Anzahlt?', ['amount_invalid'] = 'Ungültiger Wert', ['press_to_exit'] = 'Drücke ~INPUT_CONTEXT~ um die Immobilie zu verlassen', - ['rent_for'] = 'Du hast eine Immobilie gemietet ~g~$%s~s~', - ['purchased_for'] = 'Du hast eine Immobilie gekauft ~g~$%s~s~', ['not_enough'] = 'du hast nicht genug Geld', ['invalid_quantity'] = 'Ungültiger Betrag', - ['paid_rent'] = 'du ~g~bezahlst~s~ deine Miete: ~g~$%s~s~', + ['paid_rent'] = 'you paid your rent at ~g~$%s~s~ for ~y~%s~s~', + ['paid_rent_evicted'] = 'you have been ~o~evicted~s~ from ~y~%s~s~ for not affording rent at ~g~$%s~s~', ['not_enough_in_property'] = 'there\'s not enough of ~r~that item~s~ in the property!', ['player_cannot_hold'] = 'you do ~r~not~s~ have enough ~y~free space~s~ in your inventory!', } diff --git a/locales/en.lua b/locales/en.lua index 75d34bda..61296a87 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -30,7 +30,8 @@ Locales['en'] = { ['press_to_exit'] = 'press ~INPUT_CONTEXT~ to exit the property', ['not_enough'] = 'you do not have enough money', ['invalid_quantity'] = 'invalid quantity', - ['paid_rent'] = 'you ~g~paid~s~ your rent: ~g~$%s~s~', + ['paid_rent'] = 'you paid your rent at ~g~$%s~s~ for ~y~%s~s~', + ['paid_rent_evicted'] = 'you have been ~o~evicted~s~ from ~y~%s~s~ for not affording rent at ~g~$%s~s~', ['not_enough_in_property'] = 'there\'s not enough of ~r~that item~s~ in the property!', ['player_cannot_hold'] = 'you do ~r~not~s~ have enough ~y~free space~s~ in your inventory!', } diff --git a/locales/es.lua b/locales/es.lua index 387ff6c0..98966c72 100644 --- a/locales/es.lua +++ b/locales/es.lua @@ -30,7 +30,8 @@ Locales['es'] = { ['press_to_exit'] = 'Presione ~INPUT_CONTEXT~ para salir de la propiedad', ['not_enough'] = 'n\'No tiene suficiente d\'dinero', ['invalid_quantity'] = 'Cantidad inválida', - ['paid_rent'] = 'Has ~g~pagado~s~ por el alquiler: ~g~€%s~s~', + ['paid_rent'] = 'you paid your rent at ~g~€%s~s~ for ~y~%s~s~', + ['paid_rent_evicted'] = 'you have been ~o~evicted~s~ from ~y~%s~s~ for not affording rent at ~g~€%s~s~', ['not_enough_in_property'] = 'there\'s not enough of ~r~that item~s~ in the property!', ['player_cannot_hold'] = 'you do ~r~not~s~ have enough ~y~free space~s~ in your inventory!', } diff --git a/locales/fi.lua b/locales/fi.lua index ffebd828..e52417be 100644 --- a/locales/fi.lua +++ b/locales/fi.lua @@ -30,7 +30,8 @@ Locales['fi'] = { ['press_to_exit'] = 'paina ~INPUT_CONTEXT~ poistuaksesi kiinteistöstä', ['not_enough'] = 'sinulla ei ole tarpeeksi rahaa', ['invalid_quantity'] = 'virheellinen määrä', - ['paid_rent'] = 'sinä ~g~maksoit~s~ vuokraasi: ~g~$%s~s~', + ['paid_rent'] = 'you paid your rent at ~g~$%s~s~ for ~y~%s~s~', + ['paid_rent_evicted'] = 'you have been ~o~evicted~s~ from ~y~%s~s~ for not affording rent at ~g~$%s~s~', ['not_enough_in_property'] = 'täällä ei ole enempää ~r~tätä itemiä~s~ tässä kiinteistössä!', ['player_cannot_hold'] = 'sinulla ~r~ei ole~s~ tarpeeksi ~y~vapaata tilaa~s~ repussasi!', } diff --git a/locales/fr.lua b/locales/fr.lua index ad663e14..ed734e23 100644 --- a/locales/fr.lua +++ b/locales/fr.lua @@ -30,7 +30,8 @@ Locales['fr'] = { ['press_to_exit'] = 'appuyez sur ~INPUT_CONTEXT~ pour sortir de la propriété', ['not_enough'] = 'vous n\'avez pas assez d\'argent', ['invalid_quantity'] = 'quantité invalide', - ['paid_rent'] = 'vous avez ~g~payé~s~ votre loyer: ~g~$%s~s~', + ['paid_rent'] = 'you paid your rent at ~g~$%s~s~ for ~y~%s~s~', + ['paid_rent_evicted'] = 'you have been ~o~evicted~s~ from ~y~%s~s~ for not affording rent at ~g~$%s~s~', ['not_enough_in_property'] = 'il n\'a pas assez de ~r~cet objet~s~ dans votre coffre!', ['player_cannot_hold'] = 'vous n\'avez pas assez ~y~de place~s~ dans votre inventaire!', } diff --git a/locales/pl.lua b/locales/pl.lua index 985fcb2f..eb9428cb 100644 --- a/locales/pl.lua +++ b/locales/pl.lua @@ -30,7 +30,8 @@ Locales['pl'] = { ['press_to_exit'] = 'wciśnij ~INPUT_CONTEXT~ aby wyjść z mieszkania', ['not_enough'] = 'nie posiadasz wystarczająco pieniędzy', ['invalid_quantity'] = 'nieprawidłowa ilość', - ['paid_rent'] = '~g~zapłaciłeś/aś~s~ za wynajem: ~g~$%s~s~', + ['paid_rent'] = 'you paid your rent at ~g~$%s~s~ for ~y~%s~s~', + ['paid_rent_evicted'] = 'you have been ~o~evicted~s~ from ~y~%s~s~ for not affording rent at ~g~$%s~s~', ['not_enough_in_property'] = 'nie ma wystarczająco ~r~tego przedmiotu~s~ w mieszkaniu!', ['player_cannot_hold'] = '~r~nie masz~s~ wystarczająco ~y~wolnego~s~ miejsca w ekwipunku!', } diff --git a/locales/sv.lua b/locales/sv.lua index bf3a6d07..84ee01a2 100644 --- a/locales/sv.lua +++ b/locales/sv.lua @@ -30,7 +30,8 @@ Locales['sv'] = { ['press_to_exit'] = 'tryck ~INPUT_CONTEXT~ för att lämna fastigheten', ['not_enough'] = 'du har inte tillräckligt med pengar!', ['invalid_quantity'] = 'ogiltlig mängd', - ['paid_rent'] = 'du ~y~betalade~s~ din hyra: ~g~%s SEK~s~', + ['paid_rent'] = 'du betalade din hyra på ~g~%s SEK~s~ för ~y~%s~s~', + ['paid_rent_evicted'] = 'du blev ~o~vräkt~s~ från ~y~%s~s~ för att du inte har råd för att betala hyran på ~g~%s SEK~s~', ['not_enough_in_property'] = 'det finns ~r~inte~s~ tillräckligt av ~r~det objektet~s~ i fastigheten!', ['player_cannot_hold'] = 'du har ~r~inte~s~ tillräckligt med ~y~utrymme~s~ för att hålla det!', } diff --git a/server/main.lua b/server/main.lua index 980850e8..c8cd8cff 100644 --- a/server/main.lua +++ b/server/main.lua @@ -31,7 +31,7 @@ function SetPropertyOwned(name, price, rented, owner) end) end -function RemoveOwnedProperty(name, owner) +function RemoveOwnedProperty(name, owner, noPay) MySQL.Async.fetchAll('SELECT id, rented, price FROM owned_properties WHERE name = @name AND owner = @owner', { ['@name'] = name, ['@owner'] = owner @@ -45,13 +45,15 @@ function RemoveOwnedProperty(name, owner) if xPlayer then xPlayer.triggerEvent('esx_property:setPropertyOwned', name, false) - if result[1].rented == 1 then - xPlayer.showNotification(_U('moved_out')) - else - local sellPrice = ESX.Math.Round(result[1].price / Config.SellModifier) + if not noPay then + if result[1].rented == 1 then + xPlayer.showNotification(_U('moved_out')) + else + local sellPrice = ESX.Math.Round(result[1].price / Config.SellModifier) - xPlayer.showNotification(_U('moved_out_sold', ESX.Math.GroupDigits(sellPrice))) - xPlayer.addAccountMoney('bank', sellPrice) + xPlayer.showNotification(_U('moved_out_sold', ESX.Math.GroupDigits(sellPrice))) + xPlayer.addAccountMoney('bank', sellPrice) + end end end end) @@ -60,6 +62,8 @@ function RemoveOwnedProperty(name, owner) end MySQL.ready(function() + Citizen.Wait(1500) + MySQL.Async.fetchAll('SELECT * FROM properties', {}, function(properties) for i=1, #properties, 1 do @@ -162,7 +166,7 @@ AddEventHandler('esx_property:removeOwnedProperty', function(name, owner) RemoveOwnedProperty(name, owner) end) -RegisterServerEvent('esx_property:rentProperty') +RegisterNetEvent('esx_property:rentProperty') AddEventHandler('esx_property:rentProperty', function(propertyName) local xPlayer = ESX.GetPlayerFromId(source) local property = GetProperty(propertyName) @@ -171,7 +175,7 @@ AddEventHandler('esx_property:rentProperty', function(propertyName) SetPropertyOwned(propertyName, rent, true, xPlayer.identifier) end) -RegisterServerEvent('esx_property:buyProperty') +RegisterNetEvent('esx_property:buyProperty') AddEventHandler('esx_property:buyProperty', function(propertyName) local xPlayer = ESX.GetPlayerFromId(source) local property = GetProperty(propertyName) @@ -184,7 +188,7 @@ AddEventHandler('esx_property:buyProperty', function(propertyName) end end) -RegisterServerEvent('esx_property:removeOwnedProperty') +RegisterNetEvent('esx_property:removeOwnedProperty') AddEventHandler('esx_property:removeOwnedProperty', function(propertyName) local xPlayer = ESX.GetPlayerFromId(source) RemoveOwnedProperty(propertyName, xPlayer.identifier) @@ -194,7 +198,7 @@ AddEventHandler('esx_property:removeOwnedPropertyIdentifier', function(propertyN RemoveOwnedProperty(propertyName, identifier) end) -RegisterServerEvent('esx_property:saveLastProperty') +RegisterNetEvent('esx_property:saveLastProperty') AddEventHandler('esx_property:saveLastProperty', function(property) local xPlayer = ESX.GetPlayerFromId(source) @@ -204,7 +208,7 @@ AddEventHandler('esx_property:saveLastProperty', function(property) }) end) -RegisterServerEvent('esx_property:deleteLastProperty') +RegisterNetEvent('esx_property:deleteLastProperty') AddEventHandler('esx_property:deleteLastProperty', function() local xPlayer = ESX.GetPlayerFromId(source) @@ -213,7 +217,7 @@ AddEventHandler('esx_property:deleteLastProperty', function() }) end) -RegisterServerEvent('esx_property:getItem') +RegisterNetEvent('esx_property:getItem') AddEventHandler('esx_property:getItem', function(owner, type, item, count) local xPlayer = ESX.GetPlayerFromId(source) local xPlayerOwner = ESX.GetPlayerFromIdentifier(owner) @@ -262,7 +266,7 @@ AddEventHandler('esx_property:getItem', function(owner, type, item, count) end end) -RegisterServerEvent('esx_property:putItem') +RegisterNetEvent('esx_property:putItem') AddEventHandler('esx_property:putItem', function(owner, type, item, count) local xPlayer = ESX.GetPlayerFromId(source) local xPlayerOwner = ESX.GetPlayerFromIdentifier(owner) @@ -389,7 +393,7 @@ ESX.RegisterServerCallback('esx_property:getPlayerOutfit', function(source, cb, end) end) -RegisterServerEvent('esx_property:removeOutfit') +RegisterNetEvent('esx_property:removeOutfit') AddEventHandler('esx_property:removeOutfit', function(label) local xPlayer = ESX.GetPlayerFromId(source) @@ -401,28 +405,48 @@ AddEventHandler('esx_property:removeOutfit', function(label) end) end) -function PayRent(d, h, m) +function payRent(d, h, m) 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 + for k,v in ipairs(result) do table.insert(tasks, function(cb) - local xPlayer = ESX.GetPlayerFromIdentifier(result[i].owner) + local xPlayer = ESX.GetPlayerFromIdentifier(v.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 - }) + if xPlayer.getAccount('bank').money >= v.price then + xPlayer.removeAccountMoney('bank', v.price) + xPlayer.showNotification(_U('paid_rent', ESX.Math.GroupDigits(v.price), GetProperty(v.name).label)) + else + xPlayer.showNotification(_U('paid_rent_evicted', GetProperty(v.name).label, ESX.Math.GroupDigits(v.price))) + RemoveOwnedProperty(v.name, v.owner, true) + end + else + MySQL.Async.fetchScalar('SELECT accounts FROM users WHERE identifier = @identifier', { + ['@identifier'] = v.owner + }, function(accounts) + if accounts then + local playerAccounts = json.decode(accounts) + + if playerAccounts and playerAccounts.bank then + if playerAccounts.bank >= v.price then + playerAccounts.bank = playerAccounts.bank - v.price + + MySQL.Async.execute('UPDATE users SET accounts = @accounts WHERE identifier = @identifier', { + ['@identifier'] = v.owner, + ['@accounts'] = json.encode(playerAccounts) + }) + else + RemoveOwnedProperty(v.name, v.owner, true) + end + end + end + end) end TriggerEvent('esx_addonaccount:getSharedAccount', 'society_realestateagent', function(account) - account.addMoney(result[i].price) + account.addMoney(v.price) end) cb() @@ -436,4 +460,4 @@ function PayRent(d, h, m) end) end -TriggerEvent('cron:runAt', 22, 0, PayRent) +TriggerEvent('cron:runAt', 22, 0, payRent)