Jump to content

Recommended Posts

I have started to make a custom hat mod, and I want it to be able to give off heat, cook food, and give off light. Unfortunately, I know basically nothing about LUA programming. Could somebody tell me how to add tags to the script so that it works as intended?

I am currently using a custom hat template to do this, and they have already implemented some tags. I have made no changes to the code. It is here:
 

    --[[ TAGS ]]--
    inst:AddTag("custom_hat")
    -- Waterproofer (from waterproofer component) - this tag can be removed, but it's here just in case, to make the game run better.
    inst:AddTag("waterproofer")
    
    MakeInventoryFloatable(inst, "small", 0.1, 1.12)
    
    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        -- If we're not the host - stop performing further functions.
        -- Only server functions below.
        return inst
    end
    
    inst:AddComponent("inspectable")

    -- Allow "trading" the hat - used for giving the hat to Pigmen.
    inst:AddComponent("tradable")

    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.imagename = "custom_hat"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/custom_hat.xml"
    
    inst:AddComponent("equippable")
    inst.components.equippable.equipslot = EQUIPSLOTS.HEAD
    inst.components.equippable:SetOnEquip(OnEquip)
    inst.components.equippable:SetOnUnequip(OnUnequip)

    inst:AddComponent("fueled")
    -- This fuel type will allow us to use Sewing Kit to repair our hat.
    inst.components.fueled.fueltype = FUELTYPE.USAGE
    -- Our custom hat should last about 5 days of constant wearing (480 seconds is 1 day in DST).
    inst.components.fueled:InitializeFuelLevel(480*5)
    -- What should happen when we reach 0% usage - remove the item.
    inst.components.fueled:SetDepletedFn(inst.Remove)

    inst:AddComponent("waterproofer")
    -- Our hat shall grant 20% water resistance to the wearer!
    inst.components.waterproofer:SetEffectiveness(0.5)

    MakeHauntableLaunch(inst)

    return inst
end

return  Prefab("common/inventory/custom_hat", MainFunction, Assets)

Any help would be appreciated!

 

@BombardmentPigs

Tags are useful for labeling but they don't directly influence the behaviour of an entity.  Indirectly they can be used by other parts of the code base like components to look for things with tags to then modify.  In your case you're wanting to do a few things.

Production of heat you can look at how the heatrock prefab makes the holder warm.  It uses the heater component and uses the SetThermics function for controlling the properties of transference while manipulating the temperature degrees through the heater component's carriedheatfn callback.

To cook food there's an item in the game that does this already: Willow's Lighter.  It uses the cooker component.

To produce light on a hat equip the miner hat already does what you're looking for.  Look for 'minerhat' in prefabs/hats.lua for all of its relative handling and behaviour.

 

When tags are added to the entity before the pristine state this is a networking optimization.  Marking an entity as pristine means that both the server and client see the same thing.  So since some of these components that get added provide the tag to the entity it's better for the client to also mark that the entity has the tag since clients don't (normally) have components on entities with which to receive these tags.

  • Like 1

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