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

239 lines
7.9 KiB
Lua
Raw Normal View History

2025-06-25 03:26:36 +02:00
local QBCore = exports['qb-core']:GetCoreObject()
2025-06-25 02:26:26 +02:00
2025-06-25 03:34:12 +02:00
-- Debug Print Function
2025-06-25 03:26:36 +02:00
local function Debug(msg)
print("^2[Shisha Debug] ^7" .. msg)
end
2025-06-25 02:26:26 +02:00
2025-06-25 03:34:12 +02:00
-- Check if qb-target is available
2025-06-25 03:26:36 +02:00
CreateThread(function()
Wait(1000)
Debug("Überprüfe, ob qb-target verfügbar ist...")
if exports['qb-target'] then
Debug("qb-target Export ist verfügbar")
else
Debug("FEHLER: qb-target Export ist NICHT verfügbar!")
end
end)
2025-06-25 02:51:13 +02:00
2025-06-25 03:34:12 +02:00
-- Register Target for Shisha Props
2025-06-25 03:26:36 +02:00
CreateThread(function()
2025-06-25 03:34:12 +02:00
Wait(2000) -- Wait a bit longer to ensure everything is loaded
2025-06-25 03:26:36 +02:00
Debug("Registriere Target für Shisha-Props...")
2025-06-25 03:34:12 +02:00
-- Register the working model
2025-06-25 03:26:36 +02:00
local workingModel = "sf_prop_sf_g_bong_01a"
Debug("Registriere Target für funktionierendes Modell: " .. workingModel)
exports['qb-target']:AddTargetModel(workingModel, {
options = {
{
type = "client",
event = "nordi_shisha:client:OpenMenu",
icon = 'fas fa-smoking',
label = 'Shisha rauchen',
}
},
distance = 2.0
})
Debug("Target für Modell registriert: " .. workingModel)
2025-06-25 03:34:12 +02:00
-- Try to register other models as well
2025-06-25 03:26:36 +02:00
for _, propName in ipairs(Config.ShishaProps) do
if propName ~= workingModel then
Debug("Versuche zusätzliches Modell zu registrieren: " .. propName)
exports['qb-target']:AddTargetModel(propName, {
options = {
{
type = "client",
event = "nordi_shisha:client:OpenMenu",
icon = 'fas fa-smoking',
label = 'Shisha rauchen',
}
},
distance = 2.0
})
end
end
end)
2025-06-25 02:26:26 +02:00
2025-06-25 03:34:12 +02:00
-- Event Handler for opening the menu
2025-06-25 03:26:36 +02:00
RegisterNetEvent('nordi_shisha:client:OpenMenu')
AddEventHandler('nordi_shisha:client:OpenMenu', function()
Debug("Öffne Menü...")
OpenShishaMenu()
end)
2025-06-25 03:34:12 +02:00
-- Check if player has required ingredients
2025-06-25 03:26:36 +02:00
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
2025-06-25 03:34:12 +02:00
-- Show warning for missing ingredients
2025-06-25 03:26:36 +02:00
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
2025-06-25 03:34:12 +02:00
-- Open the shisha menu
2025-06-25 03:26:36 +02:00
function OpenShishaMenu()
Debug("Erstelle Menüoptionen...")
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
2025-06-25 03:46:55 +02:00
PrepareShisha(shisha)
2025-06-25 03:26:36 +02:00
else
ShowMissingIngredientsWarning(missingItems)
end
end
})
end
Debug("Zeige Menü...")
lib.registerContext({
id = 'shisha_menu',
title = 'Shisha',
options = options
})
lib.showContext('shisha_menu')
end
2025-06-25 03:46:55 +02:00
-- Prepare shisha function (without animation)
function PrepareShisha(selectedShisha)
2025-06-25 03:26:36 +02:00
Debug("Starte Shisha-Vorbereitung...")
2025-06-25 03:46:55 +02:00
-- Simple preparation without animation
2025-06-25 03:26:36 +02:00
QBCore.Functions.Progressbar("prepare_shisha", selectedShisha.label.." wird vorbereitet...", Config.PrepareTime or 5000, false, true, {
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
2025-06-25 03:46:55 +02:00
}, {}, {}, {}, function() -- Success
2025-06-25 03:26:36 +02:00
Debug("Shisha-Vorbereitung erfolgreich, löse Server-Event aus...")
TriggerServerEvent('shisha-script:consumeTobacco', selectedShisha.requires)
2025-06-25 03:34:12 +02:00
-- Start smoking after successful preparation
2025-06-25 04:24:39 +02:00
StartShishaSmoking(selectedShisha)
2025-06-25 03:34:12 +02:00
end, function() -- Cancelled
2025-06-25 03:26:36 +02:00
Debug("Shisha-Vorbereitung abgebrochen")
QBCore.Functions.Notify("Vorbereitung abgebrochen", "error")
end)
end
2025-06-25 04:24:39 +02:00
-- Smoke shisha function with animation and smoke effect
function StartShishaSmoking(selectedShisha)
2025-06-25 03:26:36 +02:00
local ped = PlayerPedId()
2025-06-25 04:24:39 +02:00
local smokeTime = Config.SmokeTime or 30000
2025-06-25 04:31:46 +02:00
local animDict = "amb@world_human_aa_smoke@male@idle_a"
local animName = "idle_a"
2025-06-25 03:26:36 +02:00
2025-06-25 04:31:46 +02:00
-- Request animation dictionary
2025-06-25 03:26:36 +02:00
RequestAnimDict(animDict)
while not HasAnimDictLoaded(animDict) do
2025-06-25 04:24:39 +02:00
Wait(10)
end
2025-06-25 04:31:46 +02:00
-- Create a separate thread to keep the animation playing
local smokingActive = true
2025-06-25 04:44:19 +02:00
CreateThread(function()
2025-06-25 04:31:46 +02:00
-- Play animation and keep it playing
while smokingActive do
if not IsEntityPlayingAnim(ped, animDict, animName, 3) then
TaskPlayAnim(ped, animDict, animName, 8.0, -8.0, -1, 49, 0, false, false, false)
end
Wait(500)
end
end)
2025-06-25 04:24:39 +02:00
-- Create smoke effect
2025-06-25 04:31:46 +02:00
CreateThread(function()
RequestNamedPtfxAsset("core")
while not HasNamedPtfxAssetLoaded("core") do
Wait(10)
end
while smokingActive do
UseParticleFxAssetNextCall("core")
SetParticleFxNonLoopedColour(1.0, 1.0, 1.0)
SetParticleFxNonLoopedAlpha(0.7)
StartParticleFxNonLoopedOnPedBone("exp_grd_bzgas_smoke", ped, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, GetPedBoneIndex(ped, 20279), 0.5, false, false, false)
Wait(2000) -- Emit smoke every 2 seconds
end
end)
2025-06-25 03:26:36 +02:00
2025-06-25 03:46:55 +02:00
-- Progress bar for smoking
2025-06-25 04:24:39 +02:00
QBCore.Functions.Progressbar("smoke_shisha", selectedShisha.label.." rauchen...", smokeTime, false, true, {
2025-06-25 03:26:36 +02:00
disableMovement = false,
disableCarMovement = false,
disableMouse = false,
disableCombat = true,
2025-06-25 03:34:12 +02:00
}, {}, {}, {}, function() -- Success
2025-06-25 04:31:46 +02:00
-- Stop the animation and smoke effect
smokingActive = false
2025-06-25 03:26:36 +02:00
ClearPedTasks(ped)
2025-06-25 03:46:55 +02:00
2025-06-25 04:44:19 +02:00
-- Warte einen kurzen Moment, um sicherzustellen, dass alle Threads beendet sind
Wait(500)
-- JETZT erst die Effekte anwenden und Nachricht anzeigen
Debug("Rauchen vollständig abgeschlossen")
2025-06-25 03:26:36 +02:00
TriggerEvent("evidence:client:SetStatus", "weedsmell", 300)
TriggerServerEvent('hud:server:RelieveStress', math.random(15, 25))
2025-06-25 04:44:19 +02:00
-- Warte noch einen Moment, bevor die Entspannungsnachricht angezeigt wird
Wait(1000)
2025-06-25 03:26:36 +02:00
QBCore.Functions.Notify("Du fühlst dich entspannt...", "success")
2025-06-25 04:44:19 +02:00
Debug("Entspannungseffekte angewendet")
2025-06-25 03:34:12 +02:00
end, function() -- Cancelled
2025-06-25 03:46:55 +02:00
-- Clean up if cancelled
2025-06-25 04:31:46 +02:00
smokingActive = false
2025-06-25 03:26:36 +02:00
ClearPedTasks(ped)
2025-06-25 04:24:39 +02:00
Debug("Rauchen abgebrochen")
2025-06-25 03:26:36 +02:00
end)
end
-- Debug Event
RegisterNetEvent('shisha-script:debug')
AddEventHandler('shisha-script:debug', function(msg)
Debug(msg)
end)