Open necm1 opened 8 years ago
Take a look at this pull request. You'll find what you need in the example.js
@sebastianwachter thanks for that pull request, but it isn't complete. I'm just still getting errors like
TypeError: Cannot read property 'WildPokemon' of undefined or
for (var j = hb.cells[i].Fort.length - 1; j >= 0; j--) ^
TypeError: Cannot read property 'Fort' of undefined
and yes, I implemented the fully source of the pull request.
Hmm, This was working for me but now i am getting the following without my inventory being full.
GetFort(fort.FortId, fort.Latitude, fort.Longitude,
function(err, fortresponse) {
try {
console.log(fortresponse);
if (fortresponse.result == 1) {
....
Console log: [TypeError: Cannot read property 'result' of undefined]
@BlackRosie this appears to be a problem with the servers not sending the response in the "expected" time. To ensure stability you can do something like:
if (fortresponse) {
if (fortresponse.result == 1)
console.log('used');
}
So you basically check if the response came in time and if not just skip until the netxt tick.
Yep this is working again and it appears its because the servers are bogged down.
And @kylonx I had a similar issue with the code. I increased the tick rate of the interval from 5 seconds to 10 seconds and it doesn't appear anymore.
I've tried increasing the heartbeat rate to 10000 ms and the if fortresponse idea. Neither are working for me. Still
for (var j = hb.cells[i].Fort.length - 1; j >= 0; j--) ^
TypeError: Cannot read property 'Fort' of undefined
Maybe this snippet can help you:
api.Heartbeat(function (err, hb) {
var mapPokemon = [];
var nearbyPokemon = [];
var pokeStops = [];
if (err) {
console.log(err);
return callback({ nearbyPokemon : nearbyPokemon, mapPokemon : mapPokemon, pokeStops : pokeStops });
};
// NearbyPokemon
for (var i = hb.cells.length - 1; i >= 0; i--) {
if (hb.cells[i].NearbyPokemon[0]) {
var pokemon = api.pokemonlist[parseInt(hb.cells[i].NearbyPokemon[0].PokedexNumber) - 1];
nearbyPokemon.push(pokemon);
console.log('[+] There is a ' + pokemon.name + ' at ' + /*hb.cells[i].NearbyPokemon[0].DistanceMeters.toString() +*/ ' meters');
}
// Pokestops
for (var j = hb.cells[i].Fort.length - 1; j >= 0; j--) { // You should check if it is near enough to use!!
var fort = hb.cells[i].Fort[j];
// 0 = GYM, 1 = PokeStop
if (fort.FortType == 1 && fort.Enabled) {
pokeStops.push(fort);
}
}
}
...
});
And for collecting a pokestop (it needs to be <40m from your location):
api.GetFort(pokestop.FortId, pokestop.Latitude, pokestop.Longitude, function (err, fortresponse) {
if (fortresponse.result == 1) {
// 1 = success
// 2 = out of range ..
// 3 = used
console.log("[PS] Pokestop " + pokestop.FortId + " used. Items: " + fortresponse.items_awarded.length);
}
callback(fortresponse);
});
Hey guys! Is it possible to collect the PokeStops in nearby?