1
0
Fork 0
forked from Simnation/Main
This commit is contained in:
Nordi98 2025-06-26 04:08:54 +02:00
parent 0484090600
commit b2139d1237
3 changed files with 197 additions and 51 deletions

View file

@ -1,11 +1,8 @@
local spawnedObjects = {}
local imageDisplayed = false
RegisterNetEvent('pl_printer:notification')
AddEventHandler('pl_printer:notification', function(message, type)
if Config.Notify == 'ox' then
TriggerEvent('ox_lib:notify', {description = message, type = type or "success"})
elseif Config.Notify == 'esx' then
@ -31,40 +28,69 @@ function enableControls()
FreezeEntityPosition(PlayerPedId(), false)
end
-- Event für QB-Core Inventar
RegisterNetEvent("pl_printer:showImageQB")
AddEventHandler("pl_printer:showImageQB", function(imageName)
TriggerServerEvent('pl_printer:fetchImageLink',imageName)
print("[DEBUG] Received showImageQB event with imageName: " .. tostring(imageName))
TriggerServerEvent('pl_printer:fetchImageLink', imageName)
end)
-- Hauptevent zum Anzeigen des Bildes
RegisterNetEvent("pl_printer:showImage")
AddEventHandler("pl_printer:showImage", function(imageName)
AddEventHandler("pl_printer:showImage", function(imageUrl)
print("[DEBUG] Received showImage event with URL: " .. tostring(imageUrl))
if not imageDisplayed then
imageDisplayed = true
SetNuiFocus(true, true)
-- Extrahiere den Dateinamen aus der URL für die Dokument-ID
local documentId = imageUrl:match(".*/(.*)$") or "unknown"
SendNUIMessage({
action = "show",
imageUrl = imageName
imageUrl = imageUrl,
documentId = documentId -- Füge die Dokument-ID hinzu
})
disableControls()
else
print("[DEBUG] Image already displayed, ignoring request")
end
end)
-- NUI-Callback zum Schließen des Bildes
RegisterNUICallback('hideFrame', function(data, cb)
print("[DEBUG] Hiding image frame")
imageDisplayed = false
SetNuiFocus(false, false)
enableControls()
-- Füge einen Callback hinzu, wenn er benötigt wird
if cb then cb('ok') end
end)
-- Sicherheits-Callback für den Fall, dass die Seite neu geladen wird
RegisterNUICallback('pageLoaded', function(data, cb)
print("[DEBUG] NUI page loaded")
-- Stelle sicher, dass der Focus zurückgesetzt wird, falls die Seite neu geladen wurde
if not imageDisplayed then
SetNuiFocus(false, false)
end
if cb then cb('ok') end
end)
-- Event zum Öffnen des Druckermenüs
RegisterNetEvent("pl_printer:openprinter")
AddEventHandler("pl_printer:openprinter", function()
local input = lib.inputDialog('Print Menu', {
{type = 'input', label = Locale("image_link"), description = Locale("image_url"), required = true},
{type = 'number', label = Locale("copies"), description = Locale("image_url"),required = true,placeholder='1', icon = 'hashtag'},
{type = 'number', label = Locale("copies"), description = Locale("image_url"), required = true, placeholder='1', icon = 'hashtag'},
})
if input then
if input[1] and input[2] then
print("[DEBUG] Sending image data to server: " .. input[1] .. ", copies: " .. input[2])
TriggerServerEvent('pl_printer:insertImageData', input[1], input[2])
else
_debug('[DEBUG] '..'Invalid Input'..'')
@ -72,6 +98,7 @@ AddEventHandler("pl_printer:openprinter", function()
end
end)
-- Target-System-Konfiguration
for _, model in ipairs(Config.PrinterModel) do
if GetResourceState('qb-target') == 'started' then
exports['qb-target']:AddTargetModel(model, {
@ -86,7 +113,7 @@ for _, model in ipairs(Config.PrinterModel) do
},
distance = 2
})
elseif GetResourceState('qtarget') == 'started' or GetResourceState('ox_target') == 'started'then
elseif GetResourceState('qtarget') == 'started' or GetResourceState('ox_target') == 'started' then
exports.ox_target:addModel(model, {
{
name = 'printer_interaction',
@ -101,7 +128,7 @@ for _, model in ipairs(Config.PrinterModel) do
end
end
-- Funktion zum Spawnen von Objekten
local function spawnObject(object, coords, heading)
lib.requestModel(object)
@ -109,6 +136,7 @@ local function spawnObject(object, coords, heading)
_debug('[DEBUG] '..object..' failed to load.'..'')
return
end
local entity = CreateObject(object, coords.x, coords.y, coords.z, true, true, true)
if DoesEntityExist(entity) then
@ -120,7 +148,7 @@ local function spawnObject(object, coords, heading)
end
end
-- Funktion zum Löschen von gespawnten Objekten
local function deleteSpawnedObjects()
for _, obj in ipairs(spawnedObjects) do
if DoesEntityExist(obj) then
@ -130,7 +158,7 @@ local function deleteSpawnedObjects()
spawnedObjects = {}
end
-- Resource-Start-Event
AddEventHandler('onResourceStart', function(resourceName)
if GetCurrentResourceName() ~= resourceName then return end
for _, location in ipairs(Config.Locations) do
@ -138,12 +166,13 @@ AddEventHandler('onResourceStart', function(resourceName)
end
end)
-- Resource-Stop-Event
AddEventHandler('onResourceStop', function(resourceName)
if GetCurrentResourceName() ~= resourceName then return end
deleteSpawnedObjects()
end)
-- Funktion für Spieler-Login
function onPlayerLoaded()
Wait(3000)
for _, location in ipairs(Config.Locations) do
@ -151,8 +180,52 @@ function onPlayerLoaded()
end
end
-- Debug-Hilfsfunktion
function _debug(...)
if Config.Debug then
print(...)
end
end
end
-- Notfall-Thread zum Zurücksetzen des NUI-Focus, falls etwas schief geht
Citizen.CreateThread(function()
while true do
Citizen.Wait(1000)
if imageDisplayed then
-- Prüfe, ob ESC gedrückt wurde (Fallback für den Fall, dass der NUI-Callback nicht funktioniert)
if IsControlJustReleased(0, 177) then -- ESC-Taste
print("[DEBUG] ESC key detected in thread, resetting focus")
imageDisplayed = false
SetNuiFocus(false, false)
enableControls()
SendNUIMessage({
action = "hide"
})
end
else
Citizen.Wait(1000) -- Längere Wartezeit, wenn kein Bild angezeigt wird
end
end
end)
-- Füge diesen Code hinzu, um das HTML zu aktualisieren, wenn die Ressource neu gestartet wird
AddEventHandler('onResourceStart', function(resourceName)
if GetCurrentResourceName() == resourceName then
-- Stelle sicher, dass der NUI-Focus zurückgesetzt wird
SetNuiFocus(false, false)
imageDisplayed = false
enableControls()
end
end)
-- Füge diesen Code hinzu, um den NUI-Focus zurückzusetzen, wenn der Spieler stirbt
AddEventHandler('playerSpawned', function()
if imageDisplayed then
imageDisplayed = false
SetNuiFocus(false, false)
enableControls()
SendNUIMessage({
action = "hide"
})
end
end)

View file

@ -1,7 +1,7 @@
if GetResourceState('qb-core') == 'started' then
QBCore = exports['qb-core']:GetCoreObject()
QBCore = exports['qb-core']:GetCoreObject()
elseif GetResourceState('es_extended') == 'started' then
ESX = exports['es_extended']:getSharedObject()
ESX = exports['es_extended']:getSharedObject()
end
local resourceName = 'pl_printer'
lib.versionCheck('pulsepk/pl_printer')
@ -19,7 +19,7 @@ AddEventHandler('pl_printer:insertImageData', function(imageUrl, amount)
['@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')
@ -31,18 +31,26 @@ AddEventHandler('pl_printer:insertImageData', function(imageUrl, amount)
end
end)
RegisterServerEvent('pl_printer:fetchImageLink')
AddEventHandler('pl_printer:fetchImageLink', function(imageName,playerSource)
local hasItem = HasItem(playerSource)
if not hasItem then return end
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
TriggerClientEvent('pl_printer:showImage',playerSource,imageLink)
print("[DEBUG] Found image link: " .. tostring(imageLink))
TriggerClientEvent('pl_printer:showImage', src, imageLink)
else
_debug('[DEBUG] '..' No Image Link Found for '..imageName..'')
print("[DEBUG] No Image Link Found for " .. tostring(imageName))
_debug('[DEBUG] '..' No Image Link Found for '..tostring(imageName)..'')
end
end)
end)
@ -54,27 +62,62 @@ function AddItem(source, amount, 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)
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)
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,imageName,false)
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)
local itemMetadata = {id = imageName}
exports['qs-inventory']:AddItem(src, Config.ItemName, amount, false, itemMetadata)
end
end
AddEventHandler('onServerResourceStart', function()
-- 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)
exports(Config.ItemName, function(event, item, inventory, slot, data)
if event == 'usingItem' then
local item_metadata = exports.ox_inventory:GetSlot(inventory.id, slot)
TriggerEvent('pl_printer:fetchImageLink', item_metadata.metadata.type, inventory.id)
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
@ -86,13 +129,7 @@ local WaterMark = function()
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()

View file

@ -10,39 +10,75 @@
margin: 0;
padding: 0;
overflow: hidden;
/* Entferne den Hintergrund, der den Schleier verursacht */
background-color: transparent;
}
#image {
#image-container {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
max-width: 90%;
max-height: 90%;
display: none;
}
#image {
max-width: 100%;
max-height: 100%;
}
#document-id {
position: absolute;
bottom: 10px;
left: 10px;
color: white;
background-color: rgba(0, 0, 0, 0.5);
padding: 5px;
border-radius: 3px;
font-family: Arial, sans-serif;
display: none; /* Verstecke die Dokument-ID standardmäßig */
}
</style>
</head>
<body>
<img id="image" src="" alt="Image" style="display:none;">
<div id="image-container">
<img id="image" src="" alt="Document">
<div id="document-id"></div>
</div>
<script>
window.addEventListener('message', function(event) {
if (event.data.action === 'show') {
// Zeige das spezifische Dokument basierend auf der URL
document.getElementById('image').src = event.data.imageUrl;
document.getElementById('image').style.display = 'block';
// Zeige optional die Dokument-ID an (nur wenn Debug aktiviert ist)
if (event.data.documentId && false) { // Setze auf true für Debug
document.getElementById('document-id').textContent = "Dokument: " + event.data.documentId;
document.getElementById('document-id').style.display = 'block';
} else {
document.getElementById('document-id').style.display = 'none';
}
document.getElementById('image-container').style.display = 'block';
// Logge die Dokument-Informationen zur Fehlersuche
console.log("Dokument angezeigt:", event.data);
} else if (event.data.action === 'hide') {
document.getElementById('image').style.display = 'none';
document.getElementById('image-container').style.display = 'none';
}
});
document.addEventListener("keydown", function(event) {
if (event.key === "Escape") {
document.getElementById('image').style.display = 'none';
axios.post(`https://${GetParentResourceName()}/hideFrame`, {})
.then(function (response) {
})
.catch(function (error) {
});
}
});
if (event.key === "Escape") {
document.getElementById('image-container').style.display = 'none';
axios.post(`https://${GetParentResourceName()}/hideFrame`, {})
.then(function (response) {
console.log("Frame versteckt");
})
.catch(function (error) {
console.error("Fehler beim Verstecken des Frames:", error);
});
}
});
</script>
</body>
</html>