Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Farm Bot
- // @namespace narvikz
- // @description Bot de farm tribalwars
- // @include *://*screen=am_farm*
- // @version 1.0
- // @grant GM_getValue
- // @grant GM_setValue
- // ==/UserScript==
- var interval;
- var next_interval;
- function randomIntFromInterval(min,max)
- {
- return Math.floor(Math.random()*(max-min+1)+min);
- }
- function canSendA ()
- {
- var spears_A, swords_A, vikings_A, archers_A, scouts_A, lc_A, ma_A, hc_A, knight_A;
- spears_A = swords_A = vikings_A = archers_A = scouts_A = lc_A = ma_A = hc_A = knight_A = 0;
- if ($('td #archer').length > 0)
- {
- spears_A = $('#content_value form:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1) > input:nth-child(1)').val();
- swords_A = $('#content_value form:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(2) > input:nth-child(1)').val();
- vikings_A = $('#content_value form:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(3) > input:nth-child(1)').val();
- archers_A = $('#content_value form:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(4) > input:nth-child(1)').val();
- scouts_A = $('#content_value form:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(5) > input:nth-child(1)').val();
- lc_A = $('#content_value form:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(6) > input:nth-child(1)').val();
- ma_A = $('#content_value form:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(7) > input:nth-child(1)').val();
- hc_A = $('#content_value form:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(8) > input:nth-child(1)').val();
- knight_A = $('#content_value form:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(9) > input:nth-child(1)').val();
- }
- else
- {
- spears_A = $('#content_value form:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1) > input:nth-child(1)').val();
- swords_A = $('#content_value form:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(2) > input:nth-child(1)').val();
- vikings_A = $('#content_value form:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(3) > input:nth-child(1)').val();
- scouts_A = $('#content_value form:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(4) > input:nth-child(1)').val();
- lc_A = $('#content_value form:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(5) > input:nth-child(1)').val();
- hc_A = $('#content_value form:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(6) > input:nth-child(1)').val();
- knight_A = $('#content_value form:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(7) > input:nth-child(1)').val();
- }
- var spears = parseInt($('#spear').text());
- var swords = parseInt($('#sword').text());
- var vikings = parseInt($('#axe').text());
- var archers = parseInt($('#archer').text()) || 0;
- var scouts = parseInt($('#spy').text());
- var lc = parseInt($('#light').text());
- var ma = parseInt($('#marcher').text()) || 0;
- var hc = parseInt($('#heavy').text());
- var knight = parseInt($('#knight').text());
- if (spears >= spears_A && swords >= swords_A && vikings >= vikings_A && archers >= archers_A && scouts >= scouts_A && lc >= lc_A && ma >= ma_A && hc >= hc_A && knight >= knight_A)
- return true;
- else
- return false;
- }
- function canSendB ()
- {
- var spears_B, swords_B, vikings_B, archers_B, scouts_B, lc_B, ma_B, hc_B, knight_B;
- spears_B = swords_B = vikings_B = archers_B = scouts_B = lc_B = ma_B = hc_B = knight_B = 0;
- if ($('td #archer').length > 0)
- {
- spears_B = $('#content_value form:nth-child(2) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1) > input:nth-child(1)').val();
- swords_B = $('#content_value form:nth-child(2) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(2) > input:nth-child(1)').val();
- vikings_B = $('#content_value form:nth-child(2) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(3) > input:nth-child(1)').val();
- archers_B = $('#content_value form:nth-child(2) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(4) > input:nth-child(1)').val();
- scouts_B = $('#content_value form:nth-child(2) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(5) > input:nth-child(1)').val();
- lc_B = $('#content_value form:nth-child(2) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(6) > input:nth-child(1)').val();
- ma_B = $('#content_value form:nth-child(2) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(7) > input:nth-child(1)').val();
- hc_B = $('#content_value form:nth-child(2) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(8) > input:nth-child(1)').val();
- knight_B = $('#content_value form:nth-child(2) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(9) > input:nth-child(1)').val();
- }
- else
- {
- spears_B = $('#content_value form:nth-child(2) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1) > input:nth-child(1)').val();
- swords_B = $('#content_value form:nth-child(2) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(2) > input:nth-child(1)').val();
- vikings_B = $('#content_value form:nth-child(2) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(3) > input:nth-child(1)').val();
- scouts_B = $('#content_value form:nth-child(2) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(4) > input:nth-child(1)').val();
- lc_B = $('#content_value form:nth-child(2) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(5) > input:nth-child(1)').val();
- hc_B = $('#content_value form:nth-child(2) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(6) > input:nth-child(1)').val();
- knight_B = $('#content_value form:nth-child(2) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(7) > input:nth-child(1)').val();
- }
- var spears = parseInt($('#spear').text());
- var swords = parseInt($('#sword').text());
- var vikings = parseInt($('#axe').text());
- var archers = parseInt($('#archer').text()) || 0;
- var scouts = parseInt($('#spy').text());
- var lc = parseInt($('#light').text());
- var ma = parseInt($('#marcher').text()) || 0;
- var hc = parseInt($('#heavy').text());
- var knight = parseInt($('#knight').text());
- if (spears >= spears_B && swords >= swords_B && vikings >= vikings_B && archers >= archers_B && scouts >= scouts_B && lc >= lc_B && ma >= ma_B && hc >= hc_B && knight >= knight_B)
- return true;
- else
- return false;
- }
- function clickA()
- {
- var farmButtons = $('.farm_icon_a');
- for (i = 1; i < farmButtons.length; i++)
- {
- if (!farmButtons.eq(i).hasClass("farm_icon_disabled"))
- {
- farmButtons.eq(i).click();
- break;
- }
- }
- }
- function clickB()
- {
- var farmButtons = $('.farm_icon_b');
- for (i = 1; i < farmButtons.length; i++)
- {
- if (!farmButtons.eq(i).hasClass("farm_icon_disabled"))
- {
- farmButtons.eq(i).click();
- break;
- }
- }
- }
- function availableC()
- {
- return $('.farm_icon_c').length != $('.farm_icon_c.farm_icon_disabled').length;
- }
- function clickC()
- {
- var farmButtons = $('.farm_icon_c');
- for (i = 1; i < farmButtons.length; i++)
- {
- if (!farmButtons.eq(i).hasClass("farm_icon_disabled"))
- {
- farmButtons.eq(i).click();
- break;
- }
- }
- }
- function getError()
- {
- if ($('.autoHideBox.error').length > 0)
- return true;
- else
- return false;
- }
- function getSuccess()
- {
- if ($('.autoHideBox.success').length > 0)
- return true;
- else
- return false;
- }
- function gotoNext()
- {
- if ($('.arrowRight').length > 0)
- $('.arrowRight').click();
- if ($('.groupRight').length > 0)
- $('.groupRight').click();
- console.log('next');
- }
- function refresh()
- {
- location.reload();
- }
- function logic()
- {
- if (canSendA())
- {
- clickA();
- }
- /*else if (canSendB())
- {
- clickB();
- }*/
- /*
- if (!getError() && availableC())
- {
- clickC();
- }
- else
- {
- var villageName = $('#menu_row2_village').text().trim();
- clearInterval(interval);
- if (villageName == "004 | O terror personificado")
- {
- clearInterval(next_interval);
- next_interval = setInterval(gotoNext, randomIntFromInterval(5, 10) * 60 * 1000);
- }
- else
- {
- gotoNext();
- }
- }
- */
- }
- window.addEventListener('load', function() {
- interval = setInterval(logic, 300);
- }, false);
- //next_interval = setInterval(gotoNext, 15 * 1000);
- next_interval = setInterval(refresh, 15 * 1000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement