Advertisement
Patix0331

Margo(AutoTP): SI

Jan 25th, 2020
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Margo(AutoTP): SI
  3. // @version      1.0
  4. // @author       Patix0331
  5. // @match        http://*.margonem.pl/
  6. // ==/UserScript==
  7.  
  8. if (getCookie("interface") === "ni") {
  9.     return;
  10. }
  11. /**
  12.  * Ustawienia AutoTP
  13.  */
  14. const config = {
  15.     /**
  16.      * Dokładna nazwa teleportu który ma używać do uciekania.
  17.      */
  18.     teleportName: "Zwój na kwieciste przejście",
  19.     /**
  20.      * Różnica lvl od której ma uciekać (np. na postaci z 100 lvl ustawimy `lvl: 15` to bedzie uciekac od graczy z lvl 75 lub wyższym).
  21.      */
  22.     lvl: 15,
  23.     /**
  24.      * Jak blisko (w kratkach) musi znajdować się gracz żeby od niego uciekać. (na kordach x ORAZ y).
  25.      */
  26.     distance: 10,
  27.     /**
  28.      * Czy ma uciekac przed przyjaciółmi.
  29.      */
  30.     friends: false,
  31.     /**
  32.      * Czy ma uciekać przed klanowiczami.
  33.      */
  34.     clan: false,
  35.     /**
  36.      * Czy ma uciekać przed sojuszniczymi klanami.
  37.      */
  38.     allyClan: true,
  39.     /**
  40.      * Blacklista osób od których ma spierdalać mimo że są przyjaciółmi lub klanowiczami. Ignoruje lvl.
  41.      */
  42.     blacklist: ["Nick1", "Nick2"],
  43.     /**
  44.      * Whitelista osób od których ma nie spierdalac mimo tego ze nie są przyjaciółmi lub klanowiczami.
  45.      */
  46.     whitelist: ["Wrog1", "Wrog2"],
  47. }
  48.  
  49. /**
  50.  * Find item then use it.
  51.  * @param {string} itemName
  52.  */
  53. const useItem = itemName => {
  54.     const itemId = Object.keys(g.item).find(x => g.item[x].name === itemName && g.item[x] === "g");
  55.     if (!itemId) {
  56.         return console.log(`Nie znaleziono w torbie ${itemName}. Nie mogę ucieć od gracza.`);
  57.     }
  58.     return _g(`moveitem&st=1&id=${itemId}`);
  59. }
  60.  
  61. /**
  62.  * Return true if player fulfill the conditions from config and hero should get away.
  63.  * @param {object} player Object representation of player
  64.  */
  65. const checkIsNeedToGetAway = player => {
  66.     // jesli znajduje sie dalej od ciebie niz podana odleglosc
  67.     if (Math.sqrt(Math.pow(hero.x - player.x, 2) + Math.pow(hero.y - player.y, 2)) > distance) {
  68.         return false;
  69.     }
  70.     // Sprwadz czy znajduje się w blackliscie.
  71.     if (blacklist.includes(player.nick)) {
  72.         return true;
  73.     }
  74.     // jesli jest przyjacielem, klanowiczem lub sojusznikiem klanu, a w configu jest wyłączone uciekanie przed nimi.
  75.     if (!config.friends && player.relations === "fr"
  76.         || !config.clan && player.relations === "cl"
  77.         || !config.allyClan && player.relations === "cl-fr") {
  78.         return false;
  79.     }
  80.     // jesli jest w whiteliscie
  81.     if (config.whitelist.includes(player.nick)) {
  82.         return false;
  83.     }
  84.     // sprwadzenie poziomu
  85.     if (player.lvl < (hero.lvl - config.lvl)) {
  86.         return false;
  87.     }
  88.  
  89.     return true;
  90. }
  91.  
  92. const old = newOther;
  93. newOther = players => {
  94.     if (map.pvp !== 2) {
  95.         return old(players);
  96.     }
  97.     for (const id in players) {
  98.         // jesli nie istnieje w liscie graczy lub nie ma atrybutu z kordami
  99.         if (!player || !players[id].x) {
  100.             continue;
  101.         }
  102.         if (checkIsNeedToGetAway(g.other[id])) {
  103.             useItem(config.teleportName);
  104.         }
  105.     }
  106.     return old(players);
  107. }
  108.  
  109. g.loadQueue.push({
  110.     fun: () => {
  111.         if (map.pvp !== 2) {
  112.             return;
  113.         }
  114.         setInterval(() => {
  115.             for (const player of Object.values(g.other)) {
  116.                 if (!checkIsNeedToGetAway(player)) {
  117.                     continue;
  118.                 }
  119.  
  120.                 useItem(config.teleportName);
  121.             }
  122.         }, 500);
  123.     }
  124. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement