Don't Starve Together

Don't Starve Together

Cosmetic Slots
 This topic has been pinned, so it's probably important
Kyno  [developer] 17 Sep @ 5:24pm
🔧 Mod Support
Cosmetic Slots supports other mods!

By default Modded Items will have their durability and spoilage time stopped when equipped as Cosmetic. If your item is more complex than that you can define custom logic on how it should behave when equipped to Cosmetic Slots.

⚙️ How to add support for your prefab

Add the following code to your prefab file:
local function onequipvanity(inst, owner) if owner ~= nil then -- Code end end local function onunequipvanity(inst, owner) if owner ~= nil then if inst.components.equippable ~= nil then inst.components.equippable:Unequip(owner) end -- Code end end -- In your prefab's master constructor inst.onequipvanity = onequipvanity inst.onunequipvanity = onunequipvanity
  • "onequipvanity" Runs when the item is equipped, usually you would want to remove every benefit the item provides, leaving only the appearance effects.

  • Some effects gets removed automatically: Waterproofness, Dapperness, Speed Bonuses, Defense Bonuses, Attack Bonuses, etc.

  • NOTE: For more complex effects you will need to remove them manually, especially Event callbacks and effects triggered by the item.

  • "onunequipvanity" Runs when the item is unequipped, this will restore the item to its original state, with their benefits and effects.

  • NOTE: Any complex effects and states will need to be restored manually.

🔐 Restricted Items
Items that can't go inside containers or the player's inventory such as Backpacks, are labeled as Restricted but that doesn't mean we can't equip them to Cosmetic Slots.

To make that, add the following code to your prefab file:
local function onpreequipvanity(inst, owner, from_ground) local inventoryitem = inst.components.inventoryitem inventoryitem.__cangoincontainer = inventoryitem.cangoincontainer inventoryitem.cangoincontainer = true end -- In your prefab's constructor inst:AddTag("vanity_item_restricted") -- In your prefab's master constructor inst.onpreequipvanity = onpreequipvanity
  • "onpreequipvanity" Runs right before "onequipvanity" and ensures the item can be equipped regardless if it couldn't originally.

  • By default when unequipping a Restricted Item the mod will restore its original state. That means if your item couldn't go inside the inventory before it will revert to that state after being unequipped from Cosmetic Slots.

  • Items that are containers such as Backpacks will drop everything inside of them when equipped.

To prevent that, add the following code to your prefab file:
-- In your prefab's constructor inst:AddTag("vanity_container_valid")
  • This will make your item valid as a container to Cosmetic Slots, preventing it from dropping any content stashed inside of them.

🚫 Forbid Items
Items that can't be equipped in Cosmetic Slots regardless, such as Heavy Objects, Oversized Farm Plants, Broken Items, etc.

To make that, add the following code to your prefab file:
-- In your prefab's constructor inst:AddTag("vanity_item_forbid")
  • This will prevent your item from being equipped to Cosmetic Slots.

📚 Examples
  • A headwear that ignites attackers and is fueled:
local function onequipvanity(inst, owner) if owner ~= nil then local fueled = inst.components.fueled if fueled ~= nil then if fueled.accepting ~= nil then fueled.__accepting = fueled.accepting fueled.accepting = false end end inst:RemoveEventCallback("attacked", inst.onattacked, owner) end end local function onunequipvanity(inst, owner) if owner ~= nil then if inst.components.equippable ~= nil then inst.components.equippable:Unequip(owner) end local fueled = inst.components.fueled if fueled ~= nil then if fueled.accepting ~= nil then fueled.accepting = fueled.__accepting end end end end -- Prefab's master constructor inst.onequipvanity = onequipvanity inst.onunequipvanity = onunequipvanity
  • A clothing that changes its appearence based on items stored inside and its perishable:
local function onequipvanity(inst, owner) if owner ~= nil then if inst.components.perishable ~= nil then inst.components.perishable:StopPerishing() end end end local function onunequipvanity(inst, owner) if owner ~= nil then if inst.components.equippable ~= nil then inst.components.equippable:Unequip(owner) end if inst.components.perishable ~= nil then inst.components.perishable:StartPerishing() end end end -- Prefab's constructor inst:AddTag("vanity_container_valid") -- Prefab's master constructor inst.onequipvanity = onequipvanity inst.onunequipvanity = onunequipvanity
  • A backpack item that reduces hunger rate:
local function onpreequipvanity(inst, owner, from_ground) local inventoryitem = inst.components.inventoryitem inventoryitem.__cangoincontainer = inventoryitem.cangoincontainer inventoryitem.cangoincontainer = true end local function onequipvanity(inst, owner) if owner ~= nil then if owner.components.hunger ~= nil then owner.components.hunger.burnratemodifiers:RemoveModifier(inst) end end end local function onunequipvanity(inst, owner) if owner ~= nil then if inst.components.equippable ~= nil then inst.components.equippable:Unequip(owner) end end end -- Prefab's constructor inst:AddTag("vanity_item_restricted") -- Prefab's master constructor inst.onpreequipvanity = onpreequipvanity inst.onequipvanity = onequipvanity inst.onunequipvanity = onunequipvanity

Let me know if you have any questions. Happy Modding!
Last edited by Kyno; 17 Sep @ 6:27pm