Jump to content

Food item errors


Recommended Posts

Heyo,

I made a custom prefab that can be eaten. (ie it's a food.) I tried to change the values of health, hunger and sanity given when it's eaten, but I only get the stats for Cooked Morsel. (i think). So can anyone help? Heres my item.lua

Spoiler


-- In a prefab file, you need to list all the assets it requires.
-- These can be either standard assets, or custom ones in your mod
-- folder.
local Assets =
{
	Asset("ANIM", "anim/aspic.zip"), -- a standard asset
    Asset("ATLAS", "images/inventoryimages/aspic.xml"),    -- a custom asset, found in the mod folder
}

-- Write a local function that creats, customizes, and returns an instance of the prefab.
local function fn(Sim)
	local inst = CreateEntity()
	inst.entity:AddTransform()
	inst.entity:AddAnimState()

    MakeInventoryPhysics(inst)
    
    inst.AnimState:SetBank("aspic")
    inst.AnimState:SetBuild("aspic")
    inst.AnimState:PlayAnimation("idle", true)
	
	inst:AddComponent("edible")
    inst.components.edible.foodtype = FOODTYPE.MEAT
	inst:AddTag("catfood") --well lol in real life it is cat food
    
	inst:AddComponent("perishable")
    inst.components.perishable:SetPerishTime(TUNING.PERISH_SUPERSLOW) --40 days!?!?!
    inst.components.perishable:StartPerishing()
    inst.components.perishable.onperishreplacement = "spoiled_food"
	
    inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.atlasname = "images/inventoryimages/aspic.xml"
	
	inst:AddComponent("stackable")
    inst.components.stackable.maxsize = TUNING.STACK_SIZE_SMALLITEM
	
	inst:AddComponent("bait")
	
	MakeHauntableLaunchAndPerish(inst)
	
	inst:AddComponent("tradable")
    inst.components.tradable.goldvalue = 1 --sells to pig king for 1 gold

	inst:AddComponent("inspectable")
    
    return inst
end

local function defaultfn()
    local inst = commonfn("idle", true, true)

    if not TheWorld.ismastersim then
        return inst
    end

    inst.components.edible.healthvalue = TUNING.HEALING_MEDSMALL --8
    inst.components.edible.hungervalue = TUNING.CALORIES_HUGE --50 or so?
    inst.components.perishable:SetPerishTime(TUNING.PERISH_SUPERSLOW) --40 days?!?!
    inst.components.edible.sanityvalue = -TUNING.SANITY_SMALL --10 sanity

    return inst
end

-- Add some strings for this item
STRINGS.NAMES.ASPIC = "Aspic"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.ASPIC = "A gelatinous compound made from meat stock and starch."


-- Finally, return a new prefab with the construction function and assets.
return Prefab( "common/inventory/aspic", fn, Assets)

 

 

Edited by NeddoFreddo
Link to comment
Share on other sites

Well lol nvm I just moved the things from the defaultfn() to the local function fn().

Spoiler


-- In a prefab file, you need to list all the assets it requires.
-- These can be either standard assets, or custom ones in your mod
-- folder.
local Assets =
{
	Asset("ANIM", "anim/aspic.zip"), -- a standard asset
    Asset("ATLAS", "images/inventoryimages/aspic.xml"),    -- a custom asset, found in the mod folder
}

-- Write a local function that creats, customizes, and returns an instance of the prefab.
local function fn(Sim)
	local inst = CreateEntity()
	inst.entity:AddTransform()
	inst.entity:AddAnimState()

    MakeInventoryPhysics(inst)
    
    inst.AnimState:SetBank("aspic")
    inst.AnimState:SetBuild("aspic")
    inst.AnimState:PlayAnimation("idle", true)
	
	inst:AddComponent("edible")
    inst.components.edible.foodtype = FOODTYPE.MEAT --wigfrid can eat this
	  inst.components.edible.healthvalue = TUNING.HEALING_MEDSMALL --8
    inst.components.edible.hungervalue = TUNING.CALORIES_HUGE --50 or so?
    inst.components.edible.sanityvalue = -TUNING.SANITY_SMALL --10 sanity
	inst:AddTag("catfood") --well lol in real life it is cat food
    
	inst:AddComponent("perishable")
    inst.components.perishable:SetPerishTime(TUNING.PERISH_SUPERSLOW) --40 days!?!?!
    inst.components.perishable:StartPerishing()
    inst.components.perishable.onperishreplacement = "spoiled_food"
	
    inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.atlasname = "images/inventoryimages/aspic.xml"
	
	inst:AddComponent("stackable")
    inst.components.stackable.maxsize = TUNING.STACK_SIZE_SMALLITEM
	
	if not TheWorld.ismastersim then
        return inst
    end
	
	inst:AddComponent("bait")
	
	MakeHauntableLaunchAndPerish(inst)
	
	inst:AddComponent("tradable")
    inst.components.tradable.goldvalue = 1 --sells to pig king for 1 gold

	inst:AddComponent("inspectable")
    
    return inst
end

local function defaultfn()
    local inst = commonfn("idle", true, true)
	--blah blah
    return inst
end

-- Add some strings for this item
STRINGS.NAMES.ASPIC = "Aspic"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.ASPIC = "A gelatinous compound made from meat stock and starch."


-- Finally, return a new prefab with the construction function and assets.
return Prefab( "common/inventory/aspic", fn, Assets)

 

 

Link to comment
Share on other sites

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
 Share

×
  • Create New...