Advertisement
Guest User

Untitled

a guest
Feb 5th, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.51 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.entity:SetPristine()
  89.  
  90.     if not TheWorld.ismastersim then
  91.         return inst
  92.     end
  93.    
  94.     inst:AddTag("hat")
  95.    
  96.         --it is important that you use the original hat's prefab name for bank (if you used wodbhat then leave it featherhat)
  97.     anim:SetBank("featherhat")
  98.        
  99.         --this is what you put in the build.bin when making the hat's .zip file
  100.     anim:SetBuild("wodbhat")
  101.        
  102.         --this is just the animation it plays leave it where it's at unless you use a different hat and run into problems
  103.     anim:PlayAnimation("anim")  
  104.        
  105.     --you want to be able to be examined it right?
  106.     inst:AddComponent("inspectable")
  107.    
  108.         --to be honest I don't know what this does
  109.     inst:AddTag("irreplaceable")
  110.  -- I think it means lureplants can't eat it, or something. Nik Mik.
  111.    
  112.         --this is so you can carry it in your inventory
  113.     inst:AddComponent("inventoryitem")
  114.     inst.components.inventoryitem.atlasname = "images/inventoryimages/wodbhat.xml"
  115.    
  116.         --this adds a sanity boost to your hat! this is half of what top hat gives
  117.     inst:AddComponent("waterproofer")
  118.     inst.components.waterproofer:SetEffectiveness(TUNING.WATERPROOFNESS_LARGE)
  119.    
  120.    
  121.         --this is so the game knows to put it on your head
  122.     inst:AddComponent("equippable")
  123.     inst.components.equippable.equipslot = EQUIPSLOTS.HEAD
  124. -- You can also do EQUIPSLOTS.BODY or EQUIPSLOTS.HANDS to make it use different slots.
  125.     inst:AddComponent("insulator")
  126.  
  127.  
  128.   inst.components.insulator:SetInsulation(TUNING.INSULATION_LARGE)
  129.        
  130.        
  131.  
  132.         --this is so the game knows there is a onequip and onunequip function
  133.     inst.components.equippable:SetOnEquip( onequip )
  134.     inst.components.equippable:SetOnUnequip( onunequip )
  135.        
  136.        
  137.     return inst
  138. end
  139.  
  140. return Prefab( "common/inventory/wodbhat", fn, assets)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement