local assets =
{
    Asset("ANIM", "anim/halloweencandy.zip"),
    Asset("ATLAS", "images/inventoryimages/permission.xml"),
    Asset("IMAGE", "images/inventoryimages/permission.tex"),
}

local function OnPickup(inst,pickuper)
    if inst.permissionid == nil then
        inst.permissionid = pickuper.userid
    end
end

local function Oneaten(inst,eater)
    eater:AddTag(tostring(inst.permissionid))
end

    local function fn()
        local inst = CreateEntity()

        inst.entity:AddTransform()
        inst.entity:AddAnimState()
        inst.entity:AddSoundEmitter()
        inst.entity:AddNetwork()

        MakeInventoryPhysics(inst)

        inst.AnimState:SetBank("halloweencandy")
        inst.AnimState:SetBuild("halloweencandy")
        inst.AnimState:PlayAnimation(tostring(11))

        inst.entity:SetPristine()

        if not TheWorld.ismastersim then
            return inst
        end

        inst.permissionid = nil
        inst:AddComponent("inspectable")
        inst:AddComponent("inventoryitem")
        inst.components.inventoryitem.atlasname = "images/inventoryimages/permission.xml"
        inst.components.inventoryitem.imagename = "permission"
        inst.components.inventoryitem:SetOnPickupFn(OnPickup)
                
        
        inst:AddComponent("stackable")
        inst.components.stackable.maxsize = TUNING.STACK_SIZE_SMALLITEM

        inst:AddComponent("edible")
        inst.components.edible.foodtype = FOODTYPE.MEAT
        inst.components.edible.hungervalue = 0
        inst.components.edible.healthvalue = 0
        inst.components.edible.sanityvalue = 0
        inst.components.edible:SetOnEatenFn(Oneaten)

        MakeHauntableLaunch(inst)

        inst:AddComponent("bait")

        return inst
    end
    return Prefab("permission", fn, assets)
