forked from Simnation/Main
135 lines
5.7 KiB
Lua
135 lines
5.7 KiB
Lua
if GetResourceState('qb-core') == 'started' then
|
|
QBCore = exports['qb-core']:GetCoreObject()
|
|
elseif GetResourceState('es_extended') == 'started' then
|
|
ESX = exports['es_extended']:getSharedObject()
|
|
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)
|
|
print("[DEBUG] Image saved to database: " .. imageName)
|
|
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')
|
|
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))
|
|
|
|
MySQL.Async.fetchScalar('SELECT image_link FROM printer WHERE image_name = @imageName', {
|
|
['@imageName'] = imageName
|
|
}, function(imageLink)
|
|
if imageLink then
|
|
print("[DEBUG] Found image link: " .. tostring(imageLink))
|
|
TriggerClientEvent('pl_printer:showImage', src, imageLink)
|
|
else
|
|
print("[DEBUG] No Image Link Found for " .. tostring(imageName))
|
|
_debug('[DEBUG] '..' No Image Link Found for '..tostring(imageName)..'')
|
|
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
|
|
exports['qb-inventory']:AddItem(src, Config.ItemName, amount, false, info)
|
|
TriggerClientEvent('qb-inventory:client:ItemBox', src, QBCore.Shared.Items[Config.ItemName], 'add', amount)
|
|
else
|
|
local Player = getPlayer(src)
|
|
Player.Functions.AddItem(Config.ItemName, amount, false, info)
|
|
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[Config.ItemName], "add")
|
|
end
|
|
elseif GetResourceState('ox_inventory') == 'started' then
|
|
exports.ox_inventory:AddItem(src, Config.ItemName, amount, {type = imageName}, false)
|
|
elseif GetResourceState('qs-inventory') == 'started' then
|
|
local itemMetadata = {id = imageName}
|
|
exports['qs-inventory']:AddItem(src, Config.ItemName, amount, false, itemMetadata)
|
|
end
|
|
end
|
|
|
|
-- 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
|
|
if GetResourceState('ox_inventory') == 'started' then
|
|
exports(Config.ItemName, function(event, item, inventory, slot, data)
|
|
if event == 'usingItem' then
|
|
local item_metadata = exports.ox_inventory:GetSlot(inventory.id, slot)
|
|
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
|
|
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()
|