Jump to content

Recommended Posts

Im planning on making 2 different craftable  items for my mod charcater 1 that restores health and 1 that restores sanity kind off like a healing salve, but how do I do this? I know little about modding so yeah, all help is appreciated. :)

Edited by AquaRC
forogt to add a detail

    inst:AddComponent("edible")
    inst.components.edible.healthvalue = ##
    inst.components.edible.hungervalue = ##

replace the ## with the number you want. this goes in the local function fn() section.

    if you want a sanity effect, add this: 

inst.components.edible.sanityvalue = ##

 

Edited by mf99k

Thanks for the line of code, but what I meant is how do I make it then add it, because all the guides I have seen have only been equipment

like hats and tools etc. But I haven't seen any healing salve like items been added. So if someone can teach me or give me a link to a guide that would be helpful. I've already done the art for this item i just need to know how to turn it into 1 so all help and info is much appreaciated and very healful! UXFkC5U.pngS0FtDe0.png

I didn't test it but here you go(I'm hoping you know what you have to do in modmain, such as setting up strings and adding the prefab name to "PREFABFILES" list;

 

 

 


local assets =
{
    Asset("ANIM", "anim/ITEM.zip"), --replace ITEM with ur .zip name.
}

local function fn()
    local inst = CreateEntity()

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

    MakeInventoryPhysics(inst)

    inst.AnimState:SetBank("item")--replace item with ur animation bank
    inst.AnimState:SetBuild("item")-- replace item with ur animation build
    inst.AnimState:PlayAnimation("idle")

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

	--make the item stackable(optional), you can remove this if you want it to be 1 item per inventory slot
    inst:AddComponent("stackable")
    inst.components.stackable.maxsize = TUNING.STACK_SIZE_SMALLITEM
	--POSSIBLE STACK SIZES:
	--STACK_SIZE_LARGEITEM (10)
	--STACK_SIZE_MEDITEM (20)
	--STACK_SIZE_SMALLITEM (40)

    inst:AddComponent("inspectable")

    inst:AddComponent("inventoryitem")

	--make the item edible
    inst:AddComponent("edible")
    inst.components.edible.foodtype = FOODTYPE.VEGGIE
    inst.components.edible.healthvalue = 0--replace with the number you want it to increase/decrease your health with.
    inst.components.edible.hungervalue = 0--replace with the number you want it to increase/decrease your hunger with.
    inst.components.edible.sanityvalue = 0--replace with the number you want it to increase/decrease your sanity with.
	--[[list of foodtypes: 
		MEAT,WOOD,VEGGIE,ELEMENTAL,GEARS,HORRIBLE,INSECT,SEEDS,BERRY,RAW,BURNT,ROUGHAGE
			FOODTYPE.BERRY is edible by SMALLBIRD, 
			FOODTYPE.BURNT is edible by LAVAE, 
			FOODTYPE.RAW can be eaten off the floor by certain monsters
	]]--
	--make the item rot(optional), you can remove this if you dont want ur item to rot
	inst:AddComponent("perishable")
	inst.components.perishable:StartPerishing()
    inst.components.perishable.onperishreplacement = "spoiled_food" --"item" to change into when it rots
    inst.components.perishable:SetPerishTime(TUNING.PERISH_MED) -- time it takes to perish,
    --[[POSSIBLE PERISH TIMES:
		PERISH_ONE_DAY = 1 * 1 FULL DAY
		PERISH_TWO_DAY = 2 * 1 FULL DAY
		PERISH_SUPERFAST = 3 * 1 FULL DAY
		PERISH_FAST = 6 * 1 FULL DAY
		PERISH_FASTISH = 8 * 1 FULL DAY
		PERISH_MED = 10 * 1 FULL DAY
		PERISH_SLOW = 15 * 1 FULL DAY
		PERISH_PRESERVED = 20 * 1 FULL DAY
		PERISH_SUPERSLOW = 40 * 1 FULL DAY
	]]--

	--make the item cookable(optional), you can remove this if you dont want ur item to be cookable
	inst:AddComponent("cookable")
    inst.components.cookable.product = "cooked_smallmeat" -- "item" to change into when it cooks
	
    MakeHauntableLaunchAndPerish(inst)

    return inst
end

return Prefab("item", fn, assets)-- replace "item" with the name you want to give to your item

 

 

Edited by Aquaterion
7 hours ago, AquaRC said:

I know how to play with some strings in mod main but I don't know how to add the prefab name to "PREFABFILES" list; :(

I think you know, maybe I confused you; I meant this:

PrefabFiles = {
    "item1",
    "item2",
}

 

10 minutes ago, AquaRC said:

Well I tried adding in the item and I followed a tutorial , but then it led to a total bust because when I run the game it freezes but dosen't crash.

check the clientlog, Documents/Klei/DontStarveTogether/clientlog.txt

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...