Starly124

Untitled

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