Guest User

Untitled

a guest
Feb 5th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.41 KB | None | 0 0
  1. --replace wodbhat with your hat's name
  2.  
  3. local assets=
  4. {
  5.     Asset("ANIM", "anim/wodbhat.zip"),
  6.         Asset("IMAGE", "images/inventoryimages/wodbhat.tex"),
  7.     Asset("ATLAS", "images/inventoryimages/wodbhat.xml"),
  8. }
  9.  
  10. --this is what happens when you equip the hat
  11. local function onequip(inst, owner)
  12.     owner.AnimState:OverrideSymbol("swap_hat", "wodbhat", "swap_hat")
  13.     owner.AnimState:Show("HAT")
  14.     owner.AnimState:Show("HAT_HAIR")
  15.     owner.AnimState:Hide("HAIR_NOHAT")
  16.     owner.AnimState:Hide("HAIR")
  17.  
  18.     owner.components.health:SetAbsorptionAmount(.375)
  19.    
  20.     owner.components.health.maxhealth = 25
  21.     owner.components.health:DoDelta(0, true)  -- this updates the health badge
  22.  
  23.    
  24.  
  25.     --this tells it to start losing durability when you equip it
  26.     if inst.components.fueled then
  27.         inst.components.fueled:StartConsuming()        
  28.     end
  29.    
  30.    inst.temperatureTask = inst:DoTaskInTime(5, function(inst)
  31.         if TheWorld.state.temperature > 35 then
  32.             inst.components.insulator:SetSummer()
  33.    
  34.         else
  35.             inst.components.insulator:SetWinter()
  36.  
  37.         end
  38.     end)
  39.    
  40. end
  41.  
  42.                
  43.  
  44. --this is what happens when you unequip the hat
  45. local function onunequip(inst, owner)
  46.     owner.AnimState:Hide("HAT")
  47.     owner.AnimState:Hide("HAT_HAIR")
  48.     owner.AnimState:Show("HAIR_NOHAT")
  49.     owner.AnimState:Show("HAIR")
  50.    
  51.    
  52.     owner.components.health:SetAbsorptionAmount(0)
  53.  
  54.     owner.components.health.maxhealth = 5
  55.     owner.components.health:DoDelta(0, true)  -- this updates the health badge
  56.  
  57.     if owner:HasTag("player") then
  58.         owner.AnimState:Show("HEAD")
  59.         owner.AnimState:Hide("HEAD_HAIR")
  60.     end
  61.  
  62.     --this tells it to stop losing durability when you unequip it
  63.     if inst.components.fueled then
  64.         inst.components.fueled:StopConsuming()
  65.     end
  66.  
  67.    
  68. end
  69.  
  70.                
  71.  
  72. --I have no idea why this is called spider_perish but it helps the hat perish!
  73. -- Nik Mik here! It's because the top hat and spider hat use the same function to be destroyed when they run out of fuel.
  74.     local function spider_perish(inst)
  75.         --spider_disable(inst) ain't needed, Fiddoop. That's telling the item to go to another function. E.G if you had the spider_disable_inst and a function with the same name that made the character fart unicorns, the code on this line would tell it to do that function.
  76.         inst:Remove()
  77.         -- This destroys it.
  78.     end
  79.  
  80.  
  81.  
  82. local function fn(Sim)
  83.         local inst = CreateEntity()
  84.         local trans = inst.entity:AddTransform()
  85.         local anim = inst.entity:AddAnimState()
  86.     MakeInventoryPhysics(inst)
  87.    
  88.     inst:AddTag("hat")
  89.    
  90.         --it is important that you use the original hat's prefab name for bank (if you used wodbhat then leave it featherhat)
  91.     anim:SetBank("featherhat")
  92.        
  93.         --this is what you put in the build.bin when making the hat's .zip file
  94.     anim:SetBuild("wodbhat")
  95.        
  96.         --this is just the animation it plays leave it where it's at unless you use a different hat and run into problems
  97.     anim:PlayAnimation("anim")  
  98.        
  99.     --you want to be able to be examined it right?
  100.     inst:AddComponent("inspectable")
  101.    
  102.         --to be honest I don't know what this does
  103.     inst:AddTag("irreplaceable")
  104.  -- I think it means lureplants can't eat it, or something. Nik Mik.
  105.    
  106.         --this is so you can carry it in your inventory
  107.     inst:AddComponent("inventoryitem")
  108.     inst.components.inventoryitem.atlasname = "images/inventoryimages/wodbhat.xml"
  109.    
  110.         --this adds a sanity boost to your hat! this is half of what top hat gives
  111.     inst:AddComponent("waterproofer")
  112.     inst.components.waterproofer:SetEffectiveness(TUNING.WATERPROOFNESS_LARGE)
  113.    
  114.    
  115.         --this is so the game knows to put it on your head
  116.     inst:AddComponent("equippable")
  117.     inst.components.equippable.equipslot = EQUIPSLOTS.HEAD
  118. -- You can also do EQUIPSLOTS.BODY or EQUIPSLOTS.HANDS to make it use different slots.
  119.     inst:AddComponent("insulator")
  120.  
  121.  
  122.   inst.components.insulator:SetInsulation(TUNING.INSULATION_LARGE)
  123.        
  124.        
  125.  
  126.         --this is so the game knows there is a onequip and onunequip function
  127.     inst.components.equippable:SetOnEquip( onequip )
  128.     inst.components.equippable:SetOnUnequip( onunequip )
  129.        
  130.        
  131.     return inst
  132. end
  133.  
  134. return Prefab( "common/inventory/wodbhat", fn, assets)
Add Comment
Please, Sign In to add comment