Advertisement
Starly124

Untitled

Feb 14th, 2015
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. local assets =
  2. {
  3. Asset("ANIM", "anim/warhammer.zip"),
  4. Asset("ANIM", "anim/swap_warhammer.zip"),
  5.  
  6. Asset("ATLAS", "images/inventoryimages/warhammer.xml"),
  7. Asset("IMAGE", "images/inventoryimages/warhammer.tex"),
  8. }
  9.  
  10. local function onfinished(inst)
  11. inst:Remove()
  12. end
  13.  
  14. local function onequip(inst, owner)
  15. owner.AnimState:OverrideSymbol("swap_object", "swap_warhammer", "swap_warhammer")
  16. owner.SoundEmitter:PlaySound("dontstarve/wilson/equip_item_gold")
  17. owner.AnimState:Show("ARM_carry")
  18. owner.AnimState:Hide("ARM_normal")
  19. end
  20.  
  21. local function onunequip(inst, owner)
  22. owner.AnimState:Hide("ARM_carry")
  23. owner.AnimState:Show("ARM_normal")
  24. end
  25.  
  26. -------------------------------------------
  27.  
  28. -- List of ingredients to return.
  29. local ingredients = {
  30. "spear",
  31. "spear",
  32. }
  33.  
  34. -- Give player ingredients.
  35. local function returningredients(inst)
  36. for k,ingredient in pairs(ingredients) do
  37. GetPlayer().components.inventory:GiveItem(ingredient)
  38. end
  39. end
  40.  
  41. -- OnSave and OnLoad, so that we only give ingredients once.
  42. local function onload(inst, data)
  43. if data and data.wascrafted then
  44. inst.wascrafted = data.wascrafted
  45. end
  46. end
  47.  
  48. local function onsave(inst, data)
  49. if inst.wascrafted then
  50. data.wascrafted = inst.wascrafted
  51. end
  52. end
  53.  
  54. -------------------------------------------
  55.  
  56. local function fn(Sim)
  57. local inst = CreateEntity()
  58. local trans = inst.entity:AddTransform()
  59. local anim = inst.entity:AddAnimState()
  60. MakeInventoryPhysics(inst)
  61.  
  62. inst.AnimState:SetBank("warhammer")
  63. inst.AnimState:SetBuild("warhammer")
  64. inst.AnimState:PushAnimation("idle")
  65.  
  66. inst:AddTag("sharp")
  67.  
  68. inst:AddComponent("weapon")
  69. inst.components.weapon:SetDamage(TUNING.SPEAR_DAMAGE)
  70.  
  71. inst:AddComponent("finiteuses")
  72. inst.components.finiteuses:SetMaxUses(TUNING.SPEAR_USES*2)
  73. inst.components.finiteuses:SetUses(TUNING.SPEAR_USES*2)
  74.  
  75. inst.components.finiteuses:SetOnFinished( onfinished )
  76.  
  77. inst:AddComponent("inspectable")
  78.  
  79. inst:AddComponent("inventoryitem")
  80. inst.components.inventoryitem.imagename = "warhammer"
  81. inst.components.inventoryitem.atlasname = "images/inventoryimages/warhammer.xml"
  82.  
  83. inst:AddComponent("equippable")
  84. inst.components.equippable:SetOnEquip( onequip )
  85. inst.components.equippable:SetOnUnequip( onunequip )
  86.  
  87. ----------------------------------
  88.  
  89. -- Save so that we don't do this more than once.
  90. inst.OnSave = onsave
  91. inst.OnLoad = onload
  92.  
  93. -- Return ingredients.
  94. if not inst.wascrafted then
  95. returningredients()
  96. end
  97.  
  98. ----------------------------------
  99.  
  100. return inst
  101. end
  102.  
  103. return Prefab( "common/warhammer", fn, assets)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement