diff --git a/resources/[inventory]/pl_printer/locales/de.json b/resources/[inventory]/pl_printer/locales/de.json index da5316076..74d33c4ea 100644 --- a/resources/[inventory]/pl_printer/locales/de.json +++ b/resources/[inventory]/pl_printer/locales/de.json @@ -5,5 +5,7 @@ "enter_copies": "Anzahl der Kopien eingeben", "prints": "Drucken", "Money_Removed": "Geld vom Bankkonto entfernt: $", - "not_enough": "Nicht genug Geld" + "not_enough": "Nicht genug Geld", + "item_received": "Du hast ein gedrucktes Dokument erhalten" + } \ No newline at end of file diff --git a/resources/[inventory]/pl_printer/server/main.lua b/resources/[inventory]/pl_printer/server/main.lua index 65d58c8c5..32306b466 100644 --- a/resources/[inventory]/pl_printer/server/main.lua +++ b/resources/[inventory]/pl_printer/server/main.lua @@ -6,20 +6,41 @@ end local resourceName = 'pl_printer' lib.versionCheck('pulsepk/pl_printer') +-- Ensure database table exists +MySQL.ready(function() + MySQL.Async.execute([[ + CREATE TABLE IF NOT EXISTS `printer` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `image_name` varchar(255) NOT NULL, + `image_link` varchar(255) NOT NULL, + PRIMARY KEY (`id`) + ) + ]], {}, function(result) + print("[DEBUG] Printer database table check completed") + end) +end) + RegisterServerEvent('pl_printer:insertImageData') AddEventHandler('pl_printer:insertImageData', function(imageUrl, amount) local Player = getPlayer(source) local account = Config.Print.Account local TotalBill = Config.Print.Price*amount + + print("[DEBUG] Player attempting to print image: " .. tostring(imageUrl)) + print("[DEBUG] Amount: " .. tostring(amount) .. ", Total cost: " .. tostring(TotalBill)) + if GetPlayerAccountMoney(Player,account,TotalBill) then local imageName = imageUrl:match(".*/(.*)$") - AddItem(source,amount, imageName) + print("[DEBUG] Extracted image name: " .. tostring(imageName)) + + AddItem(source, amount, imageName) + if imageUrl and amount then MySQL.Async.execute('INSERT INTO printer (image_name, image_link) VALUES (@image_name, @image_link)', { ['@image_name'] = tostring(imageName), ['@image_link'] = imageUrl }, function(rowsChanged) - print("[DEBUG] Image saved to database: " .. imageName) + print("[DEBUG] Image saved to database: " .. imageName .. ", Rows changed: " .. tostring(rowsChanged)) end) RemovePlayerMoney(Player,account,TotalBill) TriggerClientEvent('pl_printer:notification',source,Locale("Money_Removed") .. TotalBill,'success') @@ -27,6 +48,7 @@ AddEventHandler('pl_printer:insertImageData', function(imageUrl, amount) _debug('[DEBUG] '..' Invalid data received for image. '..'') end else + print("[DEBUG] Player doesn't have enough money. Required: " .. tostring(TotalBill)) TriggerClientEvent('pl_printer:notification',source,Locale("not_enough"),'error') end end) @@ -60,7 +82,13 @@ function AddItem(source, amount, imageName) local info = { id = imageName } - if GetResourceState('qb-inventory') == 'started' then + + if GetResourceState('tgiann-inventory') == 'started' then + -- Add support for tgiann-inventory + exports["tgiann-inventory"]:AddItem(src, Config.ItemName, amount, nil, info, false) + -- Notification for item added + TriggerClientEvent('pl_printer:notification', src, Locale("item_received") or "You received a printed document", 'success') + elseif GetResourceState('qb-inventory') == 'started' then if lib.checkDependency('qb-inventory', '2.0.0') then exports['qb-inventory']:AddItem(src, Config.ItemName, amount, false, info) TriggerClientEvent('qb-inventory:client:ItemBox', src, QBCore.Shared.Items[Config.ItemName], 'add', amount) @@ -121,6 +149,25 @@ AddEventHandler('onResourceStart', function(resourceName) end end) end + + -- tgiann-inventory item registration + if GetResourceState('tgiann-inventory') == 'started' then + -- Register the usable item with tgiann-inventory + exports['tgiann-inventory']:RegisterUsableItem(Config.ItemName, function(source, itemData) + local src = source + local metadata = itemData.metadata or itemData.info or {} + local imageName = metadata.id + + if imageName then + print("[DEBUG] tgiann-inventory: Using document with image ID: " .. tostring(imageName)) + TriggerEvent('pl_printer:fetchImageLink', imageName, src) + else + print("[DEBUG] tgiann-inventory: No image ID found in item metadata") + end + end) + + print("[DEBUG] Registered " .. Config.ItemName .. " as usable item in tgiann-inventory") + end end) local WaterMark = function()