• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

OTClient - CandyBot - Problem with talk delay on 7.6

therrax

Member
Joined
Jul 12, 2012
Messages
262
Solutions
1
Reaction score
11
Hello

I am using CandyBot module on 7.6 vers (armia.toproste.pl). While speaking server command "!mm"(using mana fluid), character becomes exhausted. It looks like he wanted to use them two times.

Maybe instead of function talk() i should call press hotkey or smth? How to fix that? Any suggestions?


Lua code:
Lua:
-- Auto Mana Spell
SupportModule.AutoManaSpell = {}
AutoManaSpell = SupportModule.AutoManaSpell

local nextMana = {}

local settings = {
  [RestoreType.cast] = 'AutoManaSpell',
  [RestoreType.item] = 'AutoManaItem'
}

function AutoManaSpell.onManaChange(player, mana, maxMana, oldMana, restoreType, tries)
  local tries = tries or 10

  local Panel = SupportModule.getPanel()
  if not Panel:getChildById(settings[restoreType]):isChecked() then
    return -- has since been unchecked
  end

  if restoreType == RestoreType.cast then
    local spellText = Panel:getChildById('ManaSpellText'):getText()
    local manaValue = Panel:getChildById('ManaBar'):getValue()
 
    local delay = 1100
    if player:getManaPercent() < manaValue then
       g_game.talk(spellText)
  
    
      delay = 1100
    end

    nextMana[RestoreType.cast] = 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
        AutoManaSpell.onManaChange(player, mana, maxMana, mana, restoreType, tries)
      else
        removeEvent(nextMana[RestoreType.cast])
      end
    end, delay)
  end
end


function AutoManaSpell.executeCast(player, mana, maxMana, oldMana)
  AutoManaSpell.onManaChange(player, mana, maxMana, oldMana, RestoreType.cast)
end

function AutoManaSpell.ConnectCastListener(listener)
  if g_game.isOnline() then
    local player = g_game.getLocalPlayer()
    addEvent(AutoManaSpell.onManaChange(player, player:getMana(),
      player:getMaxMana(), player:getMana(), RestoreType.cast))
  end

  connect(LocalPlayer, { onManaChange = AutoManaSpell.executeCast })
end

function AutoManaSpell.DisconnectCastListener(listener)
  disconnect(LocalPlayer, { onManaChange = AutoManaSpell.executeCast })
end
 
Last edited:
Here's an example:
Code:
--[[ Nubski skrypt napisany przez Ero Senina : {
]]
local delay = 900
auto_manas = cycleEvent( function ()
    if g_game.isOnline() then
        local mana = g_game.getLocalPlayer():getMana()
        local maxMana = g_game.getLocalPlayer():getMaxMana()
            if (mana < ((maxMana / 100) * 95))  then
               local checkItem = g_game.findPlayerItem(2874, -1)
               if checkItem then
                   g_game.talk('!mm')
               end
            end
    else
        removeEvent(auto_manas)
    end
end,  delay)
g_keyboard.bindKeyPress('F1', function()
    removeEvent(auto_manas)
end)
This script will call '!mm' on default channel every 900 ms if your mana is less than 95%
Press F1 or logout to turn it off.
Just copy whole script and paste it into OTClient terminal(ctrl+T). Enjoy.
 
Last edited:
Back
Top