Guest User

kidhat.lua

a guest
Dec 6th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.76 KB | None | 0 0
  1. local assets=
  2. {
  3.     Asset("ANIM", "anim/kidhat.zip"),
  4.     Asset("ANIM", "anim/kidhat_swap.zip"),
  5.  
  6.     Asset("ATLAS", "images/inventoryimages/kidhat.xml"),
  7.     Asset("IMAGE", "images/inventoryimages/kidhat.tex"),
  8. }
  9.  
  10. local prefabs =
  11. {
  12. }
  13.  
  14. local function OnEquip(inst, owner)
  15.     if not owner:HasTag("hatkid") then
  16.         inst:DoTaskInTime(0, function()
  17.             owner.components.inventory:DropItem(inst)
  18.             --electricity effect, not used but maybe in the future
  19.             local x, y, z = inst.Transform:GetWorldPosition()
  20.             --SpawnPrefab("explode_small").Transform:SetPosition(x, y - .5, z)
  21.            
  22.             if owner:HasTag("player") then
  23.                 if owner.prefab=="wx78" then
  24.                     owner.components.talker:Say("ERROR: READ-ONLY HAT")    
  25.                 elseif owner.prefab=="wendy" then
  26.                     -- Wendy is also a little girl, changing the line a little.
  27.                     owner.components.talker:Say("I wasn't really gonna do it.")    
  28.                 elseif owner.prefab=="wes" then
  29.                     --Nothing, since Wes doesn't talk
  30.                     owner.components.talker:Say("")
  31.                 elseif owner.prefab=="wilbur" then
  32.                     -- Wilbur is monkee
  33.                     owner.components.talker:Say("Ooo")
  34.                 else
  35.                     owner.components.talker:Say("I wouldn't steal from a little girl!")
  36.                 end                
  37.                 return
  38.             end
  39.         end)
  40.         return
  41.     end
  42.     owner.AnimState:OverrideSymbol("swap_hat", "kidhat", "swap_hat")
  43.    
  44.     owner.AnimState:Show("HAT")
  45.     owner.AnimState:Show("HAT_HAIR")
  46.    
  47.     if owner:HasTag("player") then
  48.         owner.AnimState:Show("HEAD")
  49.         owner.AnimState:Hide("HEAD_HAT")
  50.     end
  51.    
  52.     --Hat Badge Slot
  53.     if inst.components.container ~= nil then
  54.         inst.components.container:Open(owner)
  55.     end
  56.    
  57. end
  58.  
  59. local function OnUnequip(inst, owner)
  60.  
  61.     owner.AnimState:Hide("HAT")
  62.     owner.AnimState:Hide("HAT_HAIR")
  63.     owner.AnimState:Show("HAIR_NOHAT")
  64.     owner.AnimState:Show("HAIR")
  65.    
  66.     if owner:HasTag("player") then
  67.         owner.AnimState:Show("HEAD")
  68.         owner.AnimState:Hide("HEAD_HAT")
  69.     end
  70.    
  71.     if inst.components.container ~= nil then
  72.         inst.components.container:Close()
  73.     end
  74. end
  75.  
  76. local function OnBadgeLoaded(inst, data)
  77.     print("Badge Loaded")
  78. end
  79.  
  80. local function OnBadgeUnloaded(inst, data)
  81.     print("Badge Unloaded")
  82. end
  83.  
  84. local function fn(Sim)
  85.     local inst = CreateEntity()
  86.     local trans = inst.entity:AddTransform()
  87.  
  88.  
  89.  
  90.     inst.entity:AddTransform()
  91.     inst.entity:AddAnimState()
  92.     inst.entity:AddSoundEmitter()
  93.     inst.entity:AddNetwork()
  94.    
  95.     MakeInventoryPhysics(inst)
  96.  
  97.     inst:AddTag("hat")
  98.     inst:AddTag("hatkidhat")
  99.    
  100.     if not TheWorld.ismastersim then
  101.         return inst
  102.     end
  103.    
  104.     inst.entity:SetPristine()
  105.    
  106.     inst.AnimState:SetBank("kidhat")
  107.     inst.AnimState:SetBuild("kidhat")
  108.     inst.AnimState:PlayAnimation("idle")
  109.    
  110.     MakeHauntableLaunch(inst)
  111.  
  112.     inst:AddComponent("inspectable")
  113.  
  114.     inst:AddComponent("waterproofer")
  115.     inst.components.waterproofer:SetEffectiveness(TUNING.WATERPROOFNESS_SMALL)
  116.  
  117.     inst:AddComponent("inventoryitem")
  118.     inst.components.inventoryitem.imagename = "kidhat"
  119.     inst.components.inventoryitem.atlasname = "images/inventoryimages/kidhat.xml"
  120.      
  121.     inst:AddComponent("equippable")
  122.     inst.components.equippable.equipslot = EQUIPSLOTS.HEAD
  123.     inst.components.equippable.dapperness = TUNING.DAPPERNESS_TINY * 3
  124.     inst.components.equippable:SetOnEquip( OnEquip )
  125.     inst.components.equippable:SetOnUnequip( OnUnequip )
  126.    
  127.     inst:AddComponent("insulator")
  128.     inst.components.insulator:SetWinter()
  129.     inst.components.insulator:SetInsulation(TUNING.INSULATION_TINY * TUNING.KIDHAT_INSULATION)
  130.    
  131.     inst:AddComponent("container")
  132.     inst.components.container:WidgetSetup("slingshot")
  133.     inst.components.container.canbeopened = false
  134.     inst:ListenForEvent("itemget", OnBadgeLoaded)
  135.     inst:ListenForEvent("itemlose", OnBadgeUnloaded)
  136.    
  137.     return inst
  138. end
  139. return  Prefab("kidhat", fn, assets, prefabs)
Add Comment
Please, Sign In to add comment