Advertisement
Starly124

Untitled

Feb 15th, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 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. -- Give player ingredients.
  29. local function returningredients(inst)
  30.  
  31. -- List of ingredients to return.
  32. local ingredients = {
  33. "spear",
  34. "spear",
  35. }
  36.  
  37. for k,ingredient in pairs(ingredients) do
  38. local item = SpawnPrefab(ingredient)
  39. GetPlayer().components.inventory:GiveItem(item)
  40. end
  41. inst.wascrafted = true
  42. end
  43.  
  44. -- OnSave and OnLoad, so that we only give ingredients once.
  45. local function onload(inst, data)
  46. if data and data.wascrafted then
  47. inst.wascrafted = data.wascrafted
  48. end
  49. end
  50.  
  51. local function onsave(inst, data)
  52. if inst.wascrafted then
  53. data.wascrafted = inst.wascrafted
  54. end
  55. end
  56.  
  57. -------------------------------------------
  58.  
  59. local function fn(Sim)
  60. local inst = CreateEntity()
  61. local trans = inst.entity:AddTransform()
  62. local anim = inst.entity:AddAnimState()
  63. MakeInventoryPhysics(inst)
  64.  
  65. inst.AnimState:SetBank("warhammer")
  66. inst.AnimState:SetBuild("warhammer")
  67. inst.AnimState:PushAnimation("idle")
  68.  
  69. inst:AddTag("sharp")
  70.  
  71. inst:AddComponent("weapon")
  72. inst.components.weapon:SetDamage(TUNING.SPEAR_DAMAGE)
  73.  
  74. inst:AddComponent("finiteuses")
  75. inst.components.finiteuses:SetMaxUses(TUNING.SPEAR_USES*2)
  76. inst.components.finiteuses:SetUses(TUNING.SPEAR_USES*2)
  77.  
  78. inst.components.finiteuses:SetOnFinished( onfinished )
  79.  
  80. inst:AddComponent("inspectable")
  81.  
  82. inst:AddComponent("inventoryitem")
  83. inst.components.inventoryitem.imagename = "warhammer"
  84. inst.components.inventoryitem.atlasname = "images/inventoryimages/warhammer.xml"
  85.  
  86. inst:AddComponent("equippable")
  87. inst.components.equippable:SetOnEquip( onequip )
  88. inst.components.equippable:SetOnUnequip( onunequip )
  89.  
  90. ----------------------------------
  91.  
  92. -- Save so that we don't do this more than once.
  93. inst.OnSave = onsave
  94. inst.OnLoad = onload
  95.  
  96. -- Return ingredients.
  97. if not inst.wascrafted then
  98. returningredients(inst)
  99. end
  100.  
  101. ----------------------------------
  102.  
  103. return inst
  104. end
  105.  
  106. return Prefab( "common/warhammer", fn, assets)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement