Skip to content

Found a other issue, dupplication items with target. #18

@MaDHouSe79

Description

@MaDHouSe79

when you use a craf bench and you damaged it by driveing against it, you can easy dupplicate the bench with target.

you don't use a canInteract check in target when you place or pickup the craft bench, and when you destroy the object in gameworld the target stil works on the remain parts on the ground even if you already take the bench to you inventory.

-- Here an example for the canInteract fix

-- Events
local hasPlaceBench = false
RegisterNetEvent('qb-crafting:client:useCraftingTable', function(benchType)
    local playerPed = PlayerPedId()
    local coordsP = GetOffsetFromEntityInWorldCoords(playerPed, 0.0, 1.0, 1.0)
    local playerHeading = GetEntityHeading(PlayerPedId())
    local itemHeading = playerHeading - 90
    local workbench = CreateObject(Config[benchType].object, coordsP, true, true, true)
    if itemHeading < 0 then itemHeading = 360 + itemHeading end
    SetEntityHeading(workbench, itemHeading)
    PlaceObjectOnGroundProperly(workbench)
    TriggerServerEvent('qb-crafting:server:removeCraftingTable', benchType)
    hasPlaceBench = true
    exports['qb-target']:AddTargetEntity(workbench, {
        options = {
            {
                icon = 'fas fa-tools',
                label = string.format(Lang:t('menus.header')),
                action = function()
                    OpenCraftingMenu(benchType)
                end,
                canInteract = function(entity, distance, data)
                    if not hasPlaceBench then return false end
		    return true
		end
            },
            {
                event = 'crafting:pickupWorkbench',
                icon = 'fas fa-hand-rock',
                label = string.format(Lang:t('menus.pickupworkBench')),
                action = function()
                    hasPlaceBench = false
                    PickupBench(benchType)
                end,
                canInteract = function(entity, distance, data)
                    if not hasPlaceBench then return false end
		    return true
		end
            }
        },
        distance = 2.5
    })
end)

And for the server side you want to check if nobody that uses the bench is in a vehicle

-- Items
for benchType, v in pairs(Config) do
    if type(v) == 'table' then
        QBCore.Functions.CreateUseableItem(benchType, function(source)
            if GetVehiclePedIsIn(GetPlayerPed(source), false) == 0 then
                TriggerClientEvent('qb-crafting:client:useCraftingTable', source, benchType)
            elseif GetVehiclePedIsIn(GetPlayerPed(source), false) ~= 0 then
                TriggerClientEvent('QBCore:Notify', source, "You can't use a bench when you are sitting in a vehicle...", 'error')
            end
        end)
    end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions