Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.60 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Farm Bot
  3. // @namespace narvikz
  4. // @description Bot de farm tribalwars
  5. // @include *://*screen=am_farm*
  6. // @version 1.0
  7. // @grant GM_getValue
  8. // @grant GM_setValue
  9. // ==/UserScript==
  10.  
  11. var interval;
  12. var next_interval;
  13.  
  14. function randomIntFromInterval(min,max)
  15. {
  16. return Math.floor(Math.random()*(max-min+1)+min);
  17. }
  18.  
  19. function canSendA ()
  20. {
  21. var spears_A, swords_A, vikings_A, archers_A, scouts_A, lc_A, ma_A, hc_A, knight_A;
  22. spears_A = swords_A = vikings_A = archers_A = scouts_A = lc_A = ma_A = hc_A = knight_A = 0;
  23.  
  24. if ($('td #archer').length > 0)
  25. {
  26. 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();
  27. 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();
  28. 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();
  29. 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();
  30. 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();
  31. 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();
  32. 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();
  33. 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();
  34. 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();
  35. }
  36. else
  37. {
  38. 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();
  39. 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();
  40. 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();
  41. 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();
  42. 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();
  43. 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();
  44. 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();
  45. }
  46.  
  47. var spears = parseInt($('#spear').text());
  48. var swords = parseInt($('#sword').text());
  49. var vikings = parseInt($('#axe').text());
  50. var archers = parseInt($('#archer').text()) || 0;
  51. var scouts = parseInt($('#spy').text());
  52. var lc = parseInt($('#light').text());
  53. var ma = parseInt($('#marcher').text()) || 0;
  54. var hc = parseInt($('#heavy').text());
  55. var knight = parseInt($('#knight').text());
  56.  
  57. 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)
  58. return true;
  59. else
  60. return false;
  61. }
  62.  
  63. function canSendB ()
  64. {
  65. var spears_B, swords_B, vikings_B, archers_B, scouts_B, lc_B, ma_B, hc_B, knight_B;
  66. spears_B = swords_B = vikings_B = archers_B = scouts_B = lc_B = ma_B = hc_B = knight_B = 0;
  67.  
  68. if ($('td #archer').length > 0)
  69. {
  70. 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();
  71. 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();
  72. 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();
  73. 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();
  74. 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();
  75. 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();
  76. 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();
  77. 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();
  78. 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();
  79. }
  80. else
  81. {
  82. 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();
  83. 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();
  84. 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();
  85. 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();
  86. 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();
  87. 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();
  88. 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();
  89. }
  90.  
  91. var spears = parseInt($('#spear').text());
  92. var swords = parseInt($('#sword').text());
  93. var vikings = parseInt($('#axe').text());
  94. var archers = parseInt($('#archer').text()) || 0;
  95. var scouts = parseInt($('#spy').text());
  96. var lc = parseInt($('#light').text());
  97. var ma = parseInt($('#marcher').text()) || 0;
  98. var hc = parseInt($('#heavy').text());
  99. var knight = parseInt($('#knight').text());
  100.  
  101. 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)
  102. return true;
  103. else
  104. return false;
  105. }
  106.  
  107. function clickA()
  108. {
  109. var farmButtons = $('.farm_icon_a');
  110.  
  111. for (i = 1; i < farmButtons.length; i++)
  112. {
  113. if (!farmButtons.eq(i).hasClass("farm_icon_disabled"))
  114. {
  115. farmButtons.eq(i).click();
  116. break;
  117. }
  118. }
  119. }
  120.  
  121. function clickB()
  122. {
  123. var farmButtons = $('.farm_icon_b');
  124.  
  125. for (i = 1; i < farmButtons.length; i++)
  126. {
  127. if (!farmButtons.eq(i).hasClass("farm_icon_disabled"))
  128. {
  129. farmButtons.eq(i).click();
  130. break;
  131. }
  132. }
  133. }
  134.  
  135. function availableC()
  136. {
  137. return $('.farm_icon_c').length != $('.farm_icon_c.farm_icon_disabled').length;
  138. }
  139.  
  140. function clickC()
  141. {
  142. var farmButtons = $('.farm_icon_c');
  143.  
  144. for (i = 1; i < farmButtons.length; i++)
  145. {
  146. if (!farmButtons.eq(i).hasClass("farm_icon_disabled"))
  147. {
  148. farmButtons.eq(i).click();
  149. break;
  150. }
  151. }
  152. }
  153.  
  154. function getError()
  155. {
  156. if ($('.autoHideBox.error').length > 0)
  157. return true;
  158. else
  159. return false;
  160. }
  161.  
  162. function getSuccess()
  163. {
  164. if ($('.autoHideBox.success').length > 0)
  165. return true;
  166. else
  167. return false;
  168. }
  169.  
  170. function gotoNext()
  171. {
  172. if ($('.arrowRight').length > 0)
  173. $('.arrowRight').click();
  174. if ($('.groupRight').length > 0)
  175. $('.groupRight').click();
  176.  
  177. console.log('next');
  178. }
  179.  
  180. function refresh()
  181. {
  182. location.reload();
  183. }
  184.  
  185. function logic()
  186. {
  187. if (canSendA())
  188. {
  189. clickA();
  190. }
  191. /*else if (canSendB())
  192. {
  193. clickB();
  194. }*/
  195. /*
  196. if (!getError() && availableC())
  197. {
  198. clickC();
  199. }
  200. else
  201. {
  202. var villageName = $('#menu_row2_village').text().trim();
  203. clearInterval(interval);
  204.  
  205. if (villageName == "004 | O terror personificado")
  206. {
  207. clearInterval(next_interval);
  208. next_interval = setInterval(gotoNext, randomIntFromInterval(5, 10) * 60 * 1000);
  209. }
  210. else
  211. {
  212. gotoNext();
  213. }
  214. }
  215. */
  216. }
  217.  
  218. window.addEventListener('load', function() {
  219. interval = setInterval(logic, 300);
  220. }, false);
  221.  
  222. //next_interval = setInterval(gotoNext, 15 * 1000);
  223. next_interval = setInterval(refresh, 15 * 1000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement