Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. local assets = {
  2. Asset("ANIM", "anim/sunlight_talisman.zip"),
  3. Asset("ANIM", "anim/sunlight_talisman_swap.zip"),
  4. }
  5.  
  6.  
  7. local mycharacter
  8.  
  9. local function onFinished(inst)
  10. inst.SoundEmitter:PlaySound("dontstarve/common/gem_shatter")
  11. inst:Remove()
  12. end
  13.  
  14. local function onAttack(inst)
  15. inst.SoundEmitter:PlaySound("dontstarve/music/thunder_close")
  16. inst:Remove()
  17. end
  18.  
  19. local function onEquip(inst, owner)
  20. owner.AnimState:OverrideSymbol("swap_object", "sunlight_talisman_swap", "sunlight_talisman_swap")
  21. owner.AnimState:Show("ARM_carry")
  22. owner.AnimState:Hide("ARM_normal")
  23. end
  24.  
  25. local function onUnequip(inst, owner)
  26. owner.AnimState:Hide("ARM_carry")
  27. owner.AnimState:Show("ARM_normal")
  28. end
  29.  
  30. local function onAttack(inst, attacker, target)
  31. target.components.combat:GetAttacked(attacker, 20*3)
  32. end
  33.  
  34. local function healHimSpell(inst, target)
  35. print (target)
  36. target.components.health:DoDelta(20*2)
  37. target.SoundEmitter:PlaySound("dontstarve/common/makeFriend")
  38. end
  39.  
  40. local function healSpell(inst, target, pos)
  41. if target then --used on target
  42. healHimSpell(inst, target)
  43. else --used on some position or from inventory
  44. mycharacter = GetPlayer()
  45. healHimSpell(inst, mycharacter)
  46. end
  47. end
  48.  
  49. local function canHeal(inst, caster, target)
  50. --target
  51. if target and target.components.health then return true end
  52. --no health targets
  53. if target and not target.components.health then return false end
  54. --inventory
  55. if not target then return true end
  56. end
  57.  
  58. local function fn()
  59. local inst = CreateEntity()
  60.  
  61. inst.entity:AddTransform()
  62. inst.entity:AddAnimState()
  63. inst.entity:AddSoundEmitter()
  64. --inst.entity:AddNetwork()
  65.  
  66. MakeInventoryPhysics(inst)
  67.  
  68. inst.AnimState:SetBank("sunlight_talisman")
  69. inst.AnimState:SetBuild("sunlight_talisman")
  70. inst.AnimState:PlayAnimation("idle")
  71.  
  72. inst:AddTag("nopunch")
  73.  
  74. --inst.entity:SetPristine()
  75. --[[
  76. if not TheWorld.ismastersim then
  77. return inst
  78. end
  79. ]]
  80. inst:AddComponent("finiteuses")
  81. inst.components.finiteuses:SetMaxUses(40)
  82. inst.components.finiteuses:SetUses(40)
  83. inst.components.finiteuses:SetConsumption(ACTIONS.CASTSPELL, 1)
  84. inst.components.finiteuses:SetOnFinished(onFinished)
  85.  
  86. inst:AddComponent("inspectable")
  87.  
  88. inst:AddComponent("weapon")
  89. inst.components.weapon:SetDamage(0)
  90. inst.components.weapon:SetRange(8, 10)
  91. inst.components.weapon:SetOnAttack(onAttack)
  92. inst.components.weapon:SetProjectile("lightning_projectile")
  93.  
  94. inst:AddComponent("inventoryitem")
  95. inst.components.inventoryitem.atlasname = "images/inventoryimages/sunlight_talisman.xml"
  96.  
  97. inst:AddComponent("equippable")
  98. inst.components.equippable:SetOnEquip(onEquip)
  99. inst.components.equippable:SetOnUnequip(onUnequip)
  100.  
  101.  
  102. inst:AddComponent("spellcaster")
  103. inst.components.spellcaster.canuseontargets = true
  104. inst.components.spellcaster.canuseonpoint = false
  105. inst.components.spellcaster.canusefrominventory = true
  106. inst.components.spellcaster:SetSpellTestFn(canHeal)
  107. inst.components.spellcaster:SetSpellFn(healSpell)
  108.  
  109. return inst
  110. end
  111.  
  112.  
  113. return Prefab("common/inventory/sunlight_talisman", fn, assets)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement