forked from Simnation/Main
ed
This commit is contained in:
parent
bf1abcc776
commit
96de802827
4 changed files with 0 additions and 455 deletions
|
@ -1,310 +0,0 @@
|
|||
local QBCore = exports['qb-core']:GetCoreObject()
|
||||
|
||||
-- Debug Print Function
|
||||
local function Debug(msg)
|
||||
print("^2[Shisha Debug] ^7" .. msg)
|
||||
end
|
||||
|
||||
-- Cache system for item checks
|
||||
local itemCheckCache = {}
|
||||
local lastCheckTime = {}
|
||||
local checkCooldown = 1000 -- 1 second cooldown between checks for the same item
|
||||
|
||||
-- Function to check if player has an item
|
||||
local function HasItem(itemName, amount, callback)
|
||||
-- Check cache first (to avoid spamming the server)
|
||||
local cacheKey = itemName .. "_" .. amount
|
||||
local currentTime = GetGameTimer()
|
||||
if itemCheckCache[cacheKey] ~= nil and lastCheckTime[cacheKey] and
|
||||
(currentTime - lastCheckTime[cacheKey]) < checkCooldown then
|
||||
callback(itemCheckCache[cacheKey])
|
||||
return
|
||||
end
|
||||
|
||||
-- Create a unique event name for this check
|
||||
local uniqueEventName = 'shisha-script:itemCheckResult:' .. math.random(100000, 999999)
|
||||
|
||||
-- Register the event handler
|
||||
local eventHandler = RegisterNetEvent(uniqueEventName)
|
||||
AddEventHandler(uniqueEventName, function(hasItem)
|
||||
itemCheckCache[cacheKey] = hasItem
|
||||
lastCheckTime[cacheKey] = GetGameTimer()
|
||||
callback(hasItem)
|
||||
end)
|
||||
|
||||
-- Request the check from server with our unique event name
|
||||
TriggerServerEvent('shisha-script:checkItem', itemName, amount, uniqueEventName)
|
||||
|
||||
-- Set a timeout to prevent hanging if something goes wrong
|
||||
SetTimeout(1000, function()
|
||||
if not lastCheckTime[cacheKey] or (currentTime - lastCheckTime[cacheKey]) >= checkCooldown then
|
||||
callback(false)
|
||||
end
|
||||
end)
|
||||
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, callback)
|
||||
local hasItems = true
|
||||
local missingItems = {}
|
||||
local checkedItems = 0
|
||||
local totalItems = #requirements
|
||||
|
||||
if totalItems == 0 then
|
||||
callback(true, {})
|
||||
return
|
||||
end
|
||||
|
||||
for _, requirement in ipairs(requirements) do
|
||||
HasItem(requirement.item, requirement.amount, function(hasItem)
|
||||
checkedItems = checkedItems + 1
|
||||
|
||||
if not hasItem then
|
||||
hasItems = false
|
||||
table.insert(missingItems, {
|
||||
item = requirement.item,
|
||||
required = requirement.amount
|
||||
})
|
||||
end
|
||||
|
||||
if checkedItems == totalItems then
|
||||
callback(hasItems, missingItems)
|
||||
end
|
||||
end)
|
||||
end
|
||||
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 = {}
|
||||
local shishaChecked = 0
|
||||
local totalShishas = #Config.ShishaOptions
|
||||
|
||||
for _, shisha in ipairs(Config.ShishaOptions) do
|
||||
CheckIngredients(shisha.requires, function(hasIngredients, missingItems)
|
||||
shishaChecked = shishaChecked + 1
|
||||
|
||||
local description = shisha.description .. "\n\nBenötigt:"
|
||||
|
||||
for _, req in ipairs(shisha.requires) do
|
||||
local itemLabel = QBCore.Shared.Items[req.item].label
|
||||
local hasItem = not table.find(missingItems, function(item) return item.item == req.item end)
|
||||
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()
|
||||
CheckIngredients(shisha.requires, function(canMake, missingItems)
|
||||
if canMake then
|
||||
PrepareShisha(shisha)
|
||||
else
|
||||
ShowMissingIngredientsWarning(missingItems)
|
||||
end
|
||||
end)
|
||||
end
|
||||
})
|
||||
|
||||
if shishaChecked == totalShishas then
|
||||
ShowShishaMenu(options)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
-- Helper function to find in table
|
||||
function table.find(t, cb)
|
||||
for _, v in ipairs(t) do
|
||||
if cb(v) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function ShowShishaMenu(options)
|
||||
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
|
||||
StartShishaSmoking(selectedShisha)
|
||||
end, function() -- Cancelled
|
||||
Debug("Shisha-Vorbereitung abgebrochen")
|
||||
QBCore.Functions.Notify("Vorbereitung abgebrochen", "error")
|
||||
end)
|
||||
end
|
||||
|
||||
-- Smoke shisha function with animation and smoke effect
|
||||
function StartShishaSmoking(selectedShisha)
|
||||
local ped = PlayerPedId()
|
||||
local smokeTime = Config.SmokeTime or 30000
|
||||
local animDict = "amb@world_human_aa_smoke@male@idle_a"
|
||||
local animName = "idle_a"
|
||||
|
||||
-- Request animation dictionary
|
||||
RequestAnimDict(animDict)
|
||||
while not HasAnimDictLoaded(animDict) do
|
||||
Wait(10)
|
||||
end
|
||||
|
||||
-- Create a separate thread to keep the animation playing
|
||||
local smokingActive = true
|
||||
CreateThread(function()
|
||||
-- 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)
|
||||
|
||||
-- Create smoke effect
|
||||
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)
|
||||
|
||||
-- Progress bar for smoking
|
||||
QBCore.Functions.Progressbar("smoke_shisha", selectedShisha.label.." rauchen...", smokeTime, false, true, {
|
||||
disableMovement = false,
|
||||
disableCarMovement = false,
|
||||
disableMouse = false,
|
||||
disableCombat = true,
|
||||
}, {}, {}, {}, function() -- Success
|
||||
-- Stop the animation and smoke effect
|
||||
smokingActive = false
|
||||
ClearPedTasks(ped)
|
||||
|
||||
-- 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")
|
||||
TriggerEvent("evidence:client:SetStatus", "weedsmell", 300)
|
||||
TriggerServerEvent('hud:server:RelieveStress', math.random(15, 25))
|
||||
|
||||
-- Warte noch einen Moment, bevor die Entspannungsnachricht angezeigt wird
|
||||
Wait(1000)
|
||||
QBCore.Functions.Notify("Du fühlst dich entspannt...", "success")
|
||||
Debug("Entspannungseffekte angewendet")
|
||||
end, function() -- Cancelled
|
||||
-- Clean up if cancelled
|
||||
smokingActive = false
|
||||
ClearPedTasks(ped)
|
||||
Debug("Rauchen abgebrochen")
|
||||
end)
|
||||
end
|
||||
|
||||
-- Debug Event
|
||||
RegisterNetEvent('shisha-script:debug')
|
||||
AddEventHandler('shisha-script:debug', function(msg)
|
||||
Debug(msg)
|
||||
end)
|
|
@ -1,66 +0,0 @@
|
|||
Config = {}
|
||||
|
||||
-- Debug-Modus
|
||||
Config.DebugPoly = false -- Auf true setzen, um Box-Zonen zu sehen
|
||||
|
||||
-- Welche Props sollen als Shisha funktionieren?
|
||||
Config.ShishaProps = {
|
||||
"sf_prop_sf_g_bong_01a", -- Funktionierendes Modell
|
||||
"prop_bong_01",
|
||||
}
|
||||
|
||||
-- Progressbar Dauer in ms
|
||||
Config.PrepareTime = 5000
|
||||
Config.SmokeTime = 30000
|
||||
|
||||
-- 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},
|
||||
}
|
||||
},
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
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',
|
||||
'tgiann-inventory'
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
local QBCore = exports['qb-core']:GetCoreObject()
|
||||
|
||||
-- Debug Print Funktion
|
||||
local function Debug(msg)
|
||||
print("^2[Shisha Debug] ^7" .. msg)
|
||||
end
|
||||
|
||||
-- Function to check if player has an item
|
||||
local function HasItem(source, itemName, amount)
|
||||
local itemCount = exports["tgiann-inventory"]:GetItemCount(source, itemName)
|
||||
return itemCount >= amount
|
||||
end
|
||||
|
||||
-- Event for client to check if player has an item
|
||||
RegisterNetEvent('shisha-script:checkItem', function(itemName, amount, callbackEvent)
|
||||
local src = source
|
||||
local hasItem = HasItem(src, itemName, amount)
|
||||
TriggerClientEvent(callbackEvent, src, hasItem)
|
||||
end)
|
||||
|
||||
RegisterNetEvent('shisha-script:consumeTobacco')
|
||||
AddEventHandler('shisha-script:consumeTobacco', function(requirements)
|
||||
Debug("Tabak-Verbrauch-Event ausgelöst")
|
||||
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 HasItem(src, requirement.item, requirement.amount) then
|
||||
hasAllItems = false
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if hasAllItems then
|
||||
Debug("Spieler hat alle benötigten Items")
|
||||
-- Entferne die benötigten Items
|
||||
for _, requirement in ipairs(requirements) do
|
||||
exports["tgiann-inventory"]:RemoveItem(src, 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("Spieler hat nicht alle benötigten Items")
|
||||
TriggerClientEvent('QBCore:Notify', src, "Du hast nicht alle benötigten Zutaten!", "error")
|
||||
end
|
||||
end
|
||||
end)
|
Loading…
Add table
Add a link
Reference in a new issue