A problem with my TribalWars2 script

04/10/2015 09:42 el_bengast#1
So I got this from somebody who gave it to our guild months ago,but it doesn't works properly anymore.

Code:
//timber_camp, headquarter, barracks, tavern, hospital, wall, statue (I don't know all of the ids)

window.build = ["warehouse", "farm","barracks"];
window.index = 0;

window.socketService = window.injector.get('socketService');
window.modelDataService = window.injector.get('modelDataService');
window.villageService = window.injector.get('villageService');
window.tribeService = window.injector.get('tribeService');

window.tradeListModelProvider = window.injector.get('tradeListModelProvider');
window.eventTypeProvider = window.injector.get('eventTypeProvider');
window.questLineListModelProvider = window.injector.get('questLineListModelProvider');
window.questLineModelProvider = window.injector.get('questLineModelProvider');
window.routeProvider = window.injector.get('routeProvider');

socketService.emit(routeProvider.GET_CHARACTER_VILLAGES, {}, function(villages){
    window.village_id = villages.villages[0].id;
    console.log(village_id);
});

setInterval(function() {
	socketService.emit(routeProvider.VILLAGE_UPGRADE_BUILDING, {building: build[index], village_id: village_id, location: "menu", premium: false}, function(data) {
		if(!data.error_code) {
			index++;
		}
	});
}, 20000);
The problem is when I put in the script the game gives a building queue is full error and then the script just goes to the next building in the index, causing after a minute to throw the invalid key for 'building': " (this means it has reached the end of the index, probably also should find a fix for that.) I'm not that good anymore with this like I was 1-2 years ago, I could write an else if and pickup that error and just make sure it doesn't goes to the next one, never really got into javascript. Thanks for the help already.