1
0
Fork 0
forked from Simnation/Main
Main/resources/[inventory]/nordi_hookah/client.lua

265 lines
8.3 KiB
Lua
Raw Normal View History

2025-06-25 02:26:26 +02:00
local QBCore = exports['qb-core']:GetCoreObject()
-- Debug Print Funktion
local function Debug(msg)
print("^2[Shisha Debug] ^7" .. msg)
end
2025-06-25 03:04:57 +02:00
-- Überprüfen, ob qb-target verfügbar ist
2025-06-25 02:26:26 +02:00
CreateThread(function()
2025-06-25 02:51:13 +02:00
Wait(1000)
2025-06-25 03:04:57 +02:00
Debug("Überprüfe, ob qb-target verfügbar ist...")
2025-06-25 02:51:13 +02:00
if exports['qb-target'] then
2025-06-25 03:04:57 +02:00
Debug("qb-target Export ist verfügbar")
2025-06-25 02:51:13 +02:00
else
2025-06-25 03:04:57 +02:00
Debug("FEHLER: qb-target Export ist NICHT verfügbar!")
2025-06-25 02:51:13 +02:00
end
end)
2025-06-25 03:04:57 +02:00
-- Überprüfen, ob das Modell gültig ist und geladen werden kann
2025-06-25 02:51:13 +02:00
CreateThread(function()
2025-06-25 03:04:57 +02:00
Debug("Überprüfe Prop-Modell-Hash...")
2025-06-25 02:51:13 +02:00
local modelName = "prop_bong_01"
local modelHash = GetHashKey(modelName)
2025-06-25 03:04:57 +02:00
Debug(modelName .. " Hash: " .. modelHash)
2025-06-25 02:51:13 +02:00
if IsModelValid(modelHash) then
2025-06-25 03:04:57 +02:00
Debug("Modell ist gültig!")
2025-06-25 02:51:13 +02:00
else
2025-06-25 03:04:57 +02:00
Debug("Modell ist NICHT gültig!")
2025-06-25 02:51:13 +02:00
end
if IsModelInCdimage(modelHash) then
2025-06-25 03:04:57 +02:00
Debug("Modell ist im CD-Image!")
2025-06-25 02:51:13 +02:00
else
2025-06-25 03:04:57 +02:00
Debug("Modell ist NICHT im CD-Image!")
2025-06-25 02:51:13 +02:00
end
2025-06-25 03:04:57 +02:00
-- Versuche, das Modell zu laden
2025-06-25 02:51:13 +02:00
RequestModel(modelHash)
local timeout = 0
while not HasModelLoaded(modelHash) and timeout < 50 do
Wait(100)
timeout = timeout + 1
end
if HasModelLoaded(modelHash) then
2025-06-25 03:04:57 +02:00
Debug("Modell erfolgreich geladen!")
2025-06-25 02:51:13 +02:00
else
2025-06-25 03:04:57 +02:00
Debug("Modell konnte nach " .. timeout * 100 .. "ms nicht geladen werden!")
2025-06-25 02:51:13 +02:00
end
end)
2025-06-25 03:04:57 +02:00
-- Registriere Target für Modell
2025-06-25 02:51:13 +02:00
CreateThread(function()
2025-06-25 03:04:57 +02:00
Debug("Registriere Target für Modelle...")
2025-06-25 02:51:13 +02:00
2025-06-25 03:04:57 +02:00
-- Versuche sowohl String- als auch Hash-Methoden
2025-06-25 02:51:13 +02:00
local modelName = "prop_bong_01"
local modelHash = GetHashKey(modelName)
2025-06-25 03:04:57 +02:00
-- Methode 1: Mit String
2025-06-25 02:51:13 +02:00
exports['qb-target']:AddTargetModel(modelName, {
options = {
{
num = 1,
type = "client",
event = "nordi_shisha:client:OpenMenu",
icon = 'fas fa-smoking',
label = 'Shisha rauchen (String)',
}
},
distance = 2.0
})
2025-06-25 03:04:57 +02:00
Debug("Target für Modell-String registriert: " .. modelName)
2025-06-25 02:51:13 +02:00
2025-06-25 03:04:57 +02:00
-- Methode 2: Mit Hash
2025-06-25 02:51:13 +02:00
exports['qb-target']:AddTargetModel(modelHash, {
options = {
{
num = 1,
type = "client",
event = "nordi_shisha:client:OpenMenu",
icon = 'fas fa-smoking',
label = 'Shisha rauchen (Hash)',
}
},
distance = 2.0
})
2025-06-25 03:04:57 +02:00
Debug("Target für Modell-Hash registriert: " .. modelHash)
-- Registriere alle konfigurierten Shisha-Props
for _, propName in ipairs(Config.ShishaProps) do
exports['qb-target']:AddTargetModel(propName, {
options = {
{
num = 1,
type = "client",
event = "nordi_shisha:client:OpenMenu",
icon = 'fas fa-smoking',
label = 'Shisha rauchen',
}
},
distance = 2.0
})
Debug("Target für Modell registriert: " .. propName)
2025-06-25 02:26:26 +02:00
end
end)
-- Event Handler für das Öffnen des Menüs
RegisterNetEvent('nordi_shisha:client:OpenMenu')
AddEventHandler('nordi_shisha:client:OpenMenu', function()
2025-06-25 03:04:57 +02:00
Debug("Öffne Menü...")
2025-06-25 02:26:26 +02:00
OpenShishaMenu()
end)
function CheckIngredients(requirements)
local hasItems = true
local missingItems = {}
for _, requirement in ipairs(requirements) do
local hasItem = QBCore.Functions.HasItem(requirement.item, requirement.amount)
if not hasItem then
hasItems = false
table.insert(missingItems, {
item = requirement.item,
required = requirement.amount
})
end
end
return hasItems, missingItems
end
function ShowMissingIngredientsWarning(missingItems)
local warningText = "Fehlende Zutaten:\n"
for _, item in ipairs(missingItems) do
local itemLabel = QBCore.Shared.Items[item.item].label
warningText = warningText .. "- " .. itemLabel .. " (benötigt: " .. item.required .. ")\n"
end
QBCore.Functions.Notify(warningText, "error", 5000)
end
function OpenShishaMenu()
2025-06-25 03:04:57 +02:00
Debug("Erstelle Menüoptionen...")
2025-06-25 02:26:26 +02:00
local options = {}
for _, shisha in ipairs(Config.ShishaOptions) do
local hasIngredients, missing = CheckIngredients(shisha.requires)
local description = shisha.description .. "\n\nBenötigt:"
for _, req in ipairs(shisha.requires) do
local itemLabel = QBCore.Shared.Items[req.item].label
local hasItem = QBCore.Functions.HasItem(req.item, req.amount)
local status = hasItem and "~g~✓" or "~r~✗"
description = description .. "\n- " .. req.amount .. "x " .. itemLabel .. " " .. status
end
table.insert(options, {
title = shisha.label,
description = description,
icon = shisha.icon,
onSelect = function()
local canMake, missingItems = CheckIngredients(shisha.requires)
if canMake then
PrepareAndSmokeShisha(shisha)
else
ShowMissingIngredientsWarning(missingItems)
end
end
})
end
2025-06-25 03:04:57 +02:00
Debug("Zeige Menü...")
2025-06-25 02:26:26 +02:00
lib.registerContext({
id = 'shisha_menu',
title = 'Shisha',
options = options
})
lib.showContext('shisha_menu')
end
function PrepareAndSmokeShisha(selectedShisha)
2025-06-25 03:04:57 +02:00
Debug("Starte Shisha-Vorbereitung...")
2025-06-25 02:26:26 +02:00
local player = PlayerPedId()
local animDict = "anim@heists@humane_labs@finale@keycards"
local anim = "ped_a_enter_loop"
RequestAnimDict(animDict)
while not HasAnimDictLoaded(animDict) do
Wait(0)
end
QBCore.Functions.Progressbar("prepare_shisha", selectedShisha.label.." wird vorbereitet...", Config.PrepareTime or 5000, false, true, {
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
}, {
animDict = animDict,
anim = anim,
flags = 49,
}, {}, {}, function() -- Erfolg
2025-06-25 03:04:57 +02:00
Debug("Shisha-Vorbereitung erfolgreich, löse Server-Event aus...")
2025-06-25 02:26:26 +02:00
TriggerServerEvent('shisha-script:consumeTobacco', selectedShisha.requires)
-- Nach erfolgreicher Vorbereitung direkt rauchen
SmokeShisha(selectedShisha)
end, function() -- Abgebrochen
2025-06-25 03:04:57 +02:00
Debug("Shisha-Vorbereitung abgebrochen")
2025-06-25 02:26:26 +02:00
QBCore.Functions.Notify("Vorbereitung abgebrochen", "error")
end)
end
function SmokeShisha(selectedShisha)
local ped = PlayerPedId()
2025-06-25 02:51:13 +02:00
local propName = "v_corp_lngestoolfd" -- Dieses Modell wird aus dem Stream-Ordner geladen
2025-06-25 02:26:26 +02:00
local propBone = 28422
local propCoords = vector3(0.0, 0.0, -0.03)
local propRotation = vector3(0.0, 0.0, 0.0)
local animDict = "amb@world_human_aa_smoke@male@idle_a"
local animName = "idle_c"
RequestModel(GetHashKey(propName))
while not HasModelLoaded(GetHashKey(propName)) do
Wait(0)
end
RequestAnimDict(animDict)
while not HasAnimDictLoaded(animDict) do
Wait(0)
end
local prop = CreateObject(GetHashKey(propName), 0.0, 0.0, 0.0, true, true, true)
AttachEntityToEntity(prop, ped, GetPedBoneIndex(ped, propBone), propCoords.x, propCoords.y, propCoords.z, propRotation.x, propRotation.y, propRotation.z, true, true, false, true, 1, true)
TaskPlayAnim(ped, animDict, animName, 8.0, -8.0, -1, 49, 0, false, false, false)
QBCore.Functions.Progressbar("smoke_shisha", selectedShisha.label.." rauchen...", Config.SmokeTime or 10000, false, true, {
disableMovement = false,
disableCarMovement = false,
disableMouse = false,
disableCombat = true,
}, {}, {}, {}, function() -- Erfolg
ClearPedTasks(ped)
DeleteObject(prop)
TriggerEvent("evidence:client:SetStatus", "weedsmell", 300)
TriggerServerEvent('hud:server:RelieveStress', math.random(15, 25))
QBCore.Functions.Notify("Du fühlst dich entspannt...", "success")
end, function() -- Abgebrochen
ClearPedTasks(ped)
DeleteObject(prop)
end)
end
-- Debug Event
RegisterNetEvent('shisha-script:debug')
AddEventHandler('shisha-script:debug', function(msg)
Debug(msg)
end)