Armax / Pokemon-GO-node-api

Pokemon GO api node.js library
MIT License
875 stars 198 forks source link

Impossible to catch pokemon #245

Open davidmottet opened 8 years ago

davidmottet commented 8 years ago

I have this message when i try to catch pokemon Encountering pokemon Psyduck... Encountering pokemon Rhyhorn... Encountering pokemon Magikarp... Encountering pokemon Exeggcute... { Status: null, MissPercent: null, CapturedPokemonId: null, CaptureAward: null } undefined undefined undefined

Can you help me?

monarchfish commented 8 years ago

let me see your code

davidmottet commented 8 years ago

It's the same with exemple code :/

monarchfish commented 8 years ago

I think maybe it's goes too fast. you need to make some delay between every EncounterPokemon and CatchPokemon.

davidmottet commented 8 years ago

Same results

[+] There is a Magikarp near!! I can try to catch it!
[+] There is a Eevee near!! I can try to catch it!
[+] There is a Magikarp near!! I can try to catch it!
[+] There is a Rattata near!! I can try to catch it!
[+] There is a Magikarp near!! I can try to catch it!
Encountering pokemon Magikarp...
{ Status: null,
  MissPercent: null,
  CapturedPokemonId: null,
  CaptureAward: null }

To do that when there are pokemons catchable I engage one by one

monarchfish commented 8 years ago

I think is the same problem, how do you put your delay between them?

ameyer commented 8 years ago

Basically you have to wait for your API call to complete before you do another. So in the for loop looking for catchable pokemon, I exit the loop (either return or break) when I find one so it wont go on to the next one until the next heartbeat.

Something like this (I striped out a ton of code for this so I don't know if this works on its own)

function heartbeat(){
    pokeAPI.Heartbeat(function(err,hb) {

        //Find catchable pokemon & catch them if we can
        for (i = hb.cells.length - 1; i >= 0; i--) {
            for (var j = hb.cells[i].MapPokemon.length - 1; j >= 0; j--){
                var currentPokemon = hb.cells[i].MapPokemon[j];
                //found one we can get, GET IT!
                getCurrentPokemon(currentPokemon);
                return;
            }
        }
    });
}

function getCurrentPokemon(currentPokemon){
    pokeAPI.EncounterPokemon(currentPokemon, function(suc, dat) {

        normalized_reticle_size = 1.95;
        spin_modifier = 1;
        normalized_hit_position = 1;
        pokeBallType = 1;

        //throw the ball
        pokeAPI.CatchPokemon(currentPokemon, normalized_hit_position, normalized_reticle_size, spin_modifier, pokeBallType.id, function(err, result) {
            var status = ['Unexpected error', 'SUCCESSFUL CATCH !!!', 'Catch Escape', 'Catch Flee', 'Missed Catch'];                
            console.log(status[result.Status]);             
        });
    }); 

}
rudemex commented 8 years ago

sorry, my englis is not very good... i write in spanish.

cree una variable global

var isCatch = false;

y lo que hago es verificar si estoy atrapando uno, que no atrape otro. utilizando un simple IF

a.EncounterPokemon(currentPokemon, function(suc, dat) { if(!isCatch){ isCatch = true; console.log('Encountering pokemon ' + pokedexInfo.name + '...'); a.CatchPokemon(currentPokemon, 1, 1.950, 1, 1, function(xsuc, xdat) { var status = [ 'Unexpected error', 'Successful catch', 'Catch Escape', 'Catch Flee', 'Missed Catch' ]; isCatch = false; console.log(status[xdat.Status]); //console.log(xdat.Status); }); } });