API Lua Exemples
0 entries — WGRetro bot reference for Dofus Retro
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()
endExemple : 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 : Equiper une pierre selon les monstres (placement)
-- Table de decision : templateId monstre -> pierre a equiper selon le nombre
local FRAISE = 57 -- templateId du monstre
local PIERRE_50 = 7331 -- pierre d'ame vide (palier bas)
local PIERRE_100 = 7332 -- pierre d'ame vide (palier haut)
local function choisirPierre()
-- compo du groupe ATTAQUE (capte au grab) — lisible en placement, contrairement a getEnemies()
local mons = bot.getPendingFightMonsters()
-- compter un type de monstre precis
local nbFraise = 0
for _, e in ipairs(mons) do
if tonumber(e.templateId) == FRAISE then nbFraise = nbFraise + 1 end
end
-- decision selon le nombre
local pierre
if nbFraise >= 2 then pierre = PIERRE_100
elseif nbFraise == 1 then pierre = PIERRE_50
else return end -- pas de fraise : ne rien changer
-- trouver l'uid en inventaire et equiper
local it = bot.getItem(pierre)
if it and it.uid then
bot.equipItem(it.uid)
bot.log("Pierre " .. pierre .. " equipee (fraises=" .. nbFraise .. ")")
else
bot.log("Pierre " .. pierre .. " absente de l'inventaire")
end
end
bot.route({
{
map = "5,-24",
fight = true,
-- prefightManagement est appele en placement ; getPendingFightMonsters() = groupe attaque
prefightManagement = function()
choisirPierre()
bot.fightReady() -- ready = APRES l'equipement (dernier truc)
end,
fightManagement = function()
bot.playTurn()
end,
},
})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,
},
})These functions are used in the WGRetro bot Lua scripts — testable with the free plan (1 bot, no time limit). Ready-to-use scripts on the marketplace.