forked from Simnation/Main
ed
This commit is contained in:
parent
7033e7cb4a
commit
d9c6a056e4
2 changed files with 53 additions and 4 deletions
|
@ -5,5 +5,7 @@
|
||||||
"enter_copies": "Anzahl der Kopien eingeben",
|
"enter_copies": "Anzahl der Kopien eingeben",
|
||||||
"prints": "Drucken",
|
"prints": "Drucken",
|
||||||
"Money_Removed": "Geld vom Bankkonto entfernt: $",
|
"Money_Removed": "Geld vom Bankkonto entfernt: $",
|
||||||
"not_enough": "Nicht genug Geld"
|
"not_enough": "Nicht genug Geld",
|
||||||
|
"item_received": "Du hast ein gedrucktes Dokument erhalten"
|
||||||
|
|
||||||
}
|
}
|
|
@ -6,20 +6,41 @@ end
|
||||||
local resourceName = 'pl_printer'
|
local resourceName = 'pl_printer'
|
||||||
lib.versionCheck('pulsepk/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')
|
RegisterServerEvent('pl_printer:insertImageData')
|
||||||
AddEventHandler('pl_printer:insertImageData', function(imageUrl, amount)
|
AddEventHandler('pl_printer:insertImageData', function(imageUrl, amount)
|
||||||
local Player = getPlayer(source)
|
local Player = getPlayer(source)
|
||||||
local account = Config.Print.Account
|
local account = Config.Print.Account
|
||||||
local TotalBill = Config.Print.Price*amount
|
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
|
if GetPlayerAccountMoney(Player,account,TotalBill) then
|
||||||
local imageName = imageUrl:match(".*/(.*)$")
|
local imageName = imageUrl:match(".*/(.*)$")
|
||||||
|
print("[DEBUG] Extracted image name: " .. tostring(imageName))
|
||||||
|
|
||||||
AddItem(source, amount, imageName)
|
AddItem(source, amount, imageName)
|
||||||
|
|
||||||
if imageUrl and amount then
|
if imageUrl and amount then
|
||||||
MySQL.Async.execute('INSERT INTO printer (image_name, image_link) VALUES (@image_name, @image_link)', {
|
MySQL.Async.execute('INSERT INTO printer (image_name, image_link) VALUES (@image_name, @image_link)', {
|
||||||
['@image_name'] = tostring(imageName),
|
['@image_name'] = tostring(imageName),
|
||||||
['@image_link'] = imageUrl
|
['@image_link'] = imageUrl
|
||||||
}, function(rowsChanged)
|
}, function(rowsChanged)
|
||||||
print("[DEBUG] Image saved to database: " .. imageName)
|
print("[DEBUG] Image saved to database: " .. imageName .. ", Rows changed: " .. tostring(rowsChanged))
|
||||||
end)
|
end)
|
||||||
RemovePlayerMoney(Player,account,TotalBill)
|
RemovePlayerMoney(Player,account,TotalBill)
|
||||||
TriggerClientEvent('pl_printer:notification',source,Locale("Money_Removed") .. TotalBill,'success')
|
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. '..'')
|
_debug('[DEBUG] '..' Invalid data received for image. '..'')
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
print("[DEBUG] Player doesn't have enough money. Required: " .. tostring(TotalBill))
|
||||||
TriggerClientEvent('pl_printer:notification',source,Locale("not_enough"),'error')
|
TriggerClientEvent('pl_printer:notification',source,Locale("not_enough"),'error')
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
@ -60,7 +82,13 @@ function AddItem(source, amount, imageName)
|
||||||
local info = {
|
local info = {
|
||||||
id = imageName
|
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
|
if lib.checkDependency('qb-inventory', '2.0.0') then
|
||||||
exports['qb-inventory']:AddItem(src, Config.ItemName, amount, false, info)
|
exports['qb-inventory']:AddItem(src, Config.ItemName, amount, false, info)
|
||||||
TriggerClientEvent('qb-inventory:client:ItemBox', src, QBCore.Shared.Items[Config.ItemName], 'add', amount)
|
TriggerClientEvent('qb-inventory:client:ItemBox', src, QBCore.Shared.Items[Config.ItemName], 'add', amount)
|
||||||
|
@ -121,6 +149,25 @@ AddEventHandler('onResourceStart', function(resourceName)
|
||||||
end
|
end
|
||||||
end)
|
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)
|
end)
|
||||||
|
|
||||||
local WaterMark = function()
|
local WaterMark = function()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue