Advertisement
Guest User

Untitled

a guest
Jan 29th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. local config = {
  2. manaCost = 300,
  3. soulCost = 2,
  4. }
  5.  
  6. local spheres = {
  7. [7759] = {3, 7},
  8. [7760] = {1, 5},
  9. [7761] = {2, 6},
  10. [7762] = {4, 8}
  11. }
  12.  
  13. local enchantableGems = {2147, 2146, 2149, 2150}
  14. local enchantableItems = {2383, 7383, 7384, 7406, 7402, 2429, 2430, 7389, 7380, 2454, 2423, 2445, 7415, 7392, 2391, 2544, 8905}
  15.  
  16. local enchantingAltars = {
  17. {7504, 7505, 7506, 7507},
  18. {7508, 7509, 7510, 7511},
  19. {7516, 7517, 7518, 7519},
  20. {7512, 7513, 7514, 7515}
  21. }
  22.  
  23. local enchantedGems = {7760, 7759, 7761, 7762}
  24. local enchantedItems = {
  25. [2383] = {7744, 7763, 7854, 7869},
  26. [7383] = {7745, 7764, 7855, 7870},
  27. [7384] = {7746, 7765, 7856, 7871},
  28. [7406] = {7747, 7766, 7857, 7872},
  29. [7402] = {7748, 7767, 7858, 7873},
  30. [2429] = {7749, 7768, 7859, 7874},
  31. [2430] = {7750, 7769, 7860, 7875},
  32. [7389] = {7751, 7770, 7861, 7876},
  33. [7380] = {7752, 7771, 7862, 7877},
  34. [2454] = {7753, 7772, 7863, 7878},
  35. [2423] = {7754, 7773, 7864, 7879},
  36. [2445] = {7755, 7774, 7865, 7880},
  37. [7415] = {7756, 7775, 7866, 7881},
  38. [7392] = {7757, 7776, 7867, 7882},
  39. [2391] = {7758, 7777, 7868, 7883},
  40. [2544] = {7840, 7839, 7850, 7838},
  41. [8905] = {8906, 8907, 8909, 8908}
  42. }
  43.  
  44. function onUse(player, item, fromPosition, target, toPosition, isHotkey)
  45. if isInArray({33268, 33269}, toPosition.x) and toPosition.y == 31830 and toPosition.z == 10 and player:getStorageValue(Storage.ElementalSphere.QuestLine) > 0 then
  46. if not isInArray(spheres[item.itemid], player:getVocation():getId()) then
  47. return false
  48. elseif isInArray({7915, 7916}, target.itemid) then
  49. player:say('Turn off the machine first.', TALKTYPE_MONSTER_SAY)
  50. return true
  51. else
  52. player:setStorageValue(Storage.ElementalSphere.MachineGemCount, math.max(1, player:getStorageValue(Storage.ElementalSphere.MachineGemCount) + 1))
  53. toPosition:sendMagicEffect(CONST_ME_PURPLEENERGY)
  54. item:transform(item.itemid, item.type - 1)
  55. return true
  56. end
  57. end
  58.  
  59. if item.itemid == 2147 and target.itemid == 2342 then
  60. target:transform(2343)
  61. target:decay()
  62. item:remove(1)
  63. toPosition:sendMagicEffect(CONST_ME_MAGIC_RED)
  64. return true
  65. end
  66.  
  67. if item.itemid == 7760 and isInArray({9934, 10022}, target.itemid) then
  68. target:transform(9933)
  69. item:remove(1)
  70. toPosition:sendMagicEffect(CONST_ME_MAGIC_RED)
  71. return true
  72. end
  73.  
  74. if isInArray(enchantableGems, item.itemid) then
  75. local subtype = item.type
  76. if subtype == 0 then
  77. subtype = 1
  78. end
  79.  
  80. local mana = config.manaCost * subtype
  81. if player:getMana() < mana then
  82. player:say('Not enough mana, separate one gem in your backpack and try again.', TALKTYPE_MONSTER_SAY)
  83. return false
  84. end
  85.  
  86. local soul = config.soulCost * subtype
  87. if player:getSoul() < soul then
  88. player:sendCancelMessage(RETURNVALUE_NOTENOUGHSOUL)
  89. return false
  90. end
  91.  
  92. local targetId = table.find(enchantableGems, item.itemid)
  93. if not targetId or not isInArray(enchantingAltars[targetId], target.itemid) then
  94. return false
  95. end
  96.  
  97. player:addMana(-mana)
  98. player:addSoul(-soul)
  99. item:transform(enchantedGems[targetId])
  100. player:addManaSpent(mana * configManager.getNumber(configKeys.RATE_MAGIC))
  101. player:getPosition():sendMagicEffect(CONST_ME_HOLYDAMAGE)
  102. return true
  103. end
  104.  
  105. if item.itemid == 7761 and isInArray({9949, 9954}, target.itemid) then
  106. target:transform(target.itemid - 1)
  107. target:decay()
  108. item:remove(1)
  109. toPosition:sendMagicEffect(CONST_ME_MAGIC_GREEN)
  110. return true
  111. end
  112.  
  113. if isInArray(enchantedGems, item.itemid) then
  114. if not isInArray(enchantableItems, target.itemid) then
  115. fromPosition:sendMagicEffect(CONST_ME_POFF)
  116. return false
  117. end
  118.  
  119. local targetId = table.find(enchantedGems, item.itemid)
  120. if not targetId then
  121. return false
  122. end
  123.  
  124. local subtype = target.type
  125. if not isInArray({2544, 8905}, target.itemid) then
  126. subtype = 1000
  127. end
  128.  
  129. target:transform(enchantedItems[target.itemid][targetId], subtype)
  130. target:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
  131. item:remove(1)
  132. return true
  133. end
  134. return false
  135. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement