Advertisement
Guest User

Untitled

a guest
Sep 6th, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.41 KB | None | 0 0
  1. local skills = {
  2. [32384] = {id=SKILL_SWORD,voc=4}, -- KNIGHT
  3. [32385] = {id=SKILL_AXE,voc=4}, -- KNIGHT
  4. [32386] = {id=SKILL_CLUB,voc=4}, -- KNIGHT
  5. [32387] = {id=SKILL_DISTANCE,voc=3,range=CONST_ANI_SIMPLEARROW}, -- PALADIN
  6. [32388] = {id=SKILL_MAGLEVEL,voc=2,range=CONST_ANI_SMALLICE}, -- DRUID
  7. [32389] = {id=SKILL_MAGLEVEL,voc=1,range=CONST_ANI_FIRE}, -- SORCERER
  8. [32124] = {id=SKILL_SWORD,voc=4}, -- KNIGHT
  9. [32125] = {id=SKILL_AXE,voc=4}, -- KNIGHT
  10. [32126] = {id=SKILL_CLUB,voc=4}, -- KNIGHT
  11. [32127] = {id=SKILL_DISTANCE,voc=3,range=CONST_ANI_SIMPLEARROW}, -- PALADIN
  12. [32128] = {id=SKILL_MAGLEVEL,voc=2,range=CONST_ANI_SMALLICE}, -- DRUID
  13. [32129] = {id=SKILL_MAGLEVEL,voc=1,range=CONST_ANI_FIRE} -- SORCERER
  14. }
  15.  
  16. local houseDummies = {32143, 32144, 32145, 32146, 32147, 32148}
  17. local freeDummies = {32142, 32149}
  18. local skillRate = configManager.getNumber(configKeys.RATE_SKILL)
  19. local magicRate = configManager.getNumber(configKeys.RATE_MAGIC)
  20.  
  21. local function start_train(pid,start_pos,itemid,fpos, bonusDummy, dummyId)
  22. local player = Player(pid)
  23. if player ~= nil then
  24. if Tile(fpos):getItemById(dummyId) then
  25. local pos_n = player:getPosition()
  26. if start_pos:getDistance(pos_n) == 0 and getTilePzInfo(pos_n) then
  27. if player:getItemCount(itemid) >= 1 then
  28. local exercise = player:getItemById(itemid,true)
  29. if exercise:isItem() then
  30. if exercise:hasAttribute(ITEM_ATTRIBUTE_CHARGES) then
  31. local charges_n = exercise:getAttribute(ITEM_ATTRIBUTE_CHARGES)
  32. if charges_n >= 1 then
  33. exercise:setAttribute(ITEM_ATTRIBUTE_CHARGES,(charges_n-1))
  34.  
  35. local voc = player:getVocation()
  36.  
  37. if skills[itemid].id == SKILL_MAGLEVEL then
  38. if not bonusDummy then
  39. player:addManaSpent(math.ceil(500*magicRate))
  40. else
  41. player:addManaSpent(math.ceil(500*magicRate)*1.1) -- 10%
  42. end
  43. else
  44. if not bonusDummy then
  45. player:addSkillTries(skills[itemid].id, 1*skillRate)
  46. else
  47. player:addSkillTries(skills[itemid].id, (1*skillRate)*1.1) -- 10%
  48. end
  49. end
  50. fpos:sendMagicEffect(CONST_ME_HITAREA)
  51. if skills[itemid].range then
  52. pos_n:sendDistanceEffect(fpos, skills[itemid].range)
  53. end
  54. local training = addEvent(start_train, voc:getAttackSpeed(), pid,start_pos,itemid,fpos,bonusDummy,dummyId)
  55. player:setStorageValue(Storage.isTraining,1)
  56. else
  57. exercise:remove(1)
  58. player:sendTextMessage(MESSAGE_INFO_DESCR, "Your training weapon vanished.")
  59. stopEvent(training)
  60. player:setStorageValue(Storage.isTraining,0)
  61. end
  62. end
  63. end
  64. end
  65. else
  66. player:sendTextMessage(MESSAGE_INFO_DESCR, "Your training has stopped.")
  67. stopEvent(training)
  68. player:setStorageValue(Storage.isTraining,0)
  69. end
  70. else
  71. stopEvent(training)
  72. player:sendTextMessage(MESSAGE_INFO_DESCR, "Your training has stopped.")
  73. player:setStorageValue(Storage.isTraining, 0)
  74. end
  75. else
  76. stopEvent(training)
  77. if player then
  78. player:sendTextMessage(MESSAGE_INFO_DESCR, "Your training has stopped.")
  79. player:setStorageValue(Storage.isTraining,0)
  80. end
  81. end
  82.  
  83. return true
  84. end
  85.  
  86. function onUse(player, item, fromPosition, target, toPosition, isHotkey)
  87. local start_pos = player:getPosition()
  88. if player:getStorageValue(Storage.isTraining) == 1 then
  89. player:sendTextMessage(MESSAGE_INFO_DESCR, "You are already training.")
  90. return false
  91. end
  92. if target:isItem() then
  93. if isInArray(houseDummies,target:getId()) then
  94. if not skills[item.itemid].range and (start_pos:getDistance(target:getPosition()) > 1) then
  95. player:sendTextMessage(MESSAGE_INFO_DESCR, "Get closer to the dummy.")
  96. stopEvent(training)
  97. return true
  98. end
  99. player:sendTextMessage(MESSAGE_INFO_DESCR, "You started training.")
  100. start_train(player:getId(),start_pos,item.itemid,target:getPosition(), true, target:getId())
  101. elseif isInArray(freeDummies, target:getId()) then
  102. if not skills[item.itemid].range and (start_pos:getDistance(target:getPosition()) > 1) then
  103. player:sendTextMessage(MESSAGE_INFO_DESCR, "Get closer to the dummy.")
  104. stopEvent(training)
  105. return true
  106. end
  107. player:sendTextMessage(MESSAGE_INFO_DESCR, "You started training.")
  108. start_train(player:getId(),start_pos,item.itemid,target:getPosition(), false, target:getId())
  109. end
  110. end
  111. return true
  112. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement