1
0
Fork 0
forked from Simnation/Main
Main/resources/[inventory]/omi-printers/client/cl_main.lua
2025-06-26 02:48:12 +02:00

71 lines
2.1 KiB
Lua

local QBCore = exports["qb-core"]:GetCoreObject()
local Props = {}
local Targets = {}
function despawnprintersandtargets()
for i = 1, #Props do unloadModel(GetEntityModel(Props[i])) DeleteObject(Props[i]) end
for k in pairs(Targets) do exports['qb-target']:RemoveZone(k) end
end
CreateThread(function()
for k,v in pairs(Config.Printers) do
Props[#Props+1] = makeProp({coords = v.coords, prop = v.prop}, 1, false)
local name = 'Printers'..k
-- Vereinfachte Target-Option ohne Abhängigkeit von QBCore.Shared.Jobs
Targets[name] = exports['qb-target']:AddBoxZone(name, v.coords, 2.0, 2.0, {
heading = v.coords.w,
debugPoly = Config.Debug,
minZ = v.coords.z - 1,
maxZ = v.coords.z + 0.5,
}, {
options = {
{
event = 'moon-printers:client:useprinterbox',
icon = "fas fa-print",
label = 'Print Document',
job = k,
},
},
distance = 3.0
})
end
end)
-- Events
RegisterNetEvent('moon-printers:client:UsePaperDocument', function(ItemData)
local DocumentUrl = ItemData.info.url ~= nil and ItemData.info.url or false
SendNUIMessage({
action = "openprinternui",
url = DocumentUrl
})
SetNuiFocus(true, false)
end)
-- PRINTER AND DOCUMRNTS NUI
RegisterNetEvent('moon-printers:client:useprinterbox', function()
local ped = PlayerPedId()
local pos = GetEntityCoords(ped)
if PrinterObject ~= 0 then
SendNUIMessage({
action = "startprinternui"
})
SetNuiFocus(true, true)
end
end)
RegisterNUICallback('SaveDocument', function(data)
if data.url then
TriggerServerEvent('moon-printers:server:SavePaperDocument', data.url)
end
end)
RegisterNUICallback('CloseDocument', function()
SetNuiFocus(false, false)
end)
AddEventHandler('onResourceStop', function(resource) if resource == GetCurrentResourceName() then despawnprintersandtargets() end end)