182 lines
		
	
	
	
		
			7.7 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			182 lines
		
	
	
	
		
			7.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')
 | 
						|
 | 
						|
-- 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(".*/(.*)$")
 | 
						|
        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 .. ", Rows changed: " .. tostring(rowsChanged))
 | 
						|
            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
 | 
						|
        print("[DEBUG] Player doesn't have enough money. Required: " .. tostring(TotalBill))
 | 
						|
        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('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)
 | 
						|
        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
 | 
						|
    
 | 
						|
    -- 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()
 | 
						|
    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()
 |