Oskar1121

Untitled

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