API Lua Exemples

0 entradas — Referencia del bot WGRetro para Dofus Retro

Documentación completa
Exemple : Route de farm complete
-- Trajet de farm avec banque automatique
bot.log("Demarrage du farm...")

-- Route banque (pods pleins)
bot.setBankRoute({
    { map = "5,-17", path = "bottom" },
    { map = "4,-17", npcBank = true, path = "top" },
    { map = "5,-17", path = "right" },
})

-- Route principale
bot.route({
    { map = "5,-24", path = "right", gather = true, fight = true },
    { map = "6,-24", path = "right", gather = true },
    { map = "7,-24", path = "bottom", fight = true },
    { map = "7,-23", path = "left", gather = true },
    { map = "6,-23", path = "left" },
    { map = "5,-23", path = "top" },
})
Exemple : Combat scripte (fightManagement)
-- Combat manuel
while bot.inFight() do
    local myTurn = bot.waitForTurn()
    if not myTurn then break end

    local enemy = bot.getNearestEnemy()
    if enemy then
        -- Cast sort 3 sur l'ennemi le plus proche
        bot.castSpellOnCell(3, enemy.cell)
    end
    bot.passTurn()
end
Exemple : Stat/Spell boost
-- Monter la force a 300 base
bot.statUpgrade("strength", 300)

-- Monter le sort 161 au niveau 5
bot.spellUpgrade(161, 5)
Exemple : IA de combat avancee (style DJ)
-- === Configuration ===
local SPELL_MAIN    = 161  -- Sort principal (ex: Pression)
local SPELL_BUFF    = 162  -- Sort de buff (ex: Epee de Iop)
local SPELL_AOE     = 163  -- Sort AoE (ex: Coup de Vent)
local SPELL_BOOST   = 164  -- Sort de boost perso
local HP_FLEE       = 25   -- % PV pour fuir

-- === Monter sorts et stats au demarrage ===
bot.spellUpgrade(SPELL_MAIN, 5)
bot.statUpgrade("strength", 300)

-- === Definir route de farm ===
bot.setBankRoute({
    { map = "4,-17", npcBank = true, path = "top" },
    { map = "5,-17", path = "right" },
})

bot.route({
    {
        map = "5,-24",
        path = "right",
        fight = true,
        gather = true,

        -- --- Placement ---
        prefightManagement = function(myCells)
            -- Choisir la cellule de placement la plus centrale
            local mid = math.floor(#myCells / 2) + 1
            bot.chooseCell(myCells[mid])
            bot.fightReady()
        end,

        -- --- IA de combat ---
        fightManagement = function()
            bot.fightLog("Tour " .. bot.turnNumber() .. " | PA:" .. bot.myAP() .. " PM:" .. bot.myMP() .. " PV:" .. bot.myFightLifePercent() .. "%")

            -- Fuir si PV critiques
            if bot.myFightLifePercent() < HP_FLEE then
                local farthest = bot.getFarthestEnemy()
                if farthest then bot.moveAway(farthest.id) end
                bot.endTurn()
                return
            end

            -- Phase 1 : Buff si tour 1 et sort dispo
            if bot.turnNumber() == 1 and bot.canCastSpell(SPELL_BOOST).ok then
                bot.castSpell(SPELL_BOOST, bot.myFightCell())
                sleep(0.3)
            end

            -- Phase 2 : AoE si >= 2 ennemis groupes
            local aoe = bot.getBestZoneTarget(SPELL_AOE)
            if aoe and aoe.count >= 2 and bot.canCastSpellOnCell(SPELL_AOE, aoe.cellId) == "ok" then
                bot.fightLog("AoE sur cellule " .. aoe.cellId .. " -> " .. aoe.count .. " ennemis")
                bot.castSpell(SPELL_AOE, aoe.cellId)
                sleep(0.3)
            end

            -- Phase 3 : Se rapprocher si hors portee
            local enemy = bot.getNearestEnemy()
            if enemy then
                local spellData = bot.getFightSpell(SPELL_MAIN)
                local dist = bot.distanceTo(enemy.cell)

                if spellData and dist > spellData.maxRange then
                    bot.moveToward(enemy.id)
                    sleep(0.3)
                end

                -- Phase 4 : Spam sort principal tant que possible
                while bot.canCastSpellOnCell(SPELL_MAIN, enemy.cell) == "ok" do
                    bot.castSpell(SPELL_MAIN, enemy.cell)
                    sleep(0.3)
                end

                -- Phase 5 : Sort secondaire si PA restants
                if bot.canCastSpellOnCell(SPELL_BUFF, enemy.cell) == "ok" then
                    bot.castSpell(SPELL_BUFF, enemy.cell)
                    sleep(0.3)
                end

                -- Phase 6 : Fuir apres avoir frappe si au CaC
                if bot.myMP() > 0 and bot.distanceTo(enemy.cell) <= 1 then
                    bot.moveAway(enemy.id)
                end
            end

            bot.endTurn()
        end,
    },
    { map = "6,-24", path = "right", gather = true, fight = true },
    { map = "7,-24", path = "bottom", fight = true },
    { map = "7,-23", path = "left", gather = true },
    { map = "6,-23", path = "left" },
    { map = "5,-23", path = "top" },
})
Exemple : Auto-play simple
-- Definir les sorts a utiliser automatiquement
bot.addSpell(161)  -- Sort 1
bot.addSpell(162)  -- Sort 2

bot.route({
    {
        map = "5,-24",
        path = "right",
        fight = true,
        -- playTurn() utilise la liste addSpell() pour cast sur l'ennemi le plus proche
        fightManagement = function()
            bot.playTurn()  -- cast tous les sorts + endTurn
        end,
    },
})

Estas funciones se usan en los scripts Lua del bot WGRetro — probables con el plan gratis (1 bot, sin límite de tiempo). Scripts listos para usar en el marketplace.