forked from Simnation/Main
234 lines
7.8 KiB
Lua
234 lines
7.8 KiB
Lua
local QBCore = exports['qb-core']:GetCoreObject()
|
|
|
|
-- Debug Print Function
|
|
local function Debug(msg)
|
|
print("^2[Shisha Debug] ^7" .. msg)
|
|
end
|
|
|
|
-- Check if qb-target is available
|
|
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)
|
|
|
|
-- Register Target for Shisha Props
|
|
CreateThread(function()
|
|
Wait(2000) -- Wait a bit longer to ensure everything is loaded
|
|
Debug("Registriere Target für Shisha-Props...")
|
|
|
|
-- Register the working model
|
|
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)
|
|
|
|
-- Try to register other models as well
|
|
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)
|
|
|
|
-- Event Handler for opening the menu
|
|
RegisterNetEvent('nordi_shisha:client:OpenMenu')
|
|
AddEventHandler('nordi_shisha:client:OpenMenu', function()
|
|
Debug("Öffne Menü...")
|
|
OpenShishaMenu()
|
|
end)
|
|
|
|
-- Check if player has required ingredients
|
|
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
|
|
|
|
-- Show warning for missing ingredients
|
|
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
|
|
|
|
-- Open the shisha menu
|
|
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
|
|
PrepareShisha(shisha)
|
|
else
|
|
ShowMissingIngredientsWarning(missingItems)
|
|
end
|
|
end
|
|
})
|
|
end
|
|
|
|
Debug("Zeige Menü...")
|
|
lib.registerContext({
|
|
id = 'shisha_menu',
|
|
title = 'Shisha',
|
|
options = options
|
|
})
|
|
|
|
lib.showContext('shisha_menu')
|
|
end
|
|
|
|
-- Prepare shisha function (without animation)
|
|
function PrepareShisha(selectedShisha)
|
|
Debug("Starte Shisha-Vorbereitung...")
|
|
|
|
-- Simple preparation without animation
|
|
QBCore.Functions.Progressbar("prepare_shisha", selectedShisha.label.." wird vorbereitet...", Config.PrepareTime or 5000, false, true, {
|
|
disableMovement = true,
|
|
disableCarMovement = true,
|
|
disableMouse = false,
|
|
disableCombat = true,
|
|
}, {}, {}, {}, function() -- Success
|
|
Debug("Shisha-Vorbereitung erfolgreich, löse Server-Event aus...")
|
|
TriggerServerEvent('shisha-script:consumeTobacco', selectedShisha.requires)
|
|
-- Start smoking after successful preparation
|
|
SmokeShisha(selectedShisha)
|
|
end, function() -- Cancelled
|
|
Debug("Shisha-Vorbereitung abgebrochen")
|
|
QBCore.Functions.Notify("Vorbereitung abgebrochen", "error")
|
|
end)
|
|
end
|
|
|
|
-- Smoke shisha function with animation and prop
|
|
function SmokeShisha(selectedShisha)
|
|
local ped = PlayerPedId()
|
|
local propName = "v_corp_lngestoolfd" -- Dieses Modell wird von irgendwo auf dem Server geladen
|
|
local propBone = 18905 -- Rechte Hand
|
|
|
|
-- Angepasste Position und Rotation für bessere Platzierung
|
|
local propCoords = vector3(0.10, 0.03, 0.05)
|
|
local propRotation = vector3(100.0, 0.0, 40.0)
|
|
|
|
-- Bessere Rauch-Animation
|
|
local animDict = "timetable@gardener@smoking_joint"
|
|
local animName = "smoke_idle"
|
|
|
|
-- Request model and animation
|
|
RequestModel(GetHashKey(propName))
|
|
while not HasModelLoaded(GetHashKey(propName)) do
|
|
Wait(0)
|
|
end
|
|
|
|
RequestAnimDict(animDict)
|
|
while not HasAnimDictLoaded(animDict) do
|
|
Wait(0)
|
|
end
|
|
|
|
-- Create and attach prop
|
|
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)
|
|
|
|
-- Play animation
|
|
TaskPlayAnim(ped, animDict, animName, 8.0, -8.0, -1, 49, 0, false, false, false)
|
|
|
|
-- Füge Raucheffekt hinzu
|
|
local smokeParticle = "exp_grd_bzgas_smoke"
|
|
RequestNamedPtfxAsset("core")
|
|
while not HasNamedPtfxAssetLoaded("core") do
|
|
Wait(0)
|
|
end
|
|
|
|
UseParticleFxAssetNextCall("core")
|
|
local smoke = StartParticleFxLoopedOnEntityBone(smokeParticle, prop, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, GetEntityBoneIndexByName(prop, "ATTACH_POINT"), 0.05, false, false, false)
|
|
SetParticleFxLoopedAlpha(smoke, 0.3)
|
|
|
|
-- Progress bar for smoking
|
|
QBCore.Functions.Progressbar("smoke_shisha", selectedShisha.label.." rauchen...", Config.SmokeTime or 30000, false, true, {
|
|
disableMovement = false,
|
|
disableCarMovement = false,
|
|
disableMouse = false,
|
|
disableCombat = true,
|
|
}, {}, {}, {}, function() -- Success
|
|
-- Clean up animation and prop
|
|
ClearPedTasks(ped)
|
|
DeleteObject(prop)
|
|
StopParticleFxLooped(smoke, 0)
|
|
|
|
-- Apply effects after smoking is complete
|
|
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() -- Cancelled
|
|
-- Clean up if cancelled
|
|
ClearPedTasks(ped)
|
|
DeleteObject(prop)
|
|
StopParticleFxLooped(smoke, 0)
|
|
end)
|
|
end
|
|
|
|
|
|
-- Debug Event
|
|
RegisterNetEvent('shisha-script:debug')
|
|
AddEventHandler('shisha-script:debug', function(msg)
|
|
Debug(msg)
|
|
end)
|