#include "../../script/helpers/entity.lua"

local pShapeTagJoints = GetStringParam("shapes_tag", "hook")
local pJointTag = GetStringParam("joint_tag", "hook")

local shapes, vehicle, disabled
function init()
    shapes = FindShapes(pShapeTagJoints)
    vehicle = FindVehicle()
end

function tick(dt)
    if disabled then return end
    local veh = GetPlayerVehicle()
    if veh == 0 or veh ~= vehicle then return end
    if not InputPressed("vehicle_action") then return end

    for i = 1, #shapes do
        local shape = shapes[i]
        local joints = GetShapeJoints(shape)
        for j = 1, #joints do
            local joint = joints[j]
            if IsHandleValid(joint) and HasTag(joint, pJointTag) then
                Delete(joint)
            end
        end
    end
    disabled = cEntity:EnqueueDeletion()
end
