Oskar1121

Untitled

Oct 4th, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. local condition = createConditionObject(CONDITION_EXHAUST)
  2. setConditionParam(condition, CONDITION_PARAM_TICKS, 750)
  3. setConditionParam(condition, CONDITION_PARAM_SUBID, 128)
  4.  
  5. local REGENERATION_HEALTH = 1
  6. local REGENERATION_MANA = 2
  7.  
  8. local CHECKING_STORAGE_DO_NOT_CHANGE = 4999
  9. local CHECKING_LAST_ID = 11
  10.  
  11. local config = {
  12. [11372] = {regeneration = {REGENERATION_HEALTH, 8, REGENERATION_MANA, 8}, removeItem = false, effect = 12},
  13. [11373] = {regeneration = {REGENERATION_HEALTH, 35, REGENERATION_MANA, 35}, removeItem = false, effect = 46},
  14. [11394] = {regeneration = {REGENERATION_HEALTH, 50, REGENERATION_MANA, 50}, removeItem = true, effect = 12},
  15. [11393] = {regeneration = {REGENERATION_HEALTH, 80, REGENERATION_MANA, 80}, removeItem = true, effect = 12}
  16. }
  17.  
  18. local function getVariable(cid, variable)
  19. local var = tonumber(getCreatureStorage(cid, CHECKING_STORAGE_DO_NOT_CHANGE))
  20. if var < 2 ^ (variable - 1) then
  21. return true
  22. end
  23.  
  24. for i = CHECKING_LAST_ID, (variable - 1), -1 do
  25. if var >= 2 ^ i then
  26. if i == (variable - 1) then
  27. return false
  28. end
  29.  
  30. var = var - (2 ^ i)
  31. end
  32. end
  33.  
  34. return true
  35. end
  36.  
  37. function onUse(cid, item, fromPos, itemEx, toPos)
  38. local var = config[item.itemid]
  39. if not var then
  40. return false
  41. end
  42.  
  43. if getCreatureCondition(cid, CONDITION_EXHAUST, 128)then
  44. return false
  45. end
  46.  
  47. doAddCondition(cid, condition)
  48.  
  49. for i = 1, #var.regeneration / 2 do
  50. local value, color = 0, 0
  51. if var.regeneration[i * 2 - 1] == REGENERATION_HEALTH then
  52. local health = getCreatureMaxHealth(cid)
  53. value, color = math.min(health - getCreatureHealth(cid), health * var.regeneration[i * 2] / 100), 68
  54.  
  55. if not getVariable(cid, 6) then
  56. value = value * 1.1
  57. end
  58.  
  59. doCreatureAddHealth(cid, value)
  60. elseif var.regeneration[i * 2 - 1] == REGENERATION_MANA then
  61. local mana = getCreatureMaxMana(cid)
  62. value, color = math.min(mana - getCreatureMana(cid), mana * var.regeneration[i * 2] / 100), 22
  63.  
  64. if not getVariable(cid, 6) then
  65. value = value * 1.1
  66. end
  67.  
  68. doCreatureAddMana(cid, value)
  69. end
  70.  
  71. if value > 0 and color > 0 then
  72. doSendAnimatedText(getThingPos(cid), value, color)
  73. end
  74. end
  75.  
  76. if var.removeItem then
  77. doRemoveItem(item.uid, 1)
  78. end
  79.  
  80. doSendMagicEffect(getThingPos(cid), var.effect)
  81. return true
  82. end
Advertisement
Add Comment
Please, Sign In to add comment