Skip to content

Commit

Permalink
refactor: carry limit notifications
Browse files Browse the repository at this point in the history
Requires translations.
  • Loading branch information
dolutattoo authored Jan 20, 2022
1 parent 36ab09a commit e305a15
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 7 deletions.
2 changes: 2 additions & 0 deletions data/locales/cs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ return {
['cannot_perform'] = "Tuto akci nelze provést",
['cannot_carry'] = "Tolik toho neunesete",
['cannot_carry_other'] = "Druhý inventář toho tolik neunese",
['cannot_carry_limit'] = "You only can carry %s %s maximum",
['cannot_carry_limit_other'] = "Target only can carry %s %s maximum",
['items_confiscated'] = "Vaše předměty byly zabaveny",
['items_returned'] = "Vaše předměty vám byly vráceny",
['item_unauthorised'] = "Nemáte pravomoce k zakoupení tohoto předmětu",
Expand Down
2 changes: 2 additions & 0 deletions data/locales/da.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ return {
['cannot_perform'] = "Du kan ikke udføre denne handling",
['cannot_carry'] = "Du kan ikke bære så meget",
['cannot_carry_other'] = "Inventaret du prøver at lægge i kan ikke indeholde så meget",
['cannot_carry_limit'] = "You only can carry %s %s maximum",
['cannot_carry_limit_other'] = "Target only can carry %s %s maximum",
['items_confiscated'] = "Dine ting er blevet konfiskeret",
['items_returned'] = "Dine ting er blevet returneret",
['item_unauthorised'] = "Du har ikke tilladelse til at købe denne ting",
Expand Down
2 changes: 2 additions & 0 deletions data/locales/de.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ return {
['cannot_perform'] = "Du kannst diese Aktion nicht ausführen",
['cannot_carry'] = "Du kannst nicht so viel tragen",
['cannot_carry_other'] = "Das Inventar hat nicht genügend Platz",
['cannot_carry_limit'] = "You only can carry %s %s maximum",
['cannot_carry_limit_other'] = "Target only can carry %s %s maximum",
['items_confiscated'] = "Deine Gegenstände wurden konfisziert",
['items_returned'] = "Deine Gegenstände wurden dir zurückgegeben",
['item_unauthorised'] = "Du bist nicht autorisiert diesen Gegenstand zu kaufen",
Expand Down
2 changes: 2 additions & 0 deletions data/locales/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ return {
['cannot_perform'] = "You can not perform this action",
['cannot_carry'] = "You can not carry that much",
['cannot_carry_other'] = "Target inventory can not hold that much",
['cannot_carry_limit'] = "You only can carry %s %s maximum",
['cannot_carry_limit_other'] = "Target only can carry %s %s maximum",
['items_confiscated'] = "Your items have been confiscated",
['items_returned'] = "Your items have been returned",
['item_unauthorised'] = "You are not authorised to purchase this item",
Expand Down
2 changes: 2 additions & 0 deletions data/locales/es.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ return {
['cannot_perform'] = "No puedes hacer eso o no lo estás haciendo bien",
['cannot_carry'] = "No puedes cargar tanto",
['cannot_carry_other'] = "No cabe en ese inventario",
['cannot_carry_limit'] = "You only can carry %s %s maximum",
['cannot_carry_limit_other'] = "Target only can carry %s %s maximum",
['items_confiscated'] = "Tus items han sido confiscadas",
['items_returned'] = "Tus items te han sido devueltos",
['item_unauthorised'] = "No estás autorizado para comprar este item",
Expand Down
2 changes: 2 additions & 0 deletions data/locales/fr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ return {
['cannot_perform'] = "Vous ne pouvez pas faire cette action",
['cannot_carry'] = "Vous ne pouvez pas en porter autant",
['cannot_carry_other'] = "L’autre inventaire ne peut pas en porter autant",
['cannot_carry_limit'] = "Vous ne pouvez porter que %s %s maximum",
['cannot_carry_limit_other'] = "La personne ne peux porter que %s %s maximum",
['items_confiscated'] = "Vos objets ont été confisqués",
['items_returned'] = "Vos objets ont été retournés",
['item_unauthorised'] = "Vous n’êtes pas autorisé à acheter cet article",
Expand Down
2 changes: 2 additions & 0 deletions data/locales/it.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ return {
['cannot_perform'] = "Non puoi eseguire questa azione",
['cannot_carry'] = "Non puoi portarne così tanti",
['cannot_carry_other'] = "L'altro inventario non può portarne così tanti",
['cannot_carry_limit'] = "You only can carry %s %s maximum",
['cannot_carry_limit_other'] = "Target only can carry %s %s maximum",
['items_confiscated'] = "I tuoi oggetti sono stati confiscati",
['items_returned'] = "I tuoi oggetti sono stati restituiti",
['item_unauthorised'] = "Non sei autorizzato a comprare questo oggetto",
Expand Down
2 changes: 2 additions & 0 deletions data/locales/nl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ return {
['cannot_perform'] = "Je kan deze actie niet uitvoeren",
['cannot_carry'] = "Je kan niet zoveel dragen",
['cannot_carry_other'] = "Doel inventaris kan niet zoveel dragen",
['cannot_carry_limit'] = "You only can carry %s %s maximum",
['cannot_carry_limit_other'] = "Target only can carry %s %s maximum",
['items_confiscated'] = "Je items zijn in beslag genomen",
['items_returned'] = "Je items zijn teruggegeven",
['item_unauthorised'] = "Je bent niet geautoriseerd om dit item te kopen",
Expand Down
2 changes: 2 additions & 0 deletions data/locales/pt-br.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ return {
['cannot_perform'] = "Você não pode realizar esta ação",
['cannot_carry'] = "Você não pode carregar muito",
['cannot_carry_other'] = "O inventário de destino não pode conter tanto",
['cannot_carry_limit'] = "You only can carry %s %s maximum",
['cannot_carry_limit_other'] = "Target only can carry %s %s maximum",
['items_confiscated'] = "Seus itens foram confiscados",
['items_returned'] = "Seus itens foram devolvidos",
['item_unauthorised'] = "Você não está autorizado a comprar este item",
Expand Down
13 changes: 10 additions & 3 deletions modules/inventory/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -601,13 +601,20 @@ function Inventory.CanCarryItem(inv, item, count, metadata)
local itemSlots, totalCount, emptySlots = Inventory.GetItemSlots(inv, item, metadata == nil and {} or type(metadata) == 'string' and {type=metadata} or metadata)

if next(itemSlots) or emptySlots > 0 then
if inv.type == 'player' and item.limit and (totalCount + count) > item.limit then return false end
if inv.type == 'player' and item.limit and (totalCount + count) > item.limit then
TriggerClientEvent('ox_inventory:notify', playerId, {type = 'error', text = shared.locale('cannot_carry_limit', item.limit, item.label)})
return false
end
if item.weight == 0 then return true end
if count == nil then count = 1 end
local newWeight = inv.weight + (item.weight * count)
return newWeight <= inv.maxWeight
if newWeight >= inv.maxWeight then
TriggerClientEvent('ox_inventory:notify', playerId, {type = 'error', text = shared.locale('cannot_carry')})
return false
else
return true
end
end

end
end
exports('CanCarryItem', Inventory.CanCarryItem)
Expand Down
4 changes: 2 additions & 2 deletions modules/shops/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ ServerCallback.Register('buyItem', function(source, data)

local _, totalCount, _ = Inventory.GetItemSlots(playerInv, fromItem, fromItem.metadata)
if fromItem.limit and (totalCount + data.count) > fromItem.limit then
return false, false, {type = 'error', text = { shared.locale('cannot_carry')}}
return false, false, {type = 'error', text = shared.locale('cannot_carry_limit', fromItem.limit, fromItem.label)}
end

if toData == nil or (fromItem.name == toItem.name and fromItem.stack and table.matches(toData.metadata, metadata)) then
local canAfford = Inventory.GetItem(source, currency, false, true) >= price
if canAfford then
local newWeight = playerInv.weight + (fromItem.weight + (metadata?.weight or 0)) * count
if newWeight > playerInv.maxWeight then
return false, false, {type = 'error', text = { shared.locale('cannot_carry')}}
return false, false, {type = 'error', text = shared.locale('cannot_carry')}
else
Inventory.SetSlot(playerInv, fromItem, count, metadata, data.toSlot)
if fromData.count then shop.items[data.fromSlot].count = fromData.count - count end
Expand Down
4 changes: 2 additions & 2 deletions server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ ServerCallback.Register('swapItems', function(source, data)
local _, totalCount, _ = Inventory.GetItemSlots(toInventory, fromItem, fromItem.metadata)
if fromItem.limit and (totalCount + data.count) > fromItem.limit then
if toInventory.type == 'player' then
TriggerClientEvent('ox_inventory:notify', source, {type = 'error', text = { shared.locale('cannot_carry')}})
TriggerClientEvent('ox_inventory:notify', source, {type = 'error', text = shared.locale('cannot_carry_limit', fromItem.limit, fromItem.label)})
elseif toInventory.type == 'otherplayer' then
TriggerClientEvent('ox_inventory:notify', source, {type = 'error', text = { shared.locale('cannot_carry_other')}})
TriggerClientEvent('ox_inventory:notify', source, {type = 'error', text = shared.locale('cannot_carry_limit_other', fromItem.limit, fromItem.label)})
end
return
end
Expand Down

0 comments on commit e305a15

Please sign in to comment.