API Lua Avance

165 entradas — Referencia del bot WGRetro para Dofus Retro

Documentación completa
Format d'un step
{
    map = "x,y",              -- map a matcher (requis) ou "mapId"
    path = "right",           -- direction ou cellId ou "zaap(mapId)"
    gather = true,            -- recolter
    fight = true,             -- combattre
    npcBank = true,           -- deposer en banque (true=auto, number=npc cellId)
    sale = true,              -- vendre HDV
    custom = function() end,  -- action personnalisee
    phoenix = true,           -- utiliser statue phenix
    fightManagement = function() end,                       -- IA de combat custom
    prefightManagement = function(myCells, enemyCells) end, -- callback de placement
}
Route — fightManagement
bot.route({
    {
        map = "5,-24",
        path = "right",
        fight = true,

        -- Phase de placement : choisir la cellule la plus eloignee des ennemis
        prefightManagement = function(myCells, enemyCells)
            local bestCell = myCells[1]
            local bestDist = 0
            for _, cell in ipairs(myCells) do
                local nearest = bot.getNearestEnemy()
                if nearest then
                    local d = bot.cellDistance(cell, nearest.cell)
                    if d > bestDist then
                        bestDist = d
                        bestCell = cell
                    end
                end
            end
            bot.chooseCell(bestCell)
            bot.fightReady()
        end,

        -- IA de combat custom : appelee chaque tour
        fightManagement = function()
            local enemy = bot.getNearestEnemy()
            if not enemy then
                bot.endTurn()
                return
            end

            -- Lancer sort 3 tant qu'on peut
            while bot.canCastSpellOnCell(3, enemy.cell) == "ok" do
                bot.castSpell(3, enemy.cell)
                sleep(0.3)
            end
            bot.endTurn()
        end,
    },
})
Evenements
bot.on("event", callback)
bot.once("event", callback)
Evenements
bot.on("fightEnded", function(result)
    log("Combat termine !")
end)

bot.on("levelUp", function(info)
    log("Level up !")
end)
Utilitaires
sleep(3)              -- pause 3 secondes
bot.sleep(1500)       -- pause 1500ms
log("Message")        -- raccourci pour bot.log
Memoire de session
bot.memorySet("compteur", 0)
local c = bot.memoryGet("compteur")
bot.memorySet("compteur", c + 1)
Mort / Fantome / Phoenix
-- Route phoenix (revive automatique)
bot.setPhoenixRoute({
    { map = "5,-17", path = "bottom" },
    { map = "5,-16", phoenix = true },
})

-- Verifier si mort
if bot.isGhost() then
    log("Bot est un fantome !")
end
Configuration Recolte
-- Ne recolter que le ble et le houblon
bot.setGatherList({"Ble", "Houblon"})
Paquets bruts
bot.onPacket("Im", function(data)
    log("Paquet Im recu: " .. data)
end)
Exchange (Echange joueur)
bot.exchangeRequestByName("NomJoueur")
local senderId = bot.waitForExchangeRequest(30000)
bot.putItem(289, 5)  -- mettre item
bot.putKamas(1000)
bot.exchangeGetItem(289, 5)  -- recuperer item
bot.exchangeReady()
bot.acceptExchange()
-- ou: bot.refuseExchange() / bot.exchangeLeave()
Memory (Session)
bot.memorySet("key", value)
local v = bot.memoryGet("key")
bot.memoryHas("key")  -- boolean
bot.memoryDelete("key")
Challenges / Invocations (Combat)
-- Dans fightManagement
if bot.hasChallenges() then
    local c = bot.getActiveChallenges()
end
if bot.summonCount() < bot.summonMax() then
    bot.summon(34, cells[1])
end
Syntaxe
-- Definir une fonction (end obligatoire)
function maFonction()
    bot.log("Hello !")
end

-- Appeler
maFonction()
Avec parametres
function farmMap(direction, combattre)
    bot.changeMap(direction)
    if combattre and bot.hasMonstersOnMap() then
        bot.fight()
        bot.waitForFightEnd()
    end
end

farmMap("right", true)
farmMap("bottom", false)
Avec retour
function doitAllerBanque()
    return bot.isPodsFull(0.8) or bot.kamas() > 50000
end

if doitAllerBanque() then
    bot.bankRoute()
end
Fonctions dans une route
function checkEtFarm()
    if bot.hpPercent() < 50 then
        bot.log("PV bas, on attend la regen")
        bot.sit()
        bot.waitForRegen()
    end
    if bot.hasMonstersOnMap() then
        bot.fight()
        bot.waitForFightEnd()
    end
end

bot.route({
    { map = "5,-19", path = "right", custom = checkEtFarm },
    { map = "6,-19", path = "bottom", custom = checkEtFarm },
})
Fonction de combat reutilisable
function monIA()
    local enemy = bot.getNearestEnemy()
    if not enemy then bot.endTurn() return end

    -- Sort principal
    while bot.canCastSpellOnCell(161, enemy.cell) == "ok" do
        bot.castSpell(161, enemy.cell)
        sleep(0.3)
    end

    -- Se rapprocher si possible
    if bot.myMP() > 0 then
        bot.moveToward(enemy.id)
    end

    bot.endTurn()
end

bot.route({
    { map = "5,-19", path = "right", fight = true, fightManagement = monIA },
    { map = "6,-19", path = "bottom", fight = true, fightManagement = monIA },
    { map = "6,-18", path = "left", fight = true, fightManagement = monIA },
})
Variables globales entre fonctions
totalKamas = 0

function compterKamas()
    local avant = bot.kamas()
    bot.fight()
    bot.waitForFightEnd()
    local gain = bot.kamas() - avant
    totalKamas = totalKamas + gain
    bot.log("Gain: " .. gain .. " | Total: " .. totalKamas)
end
Boucle avec fonction
function farmNFois(n)
    for i = 1, n do
        bot.log("Combat " .. i .. "/" .. n)
        if bot.hasMonstersOnMap() then
            bot.fight()
            bot.waitForFightEnd()
        end
        if bot.isPodsFull() then
            bot.bankRoute()
        end
        sleep(1)
    end
end

farmNFois(50)

Monture

Propiedad / MétodoTipoDescripción
bot.hasMount()booleanMonture equipee ?
bot.isRiding()booleanMonte ?
bot.toggleRide()voidMonter/descendre
bot.setMountXp(percent)void% XP monture (0-90)
bot.getMountInfo()table\nil | { name, level, energy, xp, stamina, love, maturity, serenity, riding, equipped }
bot.feedMount(itemUid, qty?)voidNourrir la monture
bot.renameMount(name)voidRenommer la monture

Metiers (Jobs)

Propiedad / MétodoTipoDescripción
bot.getJobs()table{{ id, level, xp, xpNext }}
bot.jobLevel(jobId)numberNiveau d'un metier

Route (Trajet)

Propiedad / MétodoTipoDescripción
bot.route(steps)voidLancer un trajet en boucle
bot.setBankRoute(steps)voidDefinir le trajet banque
bot.bankRoute(steps?)voidLancer le trajet banque
bot.stopRoute()voidArreter le trajet
bot.stopBankRoute()voidArreter le trajet banque

Evenements

Propiedad / MétodoTipoDescripción
mapChanged()Changement de map
fightStarted(info)Combat commence
fightEnded(result)Combat termine
turned(info)Debut d'un tour
actorsUpdated()Acteurs mis a jour
chatMessage(msg)Message chat recu
statsUpdated()Stats modifiees
inventoryUpdated()Inventaire modifie
dialogQuestion(info)Question PNJ
dialogClose()Dialogue ferme
exchangeOpen()Echange ouvert
exchangeClose()Echange ferme
levelUp(info)Level up

Utilitaires

Propiedad / MétodoTipoDescripción
sleep(seconds)voidPause en secondes (bloquant)
bot.sleep(ms)voidPause en ms (bloquant)
bot.log(message)voidLog dans la console
bot.printMessage(msg)voidAlias log
bot.printError(msg)voidLog [ERROR]
bot.printSuccess(msg)voidLog [SUCCESS]
bot.random(min, max)numberEntier aleatoire (inclusif)
bot.elapsedTime()numberMs depuis le debut du script
bot.uptime()numberSecondes depuis le debut
bot.getTime()numberTimestamp Unix (secondes)
bot.getTimeMs()numberTimestamp Unix (ms)
bot.afterFight()booleanVient de finir un combat (auto-clear)
bot.finishScript()voidArreter le script
bot.disconnect()voidDeconnecter le bot
bot.waitForMapChange(timeout?)stringAttend changement map

Memoire de session

Propiedad / MétodoTipoDescripción
bot.memorySet(key, value)voidStocker une valeur
bot.memoryGet(key)anyRecuperer une valeur
bot.memoryDelete(key)voidSupprimer une valeur
bot.memoryHas(key)booleanCle existe ?

Mort / Fantome / Phoenix

Propiedad / MétodoTipoDescripción
bot.isGhost()booleanLe bot est mort (energy=0 ou mode fantome)
bot.setPhoenixRoute(steps)voidDefinir la route phoenix (revive auto a la mort)
bot.getPhoenixRoute()table\nil | Route phoenix configuree
bot.findPhoenixCell()number\nil | Trouver la cellule phoenix sur la map actuelle

Regeneration

Propiedad / MétodoTipoDescripción
Propriete / MethodeTypeDescription
bot.isRegenerating()booleanRegen HP en cours (assis)
bot.waitForRegen(timeout?)voidAttendre la fin de la regen HP

Configuration Recolte

Propiedad / MétodoTipoDescripción
bot.setGatherList(list)voidRessources a recolter (noms)
bot.getGatherList()tableListe actuelle
bot.addGatherResource(name)voidAjouter une ressource
bot.removeGatherResource(name)voidRetirer une ressource
bot.setHarvestMode(mode)voidMode 'whitelist' ou autre

Anti-Aggro

Propiedad / MétodoTipoDescripción
bot.setAntiAggro(enabled, distance?)voidActiver/desactiver anti-aggro
bot.getAntiAggro()booleanAnti-aggro actif ?

Utilitaires avances

Propiedad / MétodoTipoDescripción
bot.getUID(templateId)string\nil | UID depuis un template ID
bot.getGID(uid)number\nil | Template ID depuis un UID
bot.accountTag()stringTag du compte
bot.accountId()stringID du compte
bot.isSubscribed()booleanAbonne ?
bot.reconnect()voidReconnexion
bot.interactiveObjects()tableObjets interactifs sur la map {{ cellId, gfxId }}
bot.getNpcIdOnCell(cellId)string\nil | ID du PNJ sur une cellule

Paquets bruts

Propiedad / MétodoTipoDescripción
bot.sendPacket(packet)voidEnvoyer un paquet brut
bot.onPacket(header, callback)voidEcouter un type de paquet

Duel / Challenge joueur

Propiedad / MétodoTipoDescripción
bot.challengePlayer(id)voidDefier un joueur en duel
bot.acceptChallenge(id?)voidAccepter un duel
bot.declineChallenge(id?)voidRefuser un duel
bot.cancelChallenge()voidAnnuler un duel envoye

Stats — Boost rapide

Propiedad / MétodoTipoDescripción
bot.UpgradeStrength(pts?)voidBoost force (+1 ou pts points)
bot.UpgradeVitality(pts?)voidBoost vitalite
bot.UpgradeWisdom(pts?)voidBoost sagesse
bot.UpgradeChance(pts?)voidBoost chance
bot.UpgradeAgility(pts?)voidBoost agilite
bot.UpgradeIntelligence(pts?)voidBoost intelligence

Items — Utilitaires

Propiedad / MétodoTipoDescripción
bot.itemWeight(templateId)numberPoids d'un item en pods
bot.getUID(templateId)string\nil | UID depuis template ID
bot.getGID(uid)number\nil | Template ID depuis UID

Abonnement

Propiedad / MétodoTipoDescripción
bot.isSubscribed()booleanCompte abonne ?
bot.subscriptionEndEpoch()numberDate fin abo (timestamp Unix)

Monture — Details avances

Propiedad / MétodoTipoDescripción
bot.getMountName()stringNom monture
bot.getMountLevel()numberNiveau monture
bot.getMountXp()numberXP monture
bot.getMountEnergy()numberEnergie monture
bot.getMountStamina()numberEndurance monture
bot.getMountLove()numberAmour monture
bot.getMountMaturity()numberMaturite monture
bot.getMountSerenity()numberSerenite monture
bot.getMountFecondation()numberFecondation monture
bot.setXpRatio(pct)voidAlias setMountXp
bot.toggleRiding()voidAlias toggleRide
bot.feed(itemUid, qty?)voidAlias feedMount
bot.rename(name)voidAlias renameMount

Metiers — Details

Propiedad / MétodoTipoDescripción
bot.jobName(jobId)stringNom du metier
bot.jobXp(jobId)numberXP du metier
bot.jobXpNext(jobId)numberXP pour le prochain niveau
bot.jobXpPercent(jobId)numberXP en % du niveau

Fichiers & Memoire

Propiedad / MétodoTipoDescripción
bot.fileExists(path)booleanFichier existe ?
bot.remember(key, value)voidAlias memory.set
bot.addInMemory(key, value)voidAjouter a la memoire
bot.editInMemory(key, value)voidModifier en memoire
bot.deleteMemory(key)voidAlias memory.delete

Presets d'equipement

Propiedad / MétodoTipoDescripción
bot.createPreset(name)voidCreer un preset
bot.equipPreset(name)voidEquiper un preset
bot.deletePreset(name)voidSupprimer un preset
bot.savePreset(name)voidSauvegarder le preset actuel

Dialogue — Details

Propiedad / MétodoTipoDescripción
bot.getQuestionText()stringTexte de la question PNJ
bot.getResponseTexts()tableTextes des reponses disponibles
bot.respond(index)voidAlias npcReply

Utilitaires — Alias

Propiedad / MétodoTipoDescripción
bot.delay(ms)voidAlias sleep
bot.sleep_ms(ms)voidAlias sleep
bot.send(packet)voidAlias sendPacket
bot.sendPM(name, msg)voidAlias whisper
bot.sendReply(index)voidAlias npcReply
bot.close()voidFermer dialogue/echange/banque
bot.leave()voidQuitter dialogue/echange/banque
bot.open()voidOuvrir (contexte dependant)
bot.count(templateId)numberAlias countItem
bot.list()tableAlias getInventory
bot.items()tableAlias getInventory
bot.npc()tableAlias getNpcs
bot.npcs()tableAlias getNpcs
bot.players()tableAlias getPlayers
bot.monsterGroups()tableAlias getMonsterGroups

Fonctions restantes — Alias et utilitaires

Propiedad / MétodoTipoDescripción
bot.getActors()tableTous les acteurs (monstres + joueurs + PNJ)
bot.getActorById(id)table\nil | Acteur par ID
bot.getSpell(spellId)table\nil | Donnees d'un sort
bot.upgradeSpell(spellId)voidAlias boostSpell
bot.xpNext()numberXP necessaire pour le prochain niveau
bot.clearGatherList()voidVider la liste de recolte
bot.getHarvestMode()stringMode recolte actuel
bot.setAntiAggroDefault(dist)voidDistance anti-aggro par defaut
bot.removeItem(uid, qty?)voidAlias deleteItem
bot.itemNameId(templateId)stringNom d'un item par template
bot.itemPods(templateId)numberPoids d'un item
bot.npcBank(cellId?)voidOuvrir banque via PNJ (alias openBank)
bot.combine()voidAlias craftCombine
bot.setQuantity(qty)voidAlias craftSetQuantity
bot.waitForResult(timeout?)table\nil | Alias craftWaitForResult
bot.enterMerchantMode()voidAlias requestMerchantMode
bot.isOpen()booleanInterface ouverte (banque/HDV/craft/echange)
bot.isActive()booleanBot actif
bot.isBoss()booleanEst leader du groupe
bot.isTypeAllowed(typeId)booleanType de monstre autorise par filtre
bot.accept()voidAccepter (echange/groupe/duel)
bot.refuse()voidRefuser (echange/groupe/duel)
bot.requestById(id)voidDemande echange par ID
bot.requestByName(name)voidAlias exchangeRequestByName
bot.SendReply(index)voidAlias npcReply
bot.mountFecondation()numberAlias getMountFecondation
bot.thisAccountController()tableControleur du compte actuel
bot.getVitalityBase()numberVitalite base
bot.getWisdomBase()numberSagesse base
bot.getStrengthBase()numberForce base
bot.getIntelligenceBase()numberIntelligence base
bot.getChanceBase()numberChance base
bot.getAgilityBase()numberAgilite base
bot.getTurnNumber()numberNumero du tour (getter)
bot.getCurrentFighterId()stringID du combattant actuel (getter)
bot.getTurnOrder()tableOrdre des tours (getter)

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.