From 873f9b15f7b6509e8c713bc135cd29524436cc5f Mon Sep 17 00:00:00 2001 From: Nordi98 Date: Wed, 25 Jun 2025 02:26:26 +0200 Subject: [PATCH] shisha --- resources/[inventory]/nordi_hookah/client.lua | 180 ++++++++++++++++++ .../[inventory]/nordi_hookah/client/main.lua | 91 --------- resources/[inventory]/nordi_hookah/config.lua | 62 ++++++ .../[inventory]/nordi_hookah/fxmanifest.lua | 26 +++ resources/[inventory]/nordi_hookah/server.lua | 38 ++++ .../[inventory]/nordi_hookah/server/main.lua | 13 -- resources/[props]/hookah/fxmanifest.lua | 10 + .../hookah}/stream/prop_bong_01.ydr | Bin .../hookah}/stream/props.ytyp | 0 .../hookah}/stream/v_corp_lngestoolfd.ydr | Bin 10 files changed, 316 insertions(+), 104 deletions(-) create mode 100644 resources/[inventory]/nordi_hookah/client.lua delete mode 100644 resources/[inventory]/nordi_hookah/client/main.lua create mode 100644 resources/[inventory]/nordi_hookah/config.lua create mode 100644 resources/[inventory]/nordi_hookah/server.lua delete mode 100644 resources/[inventory]/nordi_hookah/server/main.lua create mode 100644 resources/[props]/hookah/fxmanifest.lua rename resources/{[inventory]/nordi_hookah => [props]/hookah}/stream/prop_bong_01.ydr (100%) rename resources/{[inventory]/nordi_hookah => [props]/hookah}/stream/props.ytyp (100%) rename resources/{[inventory]/nordi_hookah => [props]/hookah}/stream/v_corp_lngestoolfd.ydr (100%) diff --git a/resources/[inventory]/nordi_hookah/client.lua b/resources/[inventory]/nordi_hookah/client.lua new file mode 100644 index 000000000..dbeeb01f1 --- /dev/null +++ b/resources/[inventory]/nordi_hookah/client.lua @@ -0,0 +1,180 @@ +local QBCore = exports['qb-core']:GetCoreObject() + +-- Debug Print Funktion +local function Debug(msg) + print("^2[Shisha Debug] ^7" .. msg) +end + +CreateThread(function() + Debug("Script starting...") + for _, prop in pairs(Config.ShishaProps) do + exports['qb-target']:AddTargetModel(prop, { + options = { + { + num = 1, + type = "client", + event = "nordi_shisha:client:OpenMenu", + icon = 'fas fa-smoking', + label = 'Shisha rauchen', + } + }, + distance = 2.0 + }) + end + Debug("Target options registered") +end) + +-- Event Handler für das Öffnen des Menüs +RegisterNetEvent('nordi_shisha:client:OpenMenu') +AddEventHandler('nordi_shisha:client:OpenMenu', function() + Debug("Opening menu...") + 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() + Debug("Building menu options...") + 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 + + Debug("Showing menu...") + lib.registerContext({ + id = 'shisha_menu', + title = 'Shisha', + options = options + }) + + lib.showContext('shisha_menu') +end + +function PrepareAndSmokeShisha(selectedShisha) + Debug("Starting shisha preparation...") + 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 + Debug("Shisha preparation successful, triggering server event...") + TriggerServerEvent('shisha-script:consumeTobacco', selectedShisha.requires) + -- Nach erfolgreicher Vorbereitung direkt rauchen + SmokeShisha(selectedShisha) + end, function() -- Abgebrochen + Debug("Shisha preparation cancelled") + QBCore.Functions.Notify("Vorbereitung abgebrochen", "error") + end) +end + +function SmokeShisha(selectedShisha) + local ped = PlayerPedId() + local propName = "v_corp_lngestoolfd" + 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) diff --git a/resources/[inventory]/nordi_hookah/client/main.lua b/resources/[inventory]/nordi_hookah/client/main.lua deleted file mode 100644 index a48794282..000000000 --- a/resources/[inventory]/nordi_hookah/client/main.lua +++ /dev/null @@ -1,91 +0,0 @@ -local Config = { - HookahProp = 'prop_bong_01', -- Eigenes Prop (ohne .ydr/.ytd) - TobaccoItem = 'shisha_tobacco', - Keybind = 'E', - Animation = { - dict = 'anim@amb@clubhouse@table@male@smoking@base', - anim = 'base', - prop = 'v_corp_lngestoolfd', - flag = 49, - bone = 57005 - }, - SmokeEffect = { - name = 'ent_anim_cig_exhale_mth', - scale = 0.2 - }, - UseDuration = 30 -- Sekunden -} - -local isSmoking = false -local smokeEffect = nil - --- Preload Assets -CreateThread(function() - RequestModel(Config.HookahProp) - RequestAnimDict(Config.Animation.dict) - while not HasModelLoaded(Config.HookahProp) or not HasAnimDictLoaded(Config.Animation.dict) do - Wait(0) - end -end) - --- Hookah Placement Logic -RegisterCommand('placehookah', function() - if isSmoking then return end - - local playerPed = PlayerPedId() - local coords = GetOffsetFromEntityInWorldCoords(playerPed, 0.0, 0.8, -0.4) - local heading = GetEntityHeading(playerPed) - - local hookah = CreateObject(Config.HookahProp, coords.x, coords.y, coords.z, true, true, true) - PlaceObjectOnGroundProperly(hookah) - SetEntityHeading(hookah, heading) - FreezeEntityPosition(hookah, true) - - exports['qb-target']:AddTargetEntity(hookah, { - options = { - { - type = 'client', - event = 'qb-hookah:startSmoking', - icon = 'fas fa-smoking', - label = 'Smoke Hookah', - targeticon = 'fas fa-eye', - item = Config.TobaccoItem - } - }, - distance = 2.5 - }) -end, false) - --- Smoking Logic -RegisterNetEvent('qb-hookah:startSmoking', function(entity) - if isSmoking then return end - - QBCore.Functions.TriggerCallback('qb-hookah:removeTobacco', function(success) - if not success then - QBCore.Functions.Notify('You need hookah tobacco!', 'error') - return - end - - isSmoking = true - local playerPed = PlayerPedId() - local animDict = Config.Animation.dict - - -- Attach bong prop - local bong = CreateObject(Config.Animation.prop, GetEntityCoords(playerPed), true, true, true) - AttachEntityToEntity(bong, playerPed, Config.Animation.bone, 0.12, 0.018, -0.01, -80.0, -20.0, 180.0, true, true, false, true, 1, true) - - -- Play animation - TaskPlayAnim(playerPed, animDict, Config.Animation.anim, 8.0, -8.0, Config.UseDuration * 1000, Config.Animation.flag, 0, false, false, false) - - -- Smoke effect - UseParticleFxAssetNextCall('core') - smokeEffect = StartParticleFxLoopedOnEntityBone(Config.SmokeEffect.name, playerPed, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, GetPedBoneIndex(playerPed, 47419), Config.SmokeEffect.scale, 0.0, 0.0, 0.0) - - -- Auto stop - Wait(Config.UseDuration * 1000) - DeleteObject(bong) - StopParticleFxLooped(smokeEffect, 0) - ClearPedTasks(playerPed) - isSmoking = false - end) -end) diff --git a/resources/[inventory]/nordi_hookah/config.lua b/resources/[inventory]/nordi_hookah/config.lua new file mode 100644 index 000000000..0f5aa0013 --- /dev/null +++ b/resources/[inventory]/nordi_hookah/config.lua @@ -0,0 +1,62 @@ +Config = {} + +-- Welche Props sollen als Shisha funktionieren? +Config.ShishaProps = { + `prop_bong_01`, +} + +-- Progressbar Dauer in ms +Config.PrepareTime = 5000 +Config.SmokeTime = 15000 + +-- Verfügbare Shisha-Optionen +Config.ShishaOptions = { + { + label = "Apfel Shisha", + description = "Fruchtige Apfel-Shisha", + icon = "fa-solid fa-smoking", + requires = { + {item = "shisha_tobacco", amount = 1}, + } + }, + { + label = "Minze Shisha", + description = "Erfrischende Minz-Shisha", + icon = "fa-solid fa-smoking", + requires = { + {item = "shisha_tobacco", amount = 1}, + } + }, + { + label = "Wassermelone Shisha", + description = "Süße Wassermelonen-Shisha", + icon = "fa-solid fa-smoking", + requires = { + {item = "shisha_tobacco", amount = 1}, + } + }, + { + label = "Traube Shisha", + description = "Aromatische Trauben-Shisha", + icon = "fa-solid fa-smoking", + requires = { + {item = "shisha_tobacco", amount = 1}, + } + }, + { + label = "Blaubeere Shisha", + description = "Süße Blaubeeren-Shisha", + icon = "fa-solid fa-smoking", + requires = { + {item = "shisha_tobacco", amount = 1}, + } + }, + { + label = "Doppel-Apfel Shisha", + description = "Intensive Doppel-Apfel-Shisha", + icon = "fa-solid fa-smoking", + requires = { + {item = "shisha_tobacco", amount = 2}, + } + }, +} diff --git a/resources/[inventory]/nordi_hookah/fxmanifest.lua b/resources/[inventory]/nordi_hookah/fxmanifest.lua index 139597f9c..54313524f 100644 --- a/resources/[inventory]/nordi_hookah/fxmanifest.lua +++ b/resources/[inventory]/nordi_hookah/fxmanifest.lua @@ -1,2 +1,28 @@ +fx_version 'cerulean' +game 'gta5' +description 'Shisha mit qb_target' +author 'Nordi (converted)' +version '1.0.0' + +shared_scripts { + '@ox_lib/init.lua', + 'config.lua' +} + +client_scripts { + 'client.lua' +} + +server_scripts { + 'server.lua' +} + +lua54 'yes' + +dependencies { + 'qb-target', + 'qb-core', + 'ox_lib' +} diff --git a/resources/[inventory]/nordi_hookah/server.lua b/resources/[inventory]/nordi_hookah/server.lua new file mode 100644 index 000000000..c4c7c4b25 --- /dev/null +++ b/resources/[inventory]/nordi_hookah/server.lua @@ -0,0 +1,38 @@ +local QBCore = exports['qb-core']:GetCoreObject() + +-- Debug Print Funktion +local function Debug(msg) + print("^2[Shisha Debug] ^7" .. msg) +end + +RegisterNetEvent('shisha-script:consumeTobacco') +AddEventHandler('shisha-script:consumeTobacco', function(requirements) + Debug("Consume tobacco event triggered") + local src = source + local Player = QBCore.Functions.GetPlayer(src) + + if Player then + -- Überprüfe nochmal die Zutaten + local hasAllItems = true + for _, requirement in ipairs(requirements) do + if not Player.Functions.HasItem(requirement.item, requirement.amount) then + hasAllItems = false + break + end + end + + if hasAllItems then + Debug("Player has all required items") + -- Entferne die benötigten Items + for _, requirement in ipairs(requirements) do + Player.Functions.RemoveItem(requirement.item, requirement.amount) + TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[requirement.item], "remove") + end + + TriggerClientEvent('QBCore:Notify', src, "Du hast die Shisha vorbereitet!", "success") + else + Debug("Player missing required items") + TriggerClientEvent('QBCore:Notify', src, "Du hast nicht alle benötigten Zutaten!", "error") + end + end +end) diff --git a/resources/[inventory]/nordi_hookah/server/main.lua b/resources/[inventory]/nordi_hookah/server/main.lua deleted file mode 100644 index b6da6edf8..000000000 --- a/resources/[inventory]/nordi_hookah/server/main.lua +++ /dev/null @@ -1,13 +0,0 @@ -QBCore = exports['qb-core']:GetCoreObject() - -QBCore.Functions.CreateCallback('qb-hookah:removeTobacco', function(source, cb) - local Player = QBCore.Functions.GetPlayer(source) - if not Player then return cb(false) end - - if Player.Functions.RemoveItem('shisha_tobacco', 1) then - TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items['shisha_tobacco'], "remove") - cb(true) - else - cb(false) - end -end) diff --git a/resources/[props]/hookah/fxmanifest.lua b/resources/[props]/hookah/fxmanifest.lua new file mode 100644 index 000000000..c59c423c1 --- /dev/null +++ b/resources/[props]/hookah/fxmanifest.lua @@ -0,0 +1,10 @@ +fx_version 'cerulean' +game 'gta5' + +files { + 'stream/props.ytyp' +} + +data_file 'DLC_ITYP_REQUEST' 'stream/props.ytyp' + +this_is_a_map 'yes' diff --git a/resources/[inventory]/nordi_hookah/stream/prop_bong_01.ydr b/resources/[props]/hookah/stream/prop_bong_01.ydr similarity index 100% rename from resources/[inventory]/nordi_hookah/stream/prop_bong_01.ydr rename to resources/[props]/hookah/stream/prop_bong_01.ydr diff --git a/resources/[inventory]/nordi_hookah/stream/props.ytyp b/resources/[props]/hookah/stream/props.ytyp similarity index 100% rename from resources/[inventory]/nordi_hookah/stream/props.ytyp rename to resources/[props]/hookah/stream/props.ytyp diff --git a/resources/[inventory]/nordi_hookah/stream/v_corp_lngestoolfd.ydr b/resources/[props]/hookah/stream/v_corp_lngestoolfd.ydr similarity index 100% rename from resources/[inventory]/nordi_hookah/stream/v_corp_lngestoolfd.ydr rename to resources/[props]/hookah/stream/v_corp_lngestoolfd.ydr