Skip to content

Commit

Permalink
Merge branch 'master' of github.com:zygzagZ/otclient-candybot
Browse files Browse the repository at this point in the history
  • Loading branch information
zygzagZ committed Feb 20, 2017
2 parents de94e44 + 68926fc commit 4c44d5c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
14 changes: 11 additions & 3 deletions modules/02-support/events/healthrestore.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,21 @@ function AutoHeal.onHealthChange(player, health, maxHealth, oldHealth, restoreTy
g_game.talk(spellText)
delay = Helper.getSpellDelay(spellText)
end

if nextHeal[RestoreType.cast] ~= nil then
removeEvent(nextHeal[RestoreType.cast])
end
nextHeal[RestoreType.cast] = scheduleEvent(function()
local player = g_game.getLocalPlayer()
if not player then return end

health, maxHealth = player:getHealth(), player:getMaxHealth()
if player:getHealthPercent() < healthValue and tries > 0 then
tries = tries - 1
nextHeal[RestoreType.cast] = nil
AutoHeal.onHealthChange(player, health, maxHealth, health, restoreType, tries)
else
removeEvent(nextHeal[RestoreType.cast])
nextHeal[RestoreType.cast] = nil
end
end, delay)

Expand All @@ -54,16 +58,20 @@ function AutoHeal.onHealthChange(player, health, maxHealth, oldHealth, restoreTy
if player:getHealthPercent() < healthValue then
Helper.safeUseInventoryItemWith(item:getId(), player, BotModule.isPrecisionMode())
end

nextHeal[RestoreType.item] = scheduleEvent(function()
if nextHeal[RestoreType.item] ~= nil then
removeEvent(nextHeal[RestoreType.item])
end
nextHeal[RestoreType.item] = scheduleEvent(function()
local player = g_game.getLocalPlayer()
if not player then return end
health, maxHealth = player:getHealth(), player:getMaxHealth()
if player:getHealthPercent() < healthValue and tries > 0 then
tries = tries - 1
nextHeal[RestoreType.item] = nil
AutoHeal.onHealthChange(player, health, maxHealth, health, restoreType, tries)
else
removeEvent(nextHeal[RestoreType.item])
nextHeal[RestoreType.item] = nil
end
end, delay)
end
Expand Down
7 changes: 6 additions & 1 deletion modules/02-support/events/manarestore.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,24 @@ function AutoMana.onManaChange(player, mana, maxMana, oldMana, restoreType, trie
local delay = Helper.getItemUseDelay()

if player:getManaPercent() < manaValue then
print('restore')
Helper.safeUseInventoryItemWith(item:getId(), player, BotModule.isPrecisionMode())
end

if nextMana then
removeEvent(nextMana)
end
nextMana = scheduleEvent(function()
local player = g_game.getLocalPlayer()
if not player then return end

mana, maxMana = player:getMana(), player:getMaxMana()
if player:getManaPercent() < manaValue and tries > 0 then
tries = tries - 1
nextMana = nil
AutoMana.onManaChange(player, mana, maxMana, mana, restoreType, tries)
else
removeEvent(nextMana)
nextMana = nil
end
end, delay)
end
Expand Down

0 comments on commit 4c44d5c

Please sign in to comment.