Jump to content

How to make item stack-able?


Recommended Posts

I wonder how can I make item like 'Deer Antler', 'Guardian's Horn', ect. stack-able? I was trying to edit the lua code in prefab folder, but I don't know where should I save the edited version file in order to test it in game. I'm hoping to get some advises or please let me know if there's other way to do it. Thanks!

Edited by bink_li
Link to comment
Share on other sites

A prefab should have the component "stackable" in order to be able to stack.


    inst:AddComponent("stackable")

You shouldn't however edit the file itself, but rather use a prefab postinit. Editing base files should be avoided as much as possible and postinit prefered, because it ensure better compatibility with others mods.

In the Don't Starve API there is an example of prefab postinit :


-----------------------------------
-- Prefab mod example
--
--  AddPrefabPostInit("prefabname", initfn)
--		Use this to modify a prefab by adding, removing, or editing its properties
--		and components.
-----------------------------------

local function BetterCarrotInit(prefab)
	prefab.components.edible.hungervalue = 200 -- carrots are the best food ever!!
end
AddPrefabPostInit("carrot", BetterCarrotInit)

About creating the mod itself, you need a mod folder, with a modmain.lua and a modinfo.lua. I suggest you to download one or two mods on the workshop to see how they work and how the file are looking like. Then put the mod folder in the "mods" folder of your game and you should be able to test your mod.

(The code posted above as an example goes in the modmain.lua file)

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