Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Z3rio authored Nov 5, 2024
2 parents bcbebb4 + 9afdc87 commit be63fd2
Show file tree
Hide file tree
Showing 8 changed files with 272 additions and 41 deletions.
33 changes: 16 additions & 17 deletions client/drops.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,23 @@ CurrentDrop = nil

function GetDrops()
QBCore.Functions.TriggerCallback('qb-inventory:server:GetCurrentDrops', function(drops)
if drops then
for k, v in pairs(drops) do
local bag = NetworkGetEntityFromNetworkId(v.entityId)
if DoesEntityExist(bag) then
exports['qb-target']:AddTargetEntity(bag, {
options = {
{
icon = 'fas fa-backpack',
label = Lang:t('menu.o_bag'),
action = function()
TriggerServerEvent('qb-inventory:server:openDrop', k)
CurrentDrop = k
end,
},
if not drops then return end
for k, v in pairs(drops) do
local bag = NetworkGetEntityFromNetworkId(v.entityId)
if DoesEntityExist(bag) then
exports['qb-target']:AddTargetEntity(bag, {
options = {
{
icon = 'fas fa-backpack',
label = Lang:t('menu.o_bag'),
action = function()
TriggerServerEvent('qb-inventory:server:openDrop', k)
CurrentDrop = k
end,
},
distance = 2.5,
})
end
},
distance = 2.5,
})
end
end
end)
Expand Down
1 change: 1 addition & 0 deletions client/main.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
QBCore = exports['qb-core']:GetCoreObject()
PlayerData = nil
local hotbarShown = false
local PlayerData = nil

Expand Down
17 changes: 10 additions & 7 deletions html/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,21 +447,21 @@ const InventoryContainer = Vue.createApp({
if (sourceItem.amount < amountToTransfer) {
throw new Error("Insufficient amount of item in source inventory");
}
if (targetInventoryType == "other")
{

if (targetInventoryType !== this.dragStartInventoryType) {
if (targetInventoryType == "other") {
const totalWeightAfterTransfer = this.otherInventoryWeight + sourceItem.weight * amountToTransfer;
if (totalWeightAfterTransfer > this.otherInventoryMaxWeight) {
throw new Error("Insufficient weight capacity in target inventory");
}
}
else if (targetInventoryType == "player")
{
else if (targetInventoryType == "player") {
const totalWeightAfterTransfer = this.playerWeight + sourceItem.weight * amountToTransfer;
if (totalWeightAfterTransfer > this.maxWeight) {
throw new Error("Insufficient weight capacity in player inventory");
}
}
}

const targetItem = targetInventory[targetSlotNumber];

Expand All @@ -482,7 +482,7 @@ const InventoryContainer = Vue.createApp({
targetInventory[targetSlotNumber] = sourceItem;
sourceInventory[this.currentlyDraggingSlot].slot = this.currentlyDraggingSlot;
targetInventory[targetSlotNumber].slot = targetSlotNumber;
this.postInventoryData(this.dragStartInventoryType, targetInventoryType, this.currentlyDraggingSlot, targetSlotNumber, amountToTransfer, targetItem.amount);
this.postInventoryData(this.dragStartInventoryType, targetInventoryType, this.currentlyDraggingSlot, targetSlotNumber, sourceItem.amount, targetItem.amount);
}
} else {
sourceItem.amount -= amountToTransfer;
Expand Down Expand Up @@ -589,6 +589,7 @@ const InventoryContainer = Vue.createApp({
});

if (response.data) {
delete this.playerInventory[playerItemKey];
this.otherInventory[1] = newItem;
this.otherInventoryName = response.data;
this.otherInventoryLabel = response.data;
Expand Down Expand Up @@ -698,12 +699,14 @@ const InventoryContainer = Vue.createApp({
}

try {
await axios.post("https://qb-inventory/GiveItem", {
const response = await axios.post("https://qb-inventory/GiveItem", {
item: selectedItem,
amount: amountToGive,
slot: selectedItem.slot,
info: selectedItem.info,
});
if (!response.data) return;

this.playerInventory[selectedItem.slot].amount -= amountToGive;
if (this.playerInventory[selectedItem.slot].amount === 0) {
delete this.playerInventory[selectedItem.slot];
Expand Down
57 changes: 57 additions & 0 deletions locales/de.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
local Translations = {
progress = {
['snowballs'] = 'Schneebälle sammeln..',
},
notify = {
['failed'] = 'Fehlgeschlagen',
['canceled'] = 'Abgebrochen',
['vlocked'] = 'Fahrzeug verriegelt',
['notowned'] = 'Du besitzt diesen Gegenstand nicht!',
['missitem'] = 'Du hast diesen Gegenstand nicht!',
['nonb'] = 'Niemand in der Nähe!',
['noaccess'] = 'Nicht zugänglich',
['nosell'] = 'Du kannst diesen Gegenstand nicht verkaufen..',
['itemexist'] = 'Der Gegenstand existiert nicht',
['notencash'] = 'Du hast nicht genug Bargeld..',
['noitem'] = 'Du hast nicht die richtigen Gegenstände..',
['gsitem'] = 'Du kannst dir keinen Gegenstand geben?',
['tftgitem'] = 'Du bist zu weit weg, um Gegenstände zu geben!',
['infound'] = 'Der Gegenstand, den du geben wolltest, wurde nicht gefunden!',
['iifound'] = 'Falscher Gegenstand gefunden, versuche es erneut!',
['gitemrec'] = 'Du hast erhalten ',
['gitemfrom'] = ' Von ',
['gitemyg'] = 'Du hast gegeben ',
['gitinvfull'] = 'Das Inventar des anderen Spielers ist voll!',
['giymif'] = 'Dein Inventar ist voll!',
['gitydhei'] = 'Du hast nicht genug von dem Gegenstand',
['gitydhitt'] = 'Du hast nicht genug Gegenstände zum Übertragen',
['navt'] = 'Ungültiger Typ..',
['anfoc'] = 'Argumente nicht korrekt ausgefüllt..',
['yhg'] = 'Du hast gegeben ',
['cgitem'] = 'Kann den Gegenstand nicht geben!',
['idne'] = 'Gegenstand existiert nicht',
['pdne'] = 'Spieler ist nicht online',
},
inf_mapping = {
['opn_inv'] = 'Inventar öffnen',
['tog_slots'] = 'Schaltet die belegten Slots um',
['use_item'] = 'Verwendet den Gegenstand im Slot ',
},
menu = {
['vending'] = 'Verkaufsautomat',
['bin'] = 'Müllcontainer öffnen',
['craft'] = 'Herstellen',
['o_bag'] = 'Tasche öffnen',
},
interaction = {
['craft'] = '~g~E~w~ - Herstellen',
},
}

if GetConvar('qb_locale', 'en') == 'de' then
Lang = Locale:new({
phrases = Translations,
warnOnMissing = true,
fallbackLang = Lang,
})
end
57 changes: 57 additions & 0 deletions locales/es.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
local Translations = {
progress = {
['snowballs'] = 'Recolectando bolas de nieve..',
},
notify = {
['failed'] = 'Fallido',
['canceled'] = 'Cancelado',
['vlocked'] = 'Vehículo Bloqueado',
['notowned'] = '¡No posees este objeto!',
['missitem'] = '¡No tienes este objeto!',
['nonb'] = '¡No hay nadie cerca!',
['noaccess'] = 'No Accesible',
['nosell'] = 'No puedes vender este objeto..',
['itemexist'] = 'El objeto no existe',
['notencash'] = 'No tienes suficiente dinero..',
['noitem'] = 'No tienes los objetos adecuados..',
['gsitem'] = '¿No puedes darte un objeto a ti mismo?',
['tftgitem'] = '¡Estás demasiado lejos para dar objetos!',
['infound'] = '¡Objeto que intentaste dar no encontrado!',
['iifound'] = '¡Objeto incorrecto encontrado, intenta de nuevo!',
['gitemrec'] = 'Recibiste ',
['gitemfrom'] = ' De ',
['gitemyg'] = 'Diste ',
['gitinvfull'] = '¡El inventario del otro jugador está lleno!',
['giymif'] = '¡Tu inventario está lleno!',
['gitydhei'] = 'No tienes suficiente del objeto',
['gitydhitt'] = 'No tienes suficientes objetos para transferir',
['navt'] = 'No es un tipo válido..',
['anfoc'] = 'Argumentos no rellenados correctamente..',
['yhg'] = 'Has Dado ',
['cgitem'] = '¡No se puede dar el objeto!',
['idne'] = 'El Objeto No Existe',
['pdne'] = 'El Jugador No Está En Línea',
},
inf_mapping = {
['opn_inv'] = 'Abrir Inventario',
['tog_slots'] = 'Alterna ranuras de teclas',
['use_item'] = 'Usa el objeto en la ranura',
},
menu = {
['vending'] = 'Máquina Expendedora',
['bin'] = 'Abrir Contenedor de Basura',
['craft'] = 'Crear',
['o_bag'] = 'Abrir Bolsa',
},
interaction = {
['craft'] = '~g~E~w~ - Fabricar',
},
}

if GetConvar('qb_locale', 'en') == 'es' then
Lang = Locale:new({
phrases = Translations,
warnOnMissing = true,
fallbackLang = Lang,
})
end
56 changes: 56 additions & 0 deletions locales/nl.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
local Translations = {
progress = {
['snowballs'] = 'Sneeuwballen verzamelen..',
},
notify = {
['failed'] = 'Mislukt',
['canceled'] = 'Geannuleerd',
['vlocked'] = 'Voertuig Vergrendeld',
['notowned'] = 'Dit item is niet van jou!',
['missitem'] = 'Je hebt dit item niet!',
['nonb'] = 'Niemand in de buurt!',
['noaccess'] = 'Geen toegang',
['nosell'] = 'Je kunt dit item niet verkopen..',
['itemexist'] = 'Item bestaat niet',
['notencash'] = 'Je hebt niet genoeg geld..',
['noitem'] = 'Je hebt niet de juiste items..',
['gsitem'] = 'Je kunt jezelf geen item geven?',
['tftgitem'] = 'Je bent te ver weg om items te geven!',
['infound'] = 'Het item dat je probeerde te geven is niet gevonden!',
['iifound'] = 'Onjuist item gevonden, probeer opnieuw!',
['gitemrec'] = 'Je hebt ontvangen ',
['gitemfrom'] = ' Van ',
['gitemyg'] = 'Je hebt gegeven ',
['gitinvfull'] = 'De inventaris van de andere speler is vol!',
['giymif'] = 'Jouw inventaris is vol!',
['gitydhei'] = 'Je hebt niet genoeg van het item',
['gitydhitt'] = 'Je hebt niet genoeg items om over te dragen',
['navt'] = 'Geen geldig type..',
['anfoc'] = 'Argumenten niet correct ingevuld..',
['yhg'] = 'Je hebt gegeven ',
['cgitem'] = 'Kan item niet geven!',
['idne'] = 'Item bestaat niet',
['pdne'] = 'Speler is niet online',
},
inf_mapping = {
['opn_inv'] = 'Open Inventaris',
['tog_slots'] = 'Schakelt sleutelbind-slots om',
['use_item'] = 'Gebruikt het item in slot ',
},
menu = {
['vending'] = 'Verkoopautomaat',
['bin'] = 'Open Prullenbak',
['craft'] = 'Maak',
['o_bag'] = 'Open Tas',
},
interaction = {
['craft'] = '~g~E~w~ - Maken',
},
}

if GetConvar('qb_locale', 'en') == 'nl' then
Lang = Locale:new({
phrases = Translations,
warnOnMissing = true,
})
end
48 changes: 42 additions & 6 deletions server/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,10 @@ exports('CanAddItem', CanAddItem)
--- @param source number The player's server ID.
--- @return number - Returns the free weight of the players inventory. Error will return 0
function GetFreeWeight(source)
if not source then warn("Source was not passed into GetFreeWeight") return 0 end
if not source then
warn('Source was not passed into GetFreeWeight')
return 0
end
local Player = QBCore.Functions.GetPlayer(source)
if not Player then return 0 end

Expand Down Expand Up @@ -465,6 +468,18 @@ end

exports('OpenInventoryById', OpenInventoryById)

-- Clears a given stash of all items inside
--- @param identifier string
function ClearStash(identifier)
if not identifier then return end
local inventory = Inventories[identifier]
if not inventory then return end
inventory.items = {}
MySQL.prepare('UPDATE inventories SET items = ? WHERE identifier = ?', { json.encode(inventory.items), identifier })
end

exports('ClearStash', ClearStash)

--- @param shopData table The data of the shop to create.
function CreateShop(shopData)
if shopData.name then
Expand Down Expand Up @@ -552,9 +567,9 @@ function OpenInventory(source, identifier, data)
end

if not inventory then inventory = InitializeInventory(identifier, data) end
inventory.maxweight = (inventory and inventory.maxweight) or (data and data.maxweight) or Config.StashSize.maxweight
inventory.slots = (inventory and inventory.slots) or (data and data.slots) or Config.StashSize.slots
inventory.label = (inventory and inventory.label) or (data and data.label) or identifier
inventory.maxweight = (data and data.maxweight) or (inventory and inventory.maxweight) or Config.StashSize.maxweight
inventory.slots = (data and data.slots) or (inventory and inventory.slots) or Config.StashSize.slots
inventory.label = (data and data.label) or (inventory and inventory.label) or identifier
inventory.isOpen = source

local formattedInventory = {
Expand Down Expand Up @@ -692,6 +707,7 @@ function RemoveItem(identifier, item, amount, slot, reason)
print('RemoveItem: Invalid item')
return false
end

local inventory
local player = QBCore.Functions.GetPlayer(identifier)

Expand All @@ -715,7 +731,17 @@ function RemoveItem(identifier, item, amount, slot, reason)
return false
end

local inventoryItem = inventory[slot]
local inventoryItem = nil
local itemKey = nil

for key, invItem in pairs(inventory) do
if invItem.slot == slot then
inventoryItem = invItem
itemKey = key
break
end
end

if not inventoryItem or inventoryItem.name:lower() ~= item:lower() then
print('RemoveItem: Item not found in slot')
return false
Expand All @@ -729,13 +755,17 @@ function RemoveItem(identifier, item, amount, slot, reason)

inventoryItem.amount = inventoryItem.amount - amount
if inventoryItem.amount <= 0 then
inventory[slot] = nil
inventory[itemKey] = nil
else
inventory[itemKey] = inventoryItem
end

if player then player.Functions.SetPlayerData('items', inventory) end

local invName = player and GetPlayerName(identifier) .. ' (' .. identifier .. ')' or identifier
local removeReason = reason or 'No reason specified'
local resourceName = GetInvokingResource() or 'qb-inventory'

TriggerEvent(
'qb-log:server:CreateLog',
'playerinventory',
Expand All @@ -751,3 +781,9 @@ function RemoveItem(identifier, item, amount, slot, reason)
end

exports('RemoveItem', RemoveItem)

function GetInventory(identifier)
return Inventories[identifier]
end

exports('GetInventory', GetInventory)
Loading

0 comments on commit be63fd2

Please sign in to comment.