Advertisement
Guest User

DST Hat

a guest
Feb 4th, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.54 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 = 20
  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.    
  31. end
  32.  
  33.                
  34.  
  35. --this is what happens when you unequip the hat
  36. local function onunequip(inst, owner)
  37.     owner.AnimState:Hide("HAT")
  38.     owner.AnimState:Hide("HAT_HAIR")
  39.     owner.AnimState:Show("HAIR_NOHAT")
  40.     owner.AnimState:Show("HAIR")
  41.    
  42.    
  43.     owner.components.health:SetAbsorptionAmount(0)
  44.  
  45.     owner.components.health.maxhealth = 5
  46.     owner.components.health:DoDelta(0, true)  -- this updates the health badge
  47.  
  48.     if owner:HasTag("player") then
  49.         owner.AnimState:Show("HEAD")
  50.         owner.AnimState:Hide("HEAD_HAIR")
  51.     end
  52.  
  53.     --this tells it to stop losing durability when you unequip it
  54.     if inst.components.fueled then
  55.         inst.components.fueled:StopConsuming()
  56.     end
  57.   inst.temperatureTask = inst:DoTaskInTime(5, function(inst)
  58.         if TheWorld.state.temperature > 35 then
  59.             inst.components.insulator:SetSummer()
  60.                 inst.components.insulator:SetInsulation(TUNING.INSULATION_LARGE)
  61.         else
  62.             inst.components.insulator:SetWinter()
  63.             inst.components.insulator:SetInsulation(TUNING.INSULATION_LARGE)
  64.         end
  65.     end)
  66.    
  67. end
  68.  
  69.                
  70.  
  71. --I have no idea why this is called spider_perish but it helps the hat perish!
  72. -- 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.
  73.     local function spider_perish(inst)
  74.         --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.
  75.         inst:Remove()
  76.         -- This destroys it.
  77.     end
  78.        
  79. local function fn(Sim)
  80.         local inst = CreateEntity()
  81.         local trans = inst.entity:AddTransform()
  82.         local anim = inst.entity:AddAnimState()
  83.     MakeInventoryPhysics(inst)
  84.    
  85.     inst:AddTag("hat")
  86.    
  87.         --it is important that you use the original hat's prefab name for bank (if you used wodbhat then leave it featherhat)
  88.     anim:SetBank("featherhat")
  89.        
  90.         --this is what you put in the build.bin when making the hat's .zip file
  91.     anim:SetBuild("wodbhat")
  92.        
  93.         --this is just the animation it plays leave it where it's at unless you use a different hat and run into problems
  94.     anim:PlayAnimation("anim")  
  95.        
  96.     --you want to be able to be examined it right?
  97.     inst:AddComponent("inspectable")
  98.    
  99.         --to be honest I don't know what this does
  100.     inst:AddTag("irreplaceable")
  101.  -- I think it means lureplants can't eat it, or something. Nik Mik.
  102.    
  103.         --this is so you can carry it in your inventory
  104.     inst:AddComponent("inventoryitem")
  105.     inst.components.inventoryitem.atlasname = "images/inventoryimages/wodbhat.xml"
  106.    
  107.         --this adds a sanity boost to your hat! this is half of what top hat gives
  108.     inst:AddComponent("waterproofer")
  109.     inst.components.waterproofer:SetEffectiveness(TUNING.WATERPROOFNESS_LARGE)
  110.    
  111.    
  112.         --this is so the game knows to put it on your head
  113.     inst:AddComponent("equippable")
  114.     inst.components.equippable.equipslot = EQUIPSLOTS.HEAD
  115. -- You can also do EQUIPSLOTS.BODY or EQUIPSLOTS.HANDS to make it use different slots.
  116.     inst:AddComponent("insulator")
  117.  
  118.  
  119.   inst.components.insulator:SetInsulation(TUNING.INSULATION_LARGE)
  120.        
  121.        
  122.  
  123.         --this is so the game knows there is a onequip and onunequip function
  124.     inst.components.equippable:SetOnEquip( onequip )
  125.     inst.components.equippable:SetOnUnequip( onunequip )
  126.        
  127.        
  128.     return inst
  129. end
  130.  
  131. return Prefab( "common/inventory/wodbhat", fn, assets)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement