[Client Scripting] Random Bot Fail

Discussion in 'Server and Client Scripting' started by Onters, Jan 10, 2015.

  1. Onters

    Onters New Member

    Joined:
    Jan 7, 2015
    Messages:
    3
    Likes Received:
    1
    [​IMG]
    Random Bot
    var useAI=true;

    var channel = 0;

    var nick = function(spot) { return battle.data.field.poke(spot).pokemon.nick; };
    var verb = false;
    var send = function(msg) {
    if (!verb) /*print (msg)*/;
    else client.network().sendChanMessage(channel, msg);
    };

    var poke = function(spot) { return battle.data.team(spot).poke(0);};
    var fpoke = function(spot) { return battle.data.field.poke(spot);};
    var tpoke = function(ind) { return battle.data.team(battle.me).poke(ind);};

    ({
    onBeginTurn : function(turn) {
    send("Turn " + turn + " of the battle!");
    },
    onKo : function(spot) {
    send("Oh no! " + nick(spot) + " fainted!");
    },
    onDamageDone: function(spot, damage) {
    if (spot == battle.me) {
    send(":(( My " + nick(spot) + " lost " + damage + " HP!");
    } else {
    send(nick(spot) + " lost " + damage + "% ;D !");
    }
    },
    onChoiceSelection: function(player) {
    if (player!=battle.me || !useAI) {
    return;
    }
    var switches = [];
    for (var i = 1; i < 6; i++) {
    if (!tpoke(i).isKoed()) {
    switches.push(i);
    }
    }

    var r = sys.rand(0, 8);

    if (r == 0 || (fpoke(battle.me).onTheField && !poke(battle.me).isKoed() && (r != 1 || switches.length == 0))) {
    choice = {"slot": battle.me, "type":"attack", "attackSlot":sys.rand(0,4)};
    } else {
    var cswitch = switches[sys.rand(0,switches.length)];

    choice = {"slot": battle.me, "type":"switch", "pokeSlot": cswitch};
    }
    battle.battleCommand(battle.id, choice);
    },
    onChoiceCancellation: function(player) {
    this.onChoiceSelection(player);
    },
    onDrawRequest: function (player) {
    this.onChoiceCancelled(player);
    },
    onChoiceCancelled: function(player) {
    // print ("old useAI: " + useAI);
    useAI = !useAI;
    print ("new useAI: " + useAI);
    }
    ,
    onPlayerMessage: function(player, message) {
    if (player == battle.me) {
    if (message == "annoy") {
    verb = true;
    } else if (message == "debug") {
    verb = false;
    } else if (message.substr(0, 5) == "eval ") {
    sys.eval(message.substr(5));
    }
    }
    }
    })
    How do I make it work? Help
     
    Pumone likes this.
  2. Nightfall Alicorn

    Nightfall Alicorn Left Pokémon Online, most likely not coming back.

    Joined:
    Oct 15, 2013
    Messages:
    491
    Likes Received:
    171
    PO Trainer Name:
    Nightmare Moon
    If it's the script I think it is, did you paste it in the battle script window?

    I think 1 or 2 scripts had problems on the github page for battle what I've found. Make sure you copied all the code in the window as well. If I recall reading about it, the auto battle bot only has limited intelligence and selects random moves.

    I'm not very good at battle scripting I'm afraid. I can only do a bit. Sorry I'm not much more help. I'm more familiar with client scripts.
     
  3. Pumone

    Pumone Member

    Joined:
    Aug 30, 2015
    Messages:
    63
    Likes Received:
    14
    I'm not here to help you I'm sorry.

    The idea of a battling bot is simple to think but hard to make true.

    It seems that this bot you reported is working fine, but I wonder if I can battle it without using 2 different IP. I tried by opening 2 windows but the result is bot Vs bot and I can just watch the battle...any solutions?
     
  4. RedJoker25

    RedJoker25 Resident Lurker Server Moderator Article Contributor Server Moderator Article Contributor

    Joined:
    Apr 5, 2011
    Messages:
    269
    Likes Received:
    54
    PO Trainer Name:
    RedJoker25
    try replacing "if (player!=battle.me || !useAI)" with "if (client.ownName() !== "botname" || !useAI)"
     
  5. Nightfall Alicorn

    Nightfall Alicorn Left Pokémon Online, most likely not coming back.

    Joined:
    Oct 15, 2013
    Messages:
    491
    Likes Received:
    171
    PO Trainer Name:
    Nightmare Moon
    Maybe try adding this at top with your name in the quotes under "var useAI=true;" part.
    Code (JavaScript):
    1. if (client.ownName() === "You Name Here") {
    2.     var useAI = false;
    3. }
     
  6. Pumone

    Pumone Member

    Joined:
    Aug 30, 2015
    Messages:
    63
    Likes Received:
    14
    Thank you both for help, I tried every solution you gave me but with no results.

    The problem is that when I open 2 windows I can only do 2 things:

    1) me vs me
    2) bot vs bot

    The final result would be me vs bot, but I can't figure how to make the code to properly work.
     
  7. Nightfall Alicorn

    Nightfall Alicorn Left Pokémon Online, most likely not coming back.

    Joined:
    Oct 15, 2013
    Messages:
    491
    Likes Received:
    171
    PO Trainer Name:
    Nightmare Moon
    You could, for now. Open 1 window, login, load the battle script, then open a second tab (CTRL+T), log in, then remove code in the second tab then battle yourself.

    It's a bug with PO where only newest tabs update the script functionality.
     
  8. Strudels

    Strudels ・◡・ Super Moderator Server Administrator Super Moderator Server Administrator

    Joined:
    Oct 31, 2013
    Messages:
    322
    Likes Received:
    1,104
    PO Trainer Name:
    Strudels/Ripper Roo
    I'm not sure what you did though because it works fine for me.

    Did you place this

    if (client.ownName() === "yournamehere") {
    var useAI = false;
    }

    after this?

    var useAI = true;

    If you didn't it won't work.
     
    Nightfall Alicorn and Pumone like this.
  9. Pumone

    Pumone Member

    Joined:
    Aug 30, 2015
    Messages:
    63
    Likes Received:
    14

    Ohhh yes! It works fine now!! I was wrong by putting the code BEFORE var useAI = true;

    Thank you so much, now it works =)
     
    Nightfall Alicorn and Strudels like this.