Jump to content

flowerhat lua file?


Recommended Posts

Hi guys,

 

I want to make a custom item that's essentially an infinite flower garland, but I'm kinda stumped as to where to start. Usually I'll find a lua file then mess with it, but I can't find anything for the flower garland?

 

Does anyone know where to find it, or have a copy of it?

 

Does anyone know where to find or have a copy of the flower garland images?

 

I looked through the forum and couldn't really find much.

 

Thanks

Link to comment
Share on other sites

yeah, that one is actually a little tricky. if u cant find an item, have a look in the wiki for the Debugspawn string, here it is "flowerhat". since theres no flowerhat in the the prefabs of the game or the dlc, its probably a special version of something more general: hats.lua. that whole lua is very dynamicly programed for all the differnt hats, so it would probably be easier, to use a hat from a mod as base(for instance the "bunnyhood" from the "link the hero"-mod), but thats up to u.

Link to comment
Share on other sites

@NotFunnyMistahJ, @Seiai,

 

It's pretty straightforward -- that becomes clear when you open up hats.lua in Notepad++ and press Alt-2 :)

 

Details below.

 

If you cut away everything pertaining to other hats, you can see that there's not all that much going on.  Just trace it back like it would execute.  return MakeHat("flower") is what we're interested in.

function MakeHat(name)    local fname = "hat_"..name        --> fname = "hat_flower"    local symname = name.."hat"       --> symname = "flowerhat"    local texture = symname..".tex"   --> texture = "flowerhat.tex"    local prefabname = symname        --> prefabname = "flowerhat"    local assets=        {            Asset("ANIM", "anim/"..fname..".zip"),  --> Asset("ANIM", "anim/hat_flower.zip")        }...     local prefabs = nil           -- NOTE: this is there in case a hat needs to add "extra" prefabs    if name == "bee" then         -- like special effects.        fn = bee...    elseif name == "flower" then        fn = flower    elseif...    return Prefab( "common/inventory/"..prefabname, fn or simple, assets, prefabs)end

You can see that the MakeHat function is effectively just returning the result of a Prefab function (which is to be expected, cause that's what you need to return from prefab files!).  Plugging in those values that we figured out above, we can determine that it's doing this:

return Prefab( "common/inventory/flowerhat", flower, assets, nil)

We already saw the assets variable above, so the only thing left to check out is the flower variable, which the code seems to suggest should be a function.  (Remember, in Lua functions are stored in variables just like tables.)  Here's how the flower variable(function) is defined:

local function flower()    local inst = simple()    inst.components.equippable.dapperness = TUNING.DAPPERNESS_TINY     inst:AddTag("show_spoilage")    inst:AddComponent("perishable")    inst.components.perishable:SetPerishTime(TUNING.PERISH_FAST)    inst.components.perishable:StartPerishing()    inst.components.perishable:SetOnPerishFn(generic_perish)    inst.components.equippable:SetOnEquip( opentop_onequip )    return instend

If you were to remove the perishable stuff, that becomes a very small function:

local function flower()    local inst = simple()    inst.components.equippable.dapperness = TUNING.DAPPERNESS_TINY    inst.components.equippable:SetOnEquip( opentop_onequip )    return instend 

So, we can tell that it starts out by calling the simple() function to create an instance, then adds on the dapperness boost and sets an onequip function.  Specifically, it uses the "opentop_onequip" function, because that function doesn't hide the character's hair like most hats do. Lets look at what simple() does.

    local function simple()        local inst = CreateEntity()        inst.entity:AddTransform()        inst.entity:AddAnimState()        MakeInventoryPhysics(inst)        inst.AnimState:SetBank(symname)        inst.AnimState:SetBuild(fname)        inst.AnimState:PlayAnimation("anim")        inst:AddTag("hat")        inst:AddComponent("inspectable")        inst:AddComponent("inventoryitem")        inst:AddComponent("tradable")        inst:AddComponent("equippable")        inst.components.equippable.equipslot = EQUIPSLOTS.HEAD        inst.components.equippable:SetOnEquip( onequip )        inst.components.equippable:SetOnUnequip( onunequip )        return inst    end

Pretty generic stuff.  The only notable thing here is that it sets an OnEquip and OnUnEquip function.  If you replicate this hat, there's no reason to set it once and then override it.

 

 

You should be able to figure it out from there on ;)  It's just a matter of combining all the elements into one big function, really.

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...