Jump to content

Recommended Posts

I don't think the code DST uses has been ported back to DS yet.

You can listen for the "onbuilt" event from your prefab (e.g. Meat Effigy) and take the health there. It's not particularly nice, and does not show as ingredient, but it works.

This code should crash for the reason below. Double-check the position of the code, it should be in the same place you add components like "inspectable" and "inventoryitem".

You are passing a function to the event system, but that function does not receive the "builder" variable. Add "inst" and "builder" into the parantheses "()" so it says "(inst, builder)". These are the parameter given by the event system (I think).

3 hours ago, Eonnn said:

I have done that (and moved the code to where it should be), but nothing happens still when the item is crafted. Is there something wrong with using "builder.components.sanity:DoDelta(-25)"?

Paste your item code. Something about the way you set the function up must be wrong.

local assets=

    Asset("ANIM", "anim/alchemytoken.zip"),

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

local prefabs = 
{
}

local function onbuilt(inst, builder)
        inst.builder.components.sanity:DoDelta(-25)
        end

local function fn(colour)

    local inst = CreateEntity()
    local trans = inst.entity:AddTransform()
    local anim = inst.entity:AddAnimState()
    MakeInventoryPhysics(inst)
    
    anim:SetBank("alchemytoken")
    anim:SetBuild("alchemytoken")
    anim:PlayAnimation("idle")
    inst:AddComponent("inspectable")
    inst:AddComponent("inventoryitem")
    inst:AddComponent("stackable")
    inst.components.inventoryitem.imagename = "alchemytoken"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/alchemytoken.xml"
    STRINGS.NAMES.ALCHEMYTOKEN = "Philosopher's Stone"
    STRINGS.CHARACTERS.GENERIC.DESCRIBE.ALCHEMYTOKEN = "The essence of alchemy."
    inst:ListenForEvent("onbuilt", function(inst,builder)
        inst.builder.components.sanity:DoDelta(-25)
    end)
    return inst
end

return  Prefab("common/inventory/alchemytoken", fn, assets, prefabs)

@Eonnn the following should work:

Spoiler

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

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

local prefabs =
{
}

local function fn()
    local inst = CreateEntity()
    local trans = inst.entity:AddTransform()
    local anim = inst.entity:AddAnimState()
    MakeInventoryPhysics(inst)
    
    anim:SetBank("alchemytoken")
    anim:SetBuild("alchemytoken")
    anim:PlayAnimation("idle")
    
    inst:AddComponent("inspectable")
    
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.imagename = "alchemytoken"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/alchemytoken.xml"
    
    inst:AddComponent("stackable")
    
    --the following adds custom code for when crafted
    local oldonbuilt = inst.OnBuilt
    inst.OnBuilt = function(inst,builder)
        --your code here
        if builder.components.sanity then
            builder.components.sanity:DoDelta(-25)
        end
        --
        oldonbuilt(inst,builder)
    end
    
    
    return inst
end


STRINGS.NAMES.ALCHEMYTOKEN = "Philosopher's Stone"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.ALCHEMYTOKEN = "The essence of alchemy."

return Prefab("common/inventory/alchemytoken", fn, assets, prefabs)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...