Started to make a script but need some help

this is the client side

local items = Config.Items

local itemHandles = {}
local activeZones = {}

-- Function to load a model
local function LoadModel(model)
    local modelHash = GetHashKey(model)
    if not IsModelInCdimage(modelHash) or not IsModelValid(modelHash) then
        print(('DEBUG: Model %s is not valid or not in the game CD image.'):format(model))
        return false
    end

    RequestModel(modelHash)
    while not HasModelLoaded(modelHash) do
        Citizen.Wait(10)
    end

    print(('DEBUG: Model %s loaded successfully.'):format(model))
    return true
end

-- Function to spawn item
RegisterNetEvent('qb-cooking:client:spawnItem')
AddEventHandler('qb-cooking:client:spawnItem', function(stage, coords, pointIndex)
    print(('DEBUG: Spawning item at point %d with stage %s'):format(pointIndex, stage))
    local item = items[stage]
    if not item then
        print(('DEBUG: Item for stage %s not defined at point %d'):format(stage, pointIndex))
        return
    end

    if not LoadModel(item) then
        print(('DEBUG: Failed to load model for item %s at point %d'):format(item, pointIndex))
        return
    end

    local itemHandle = CreateObject(GetHashKey(item), coords.x, coords.y, coords.z, true, true, true)
    if not DoesEntityExist(itemHandle) then
        print(('DEBUG: Failed to create item %s at coordinates (%.2f, %.2f, %.2f)'):format(item, coords.x, coords.y, coords.z))
        return
    end

    PlaceObjectOnGroundProperly(itemHandle)
    SetEntityAsMissionEntity(itemHandle, true, true)
    itemHandles[pointIndex] = itemHandle

    if activeZones[pointIndex] then
        exports['qb-target']:RemoveZone(activeZones[pointIndex])
    end

    activeZones[pointIndex] = exports['qb-target']:AddEntityZone("CookingItem" .. pointIndex, itemHandle, {
        name = "CookingItem" .. pointIndex,
        debugPoly = false,
        useZ = true,
    }, {
        options = {
            {
                type = "client",
                event = "qb-cooking:client:collectItem",
                icon = "fas fa-hand-holding",
                label = "Collect Item",
                eventArgs = { pointIndex = pointIndex }
            },
        },
        distance = 2.5,
    })

    print(('DEBUG: Spawned item %s at point %d'):format(item, pointIndex))
end)

-- Function to delete item
RegisterNetEvent('qb-cooking:client:deleteItem')
AddEventHandler('qb-cooking:client:deleteItem', function(pointIndex)
    print(('DEBUG: Deleting item at point %d'):format(pointIndex))
    local itemHandle = itemHandles[pointIndex]
    if itemHandle and DoesEntityExist(itemHandle) then
        DeleteObject(itemHandle)
        itemHandles[pointIndex] = nil
    else
        print(('DEBUG: Item handle at point %d does not exist'):format(pointIndex))
    end

    if activeZones[pointIndex] then
        exports['qb-target']:RemoveZone(activeZones[pointIndex])
        activeZones[pointIndex] = nil
    end

    print(('DEBUG: Deleted item at point %d'):format(pointIndex))
end)

-- Function to clear all items
RegisterNetEvent('qb-cooking:client:clearAllItems')
AddEventHandler('qb-cooking:client:clearAllItems', function()
    print('DEBUG: Clearing all items')
    for pointIndex, itemHandle in pairs(itemHandles) do
        if itemHandle and DoesEntityExist(itemHandle) then
            DeleteObject(itemHandle)
            itemHandles[pointIndex] = nil
        end

        if activeZones[pointIndex] then
            exports['qb-target']:RemoveZone(activeZones[pointIndex])
            activeZones[pointIndex] = nil
        end

        print(('DEBUG: Cleared item at point %d'):format(pointIndex))
    end
end)

-- Example qb-target setup for the grill
exports['qb-target']:AddBoxZone("Grill", vector3(Config.GrillLocation.x, Config.GrillLocation.y, Config.GrillLocation.z), 1, 1, {
    name = "Grill",
    heading = 0,
    debugPoly = false,
    minZ = Config.GrillLocation.z - 1,
    maxZ = Config.GrillLocation.z + 1,
}, {
    options = {
        {
            type = "client",
            event = "qb-cooking:client:startCooking",
            icon = "fas fa-utensils",
            label = "Start Cooking",
            item = Config.Items.raw,
        },
    },
    distance = 2.5,
})

RegisterNetEvent('qb-cooking:client:startCooking')
AddEventHandler('qb-cooking:client:startCooking', function(itemId)
    print(('DEBUG: Start cooking with item ID %s'):format(itemId))
    TriggerServerEvent('qb-cooking:server:startCooking', itemId)
end)

RegisterNetEvent('qb-cooking:client:collectItem')
AddEventHandler('qb-cooking:client:collectItem', function(data)
    print(('DEBUG: Collect item at point %d'):format(data.pointIndex))
    TriggerServerEvent('qb-cooking:server:collectItem', data.pointIndex)
end)

This is the server side

local items = Config.Items

local itemHandles = {}
local activeZones = {}

-- Function to load a model
local function LoadModel(model)
    local modelHash = GetHashKey(model)
    if not IsModelInCdimage(modelHash) or not IsModelValid(modelHash) then
        print(('DEBUG: Model %s is not valid or not in the game CD image.'):format(model))
        return false
    end

    RequestModel(modelHash)
    while not HasModelLoaded(modelHash) do
        Citizen.Wait(10)
    end

    print(('DEBUG: Model %s loaded successfully.'):format(model))
    return true
end

-- Function to spawn item
RegisterNetEvent('qb-cooking:client:spawnItem')
AddEventHandler('qb-cooking:client:spawnItem', function(stage, coords, pointIndex)
    print(('DEBUG: Spawning item at point %d with stage %s'):format(pointIndex, stage))
    local item = items[stage]
    if not item then
        print(('DEBUG: Item for stage %s not defined at point %d'):format(stage, pointIndex))
        return
    end

    if not LoadModel(item) then
        print(('DEBUG: Failed to load model for item %s at point %d'):format(item, pointIndex))
        return
    end

    local itemHandle = CreateObject(GetHashKey(item), coords.x, coords.y, coords.z, true, true, true)
    if not DoesEntityExist(itemHandle) then
        print(('DEBUG: Failed to create item %s at coordinates (%.2f, %.2f, %.2f)'):format(item, coords.x, coords.y, coords.z))
        return
    end

    PlaceObjectOnGroundProperly(itemHandle)
    SetEntityAsMissionEntity(itemHandle, true, true)
    itemHandles[pointIndex] = itemHandle

    if activeZones[pointIndex] then
        exports['qb-target']:RemoveZone(activeZones[pointIndex])
    end

    activeZones[pointIndex] = exports['qb-target']:AddEntityZone("CookingItem" .. pointIndex, itemHandle, {
        name = "CookingItem" .. pointIndex,
        debugPoly = false,
        useZ = true,
    }, {
        options = {
            {
                type = "client",
                event = "qb-cooking:client:collectItem",
                icon = "fas fa-hand-holding",
                label = "Collect Item",
                eventArgs = { pointIndex = pointIndex }
            },
        },
        distance = 2.5,
    })

    print(('DEBUG: Spawned item %s at point %d'):format(item, pointIndex))
end)

-- Function to delete item
RegisterNetEvent('qb-cooking:client:deleteItem')
AddEventHandler('qb-cooking:client:deleteItem', function(pointIndex)
    print(('DEBUG: Deleting item at point %d'):format(pointIndex))
    local itemHandle = itemHandles[pointIndex]
    if itemHandle and DoesEntityExist(itemHandle) then
        DeleteObject(itemHandle)
        itemHandles[pointIndex] = nil
    else
        print(('DEBUG: Item handle at point %d does not exist'):format(pointIndex))
    end

    if activeZones[pointIndex] then
        exports['qb-target']:RemoveZone(activeZones[pointIndex])
        activeZones[pointIndex] = nil
    end

    print(('DEBUG: Deleted item at point %d'):format(pointIndex))
end)

-- Function to clear all items
RegisterNetEvent('qb-cooking:client:clearAllItems')
AddEventHandler('qb-cooking:client:clearAllItems', function()
    print('DEBUG: Clearing all items')
    for pointIndex, itemHandle in pairs(itemHandles) do
        if itemHandle and DoesEntityExist(itemHandle) then
            DeleteObject(itemHandle)
            itemHandles[pointIndex] = nil
        end

        if activeZones[pointIndex] then
            exports['qb-target']:RemoveZone(activeZones[pointIndex])
            activeZones[pointIndex] = nil
        end

        print(('DEBUG: Cleared item at point %d'):format(pointIndex))
    end
end)

-- Example qb-target setup for the grill
exports['qb-target']:AddBoxZone("Grill", vector3(Config.GrillLocation.x, Config.GrillLocation.y, Config.GrillLocation.z), 1, 1, {
    name = "Grill",
    heading = 0,
    debugPoly = false,
    minZ = Config.GrillLocation.z - 1,
    maxZ = Config.GrillLocation.z + 1,
}, {
    options = {
        {
            type = "client",
            event = "qb-cooking:client:startCooking",
            icon = "fas fa-utensils",
            label = "Start Cooking",
            item = Config.Items.raw,
        },
    },
    distance = 2.5,
})

RegisterNetEvent('qb-cooking:client:startCooking')
AddEventHandler('qb-cooking:client:startCooking', function(itemId)
    print(('DEBUG: Start cooking with item ID %s'):format(itemId))
    TriggerServerEvent('qb-cooking:server:startCooking', itemId)
end)

RegisterNetEvent('qb-cooking:client:collectItem')
AddEventHandler('qb-cooking:client:collectItem', function(data)
    print(('DEBUG: Collect item at point %d'):format(data.pointIndex))
    TriggerServerEvent('qb-cooking:server:collectItem', data.pointIndex)
end)
--------------------------------------------------------
This is the config

Config = {}

-- Define items for each stage
Config.Items = {
    raw = 'rawsausage',      -- Item ID for raw
    cooked = 'cookedsausage', -- Item ID for cooked
    burnt = 'burnt_meat'      -- Item ID for burnt
}

-- Define cooking points
Config.CookingPoints = {
    { x = -527.34, y = -527.34, z = 33.66 },
    { x = 527.34, y = -690.71, z = 33.66 },
    { x = 527.34, y = 690.89, z = 33.66 },
    { x = -527.34, y = -691.17, z = 33.66 }
}

-- Define cooking times (in seconds)
Config.CookingTimes = {
    rawToCooked = 25,  -- Time from raw to cooked
    cookedToBurnt = 45  -- Time from cooked to burnt
}

-- Define the grill location
Config.GrillLocation = { x = -527.39, y = -690.66, z = 33.67 }

This got approved?

Manual approval of Releases has been disabled for the foreseeable future.

1 Like

What does that mean?

trying to make a script for foodcourt this is the start of the 3 stage cooking for the hotdogs