Jump to content

I can't make an item only equip by one character


Recommended Posts

the code:

inst.components.inventoryitem.onputininventoryfn = function(inst, player) 
    local owner = inst.components.inventoryitem:GetGrandOwner()
    if owner.components.inventory and owner.prefab ~= "terrifried" then 
        inst:DoTaskInTime(0.1, function()
        
        player.components.inventory:DropItem(inst)
        player.components.talker:Say("Eww, it's too sticky!")
    end)
    end
    end

has always worked for me getting other character to drop the item when they pick it up, but for some reason when I use basically the same code on an item that is a pan flute replica rather then a weapon, it can just be picked up. Why does this happen, and how do I fix it? here is the full code:

local assets =
{
    Asset("ANIM", "anim/sigjam.zip"),

    Asset("ATLAS", "images/inventoryimages/sigjam.xml"),
    Asset("IMAGE", "images/inventoryimages/sigjam.tex"),
}

local function HearPanFlute(inst, musician, instrument)
    musician.sg:GoToState("electrocute")
    
    musician.components.health:DoDelta(-2)
    
    if inst ~= musician and
        (TheNet:GetPVPEnabled() or not inst:HasTag("player")) and
        not (inst.components.freezable ~= nil and inst.components.freezable:IsFrozen()) and
        not (inst.components.pinnable ~= nil and inst.components.pinnable:IsStuck()) and
        not (inst.components.fossilizable ~= nil and inst.components.fossilizable:IsFossilized()) then
        local mount = inst.components.rider ~= nil and inst.components.rider:GetMount() or nil
        if mount ~= nil then
            mount:PushEvent("ridersleep", { sleepiness = 10, sleeptime = TUNING.PANFLUTE_SLEEPTIME })
        end
        if inst.components.farmplanttendable ~= nil then
            inst.components.farmplanttendable:TendTo(musician)
        elseif inst.components.sleeper ~= nil then
            inst.components.sleeper:AddSleepiness(10, TUNING.PANFLUTE_SLEEPTIME)
        elseif inst.components.grogginess ~= nil then
            inst.components.grogginess:AddGrogginess(10, TUNING.PANFLUTE_SLEEPTIME)
        else
            inst:PushEvent("knockedout")
        end
    end
end

local function fn()
    local inst = CreateEntity()

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

    MakeInventoryPhysics(inst)

    inst:AddTag("sigjam")

    inst.AnimState:SetBank("pan_flute")
    inst.AnimState:SetBuild("sigjam")
    inst.AnimState:PlayAnimation("idle")
    
    
    
     if not TheWorld.ismastersim then
        return inst
    end
    inst.entity:SetPristine()
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.atlasname = "images/inventoryimages/sigjam.xml"
    
    inst.components.inventoryitem.cangoincontainer = true  
    inst.components.inventoryitem.onputininventoryfn = function(inst, player, musician) 
    local owner = inst.components.inventoryitem:GetGrandOwner()
    if owner.components.inventory and owner.prefab ~= "absynth" then 
        inst:DoTaskInTime(0.1, function()
        
        player.components.inventory:DropItem(inst)
        player.components.talker:Say("I guess only holograms can use this?")
    end)
    end
    end
    
    

    --tool (from tool component) added to pristine state for optimization
    inst:AddTag("tool")

    MakeInventoryFloatable(inst, "small", 0.05, 0.8)
    inst.AnimState:AddOverrideBuild("sigjam")

    inst.entity:SetPristine()

    inst:AddComponent("inspectable")
    inst:AddComponent("instrument")
    inst.components.instrument.range = TUNING.PANFLUTE_SLEEPRANGE
    inst.components.instrument:SetOnHeardFn(HearPanFlute)

    inst:AddComponent("tool")
    inst.components.tool:SetAction(ACTIONS.PLAY)

    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.imagename = "sigjam"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/sigjam.xml"
    

    MakeHauntableLaunch(inst)

    inst:ListenForEvent("floater_startfloating", function(inst) inst.AnimState:PlayAnimation("float") end)
    inst:ListenForEvent("floater_stopfloating", function(inst) inst.AnimState:PlayAnimation("idle") end)

    return inst
end

return Prefab("common/inventory/sigjam", fn, assets)

 I am unsure if I just missed something in another .lua, but any help is necessary because I am losing my mind.

sigjam.lua absynth.zip

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...