1
0
Fork 0
forked from Simnation/Main
Main/resources/[inventory]/pl_printer/server/main.lua

136 lines
5.7 KiB
Lua
Raw Normal View History

2025-06-26 03:23:18 +02:00
if GetResourceState('qb-core') == 'started' then
2025-06-26 04:08:54 +02:00
QBCore = exports['qb-core']:GetCoreObject()
2025-06-26 03:23:18 +02:00
elseif GetResourceState('es_extended') == 'started' then
2025-06-26 04:08:54 +02:00
ESX = exports['es_extended']:getSharedObject()
2025-06-26 03:23:18 +02:00
end
local resourceName = 'pl_printer'
lib.versionCheck('pulsepk/pl_printer')
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
if GetPlayerAccountMoney(Player,account,TotalBill) then
local imageName = imageUrl:match(".*/(.*)$")
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)
2025-06-26 04:08:54 +02:00
print("[DEBUG] Image saved to database: " .. imageName)
2025-06-26 03:23:18 +02:00
end)
RemovePlayerMoney(Player,account,TotalBill)
TriggerClientEvent('pl_printer:notification',source,Locale("Money_Removed") .. TotalBill,'success')
else
_debug('[DEBUG] '..' Invalid data received for image. '..'')
end
else
TriggerClientEvent('pl_printer:notification',source,Locale("not_enough"),'error')
end
end)
RegisterServerEvent('pl_printer:fetchImageLink')
2025-06-26 04:08:54 +02:00
AddEventHandler('pl_printer:fetchImageLink', function(imageName, playerSource)
local src = playerSource or source
local hasItem = HasItem(src)
if not hasItem then
print("[DEBUG] Player doesn't have the required item")
return
end
print("[DEBUG] Fetching image with name: " .. tostring(imageName))
2025-06-26 03:23:18 +02:00
MySQL.Async.fetchScalar('SELECT image_link FROM printer WHERE image_name = @imageName', {
['@imageName'] = imageName
}, function(imageLink)
if imageLink then
2025-06-26 04:08:54 +02:00
print("[DEBUG] Found image link: " .. tostring(imageLink))
TriggerClientEvent('pl_printer:showImage', src, imageLink)
2025-06-26 03:23:18 +02:00
else
2025-06-26 04:08:54 +02:00
print("[DEBUG] No Image Link Found for " .. tostring(imageName))
_debug('[DEBUG] '..' No Image Link Found for '..tostring(imageName)..'')
2025-06-26 03:23:18 +02:00
end
end)
end)
function AddItem(source, amount, imageName)
local src = source
local info = {
id = imageName
}
if GetResourceState('qb-inventory') == 'started' then
if lib.checkDependency('qb-inventory', '2.0.0') then
2025-06-26 04:08:54 +02:00
exports['qb-inventory']:AddItem(src, Config.ItemName, amount, false, info)
2025-06-26 03:23:18 +02:00
TriggerClientEvent('qb-inventory:client:ItemBox', src, QBCore.Shared.Items[Config.ItemName], 'add', amount)
else
local Player = getPlayer(src)
2025-06-26 04:08:54 +02:00
Player.Functions.AddItem(Config.ItemName, amount, false, info)
2025-06-26 03:23:18 +02:00
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[Config.ItemName], "add")
end
elseif GetResourceState('ox_inventory') == 'started' then
2025-06-26 04:08:54 +02:00
exports.ox_inventory:AddItem(src, Config.ItemName, amount, {type = imageName}, false)
2025-06-26 03:23:18 +02:00
elseif GetResourceState('qs-inventory') == 'started' then
2025-06-26 04:08:54 +02:00
local itemMetadata = {id = imageName}
exports['qs-inventory']:AddItem(src, Config.ItemName, amount, false, itemMetadata)
2025-06-26 03:23:18 +02:00
end
end
2025-06-26 04:08:54 +02:00
-- Registriere verwendbare Items für verschiedene Frameworks
AddEventHandler('onResourceStart', function(resourceName)
if GetCurrentResourceName() ~= resourceName then return end
-- QB-Core Item Registration
if GetResourceState('qb-core') == 'started' then
QBCore.Functions.CreateUseableItem(Config.ItemName, function(source, item)
local src = source
local imageName = item.info and item.info.id
if imageName then
TriggerEvent('pl_printer:fetchImageLink', imageName, src)
else
print("[DEBUG] No image ID found in item info")
end
end)
end
-- ESX Item Registration
if GetResourceState('es_extended') == 'started' then
ESX.RegisterUsableItem(Config.ItemName, function(source, item)
local src = source
local metadata = item.metadata or {}
local imageName = metadata.id
if imageName then
TriggerEvent('pl_printer:fetchImageLink', imageName, src)
else
print("[DEBUG] No image ID found in item metadata")
end
end)
end
-- ox_inventory export
2025-06-26 03:23:18 +02:00
if GetResourceState('ox_inventory') == 'started' then
2025-06-26 04:08:54 +02:00
exports(Config.ItemName, function(event, item, inventory, slot, data)
2025-06-26 03:23:18 +02:00
if event == 'usingItem' then
local item_metadata = exports.ox_inventory:GetSlot(inventory.id, slot)
2025-06-26 04:08:54 +02:00
if item_metadata and item_metadata.metadata and item_metadata.metadata.type then
TriggerEvent('pl_printer:fetchImageLink', item_metadata.metadata.type, inventory.id)
else
print("[DEBUG] No metadata type found in ox_inventory item")
end
2025-06-26 03:23:18 +02:00
end
end)
end
end)
local WaterMark = function()
SetTimeout(1500, function()
print('^1['..resourceName..'] ^2Thank you for Downloading the Script^0')
print('^1['..resourceName..'] ^2If you encounter any issues please Join the discord https://discord.gg/c6gXmtEf3H to get support..^0')
print('^1['..resourceName..'] ^2Enjoy a secret 20% OFF any script of your choice on https://pulsescripts.tebex.io/freescript^0')
print('^1['..resourceName..'] ^2Using the coupon code: SPECIAL20 (one-time use coupon, choose wisely)^0')
end)
end
WaterMark()