Advertisement
bombpaw

LootScript

Jul 1st, 2015
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     Careful when using this as it messes with and manages your inventory/equipment a bit,
  3.     Duplicates mess with it a tad bit.
  4.  
  5.  
  6. */
  7.  
  8. //Options
  9. var GoldThreshold = 20000;
  10.  
  11. var SwapIfHigherRarity = true; //Currently not dynamic, this may get you killed if it swaps
  12.  
  13.  
  14.     //Notifications
  15. var EnableSellNotifications = false;
  16. var EnableCraftingNotifications = true;
  17. var EnableChromeNotifications = {
  18.     Crafting: false,
  19.     Sell: false,
  20. };
  21.  
  22. var IncludeColorsInNames = true;
  23.  
  24.  
  25.     //Autoselling
  26. var SellIfRarityIsLowerThan = 0; //Set to 0 to disable
  27.  
  28.     //Storage Options
  29. var StoreEachType = true;
  30.  
  31.  
  32.     //Crafting Options
  33. var EnableArmorCrafting = true;
  34. var EnableWeaponCrafting = true;
  35.  
  36. var EnableCraftingGrinder = true;
  37.  
  38. var RestrictToSameRarity = false;
  39.  
  40.  
  41.  
  42. //Edit things below with caution
  43.  
  44.  
  45. //Variables
  46. var ActionTaken = false;
  47. var Equipment = character.equipment;
  48. var Inventory = ScriptAPI.$user.inventory.items;
  49. var Item = items[0];
  50. var ItemVsSlot;
  51. var PlayerGold = ScriptAPI.$user.money;
  52.  
  53.  
  54. //Slots (Assign as [inventory/equip,slotnumber,item]
  55.  
  56. var ArmorToSubtype = {
  57.     Helmet: "HEAD",
  58.     Armor: "BODY",
  59.     Leggings: "LEGS",
  60. }; 
  61.  
  62.  
  63. var Slots = {
  64.     HEAD: null,
  65.     BODY: null,
  66.     LEGS: null,
  67.    
  68.     BOW: null,
  69.     LARGE_SHIELD: null,
  70.     SMALL_SHIELD: null,
  71.     STAFF: null,
  72.     SWORD: null,
  73.     TWO_HANDED_SWORD: null,
  74.     WAND: null,
  75. };
  76.  
  77. var RarityColorFromNumber = ["Undefined","Gray","Green","Blue","Red","Orange"];
  78.  
  79.  
  80.  
  81. //functions
  82.  
  83.  
  84.  
  85. function craft(primary, consumed) {
  86.     //Check if you can even craft
  87.     if (primary.plus<(5+(5*primary.rarity)-1)) {
  88.         API.inventory.craft(primary,consumed);
  89.        
  90.         //notify if enabled
  91.         if (EnableCraftingNotifications) {
  92.             API.notifications.create("Crafted a "+LocalizeItem(consumed)+" into your "+LocalizeItem(primary));
  93.             if (EnableChromeNotifications.Crafting) {
  94.                 chromeNotify("Item successfully crafted!","Crafted a "+consumed.name+" into your "+primary.name+"+"+Math.floor(primary.plus));
  95.             }
  96.         }
  97.         return true;
  98.     }
  99.     return false;
  100. }
  101.  
  102. //To clean up later code
  103. function createSlotObject(_area,_slot,_item) {
  104.     return {
  105.         area: _area,
  106.         slot: _slot,
  107.         item: _item,
  108.     };
  109. }
  110.  
  111. //Thanks to FallenAdvent for pointing out that there is still access to chrome libraries for these scripts, and thanks for the snippet!
  112. function chromeNotify(Title,Message) {
  113.     // Checks to see if Chrome is allowed to create notifications from this page
  114.     if (Notification.permission !== "granted") {
  115.         // No, Request Permission.
  116.         Notification.requestPermission();
  117.     } else {
  118.         // Yes, Create Notification
  119.         var n = new Notification(Title, {
  120.              body: Message,
  121.         });
  122.     }
  123. }
  124.  
  125. function LocalizeItem(i) {
  126.     var localName = i.name+"+"+Math.floor(i.plus);
  127.     if (IncludeColorsInNames) {
  128.         return RarityColorFromNumber[i.rarity]+" "+localName;
  129.     } else {
  130.         return localName;
  131.     }
  132. }
  133.  
  134. function sell(i) {
  135.     API.inventory.sell(i);
  136.    
  137.     //Notify if enabled
  138.     if (EnableSellNotifications) {
  139.             API.notifications.create("Sold a "+LocalizeItem(i));
  140.             if (EnableChromeNotifications.Sell) {
  141.                 chromeNotify("Item sold!","Sold a "+LocalizeItem(i));
  142.             }
  143.     }
  144. }
  145.  
  146.  
  147.  
  148. //Rarity based autosell, if it meets this exit the script
  149. if (Item.rarity<SellIfRarityIsLowerThan) {
  150.     sell(Item);
  151.     return;
  152. }
  153.  
  154.  
  155.  
  156. //Find slots
  157.     //Equips
  158. for (slotNum = 0; slotNum < Equipment.length; slotNum++) {
  159.     //Check if it's a weapon
  160.     if (Equipment[slotNum].subType!="ARMOR"){
  161.         Slots[Equipment[slotNum].subType] = createSlotObject("Equip",slotNum,Equipment[slotNum]);
  162.  
  163.     } else { //if not assign armors
  164.         Slots[ArmorToSubtype[Equipment[slotNum].name]] = createSlotObject("Equip",slotNum,Equipment[slotNum]);
  165.     }
  166.  
  167. }
  168.  
  169.     //Inventory (And if it's fully crafted while crafting grinder is on, sell it)
  170. for (slotNum = 0; slotNum < Inventory.length; slotNum++) {
  171.     if (Inventory[slotNum].id != Item.id) {
  172.         //if item is max level and crafting grinder is enabled, sell to open the slot
  173.         if ((EnableCraftingGrinder) && (Inventory[slotNum].plus>=(5+(5*Inventory[slotNum].rarity)-1))) {
  174.             sell(Inventory[slotNum]);
  175.         } else {
  176.             Slots[Inventory[slotNum].subType] = createSlotObject("Inventory",slotNum,Inventory[slotNum]);
  177.         }
  178.     }
  179. }
  180.  
  181.     //Assign VS Slot
  182. if (Item.subType!="ARMOR"){
  183.     ItemVsSlot = Slots[Item.subType];
  184. } else {
  185.     ItemVsSlot = Slots[ArmorToSubtype[Item.name]];
  186. }
  187.  
  188.  
  189. //Now actually do stuff with the new item
  190.  
  191.  
  192. //Check if a similar one is owned, if not: keep and exit
  193.  
  194. if (StoreEachType) {
  195.     //Check if it's a weapon
  196.     if (Item.subType!="ARMOR"){
  197.         if (Slots[Item.subType] == null){
  198.             return;
  199.         }
  200.     } else {
  201.         //If it's armor, and none is equipped, it'll be equipped
  202.         if (Slots[ArmorToSubtype[Item.name]] == null){
  203.             API.inventory.equip(Item);
  204.             return;
  205.         }
  206.     }
  207. }
  208.  
  209. //Swap here
  210.  
  211.  if (SwapIfHigherRarity) {
  212.      if (Item.rarity>ItemVsSlot.item.rarity) {
  213.         //Equip if needed
  214.         if (ItemVsSlot.area == "Equip") {
  215.             API.inventory.unequip(ItemVsSlot.item);
  216.             API.inventory.equip(Item);
  217.         }
  218.      
  219.         //if the old item's plus value is 0, swap and treat it as a dropped item for crafting/selling purposes, otherwise sell
  220.         if (ItemVsSlot.item.plus==0) {
  221.             var local = ItemVsSlot.item;
  222.             ItemVsSlot.item = Item;
  223.             Item = local;
  224.         } else {
  225.             sell(ItemVsSlot.item);
  226.             return;
  227.         }
  228.      }
  229. }
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236. //Gold Threshold
  237. if (PlayerGold < GoldThreshold) {
  238.     sell(Item);
  239.     return;
  240. }
  241.  
  242.  
  243. //Craft
  244.  
  245. if ((EnableWeaponCrafting && Item.subType!="ARMOR") || (EnableArmorCrafting && Item.subType=="ARMOR")) {
  246.     //If crafting fails, sell it
  247.     if (RestrictToSameRarity == false || (RestrictToSameRarity == true  && Item.rarity == ItemVsSlot.item.rarity)) {
  248.         if (!craft(ItemVsSlot.item,Item)) {
  249.             sell(Item);
  250.             return;
  251.         } else {
  252.             return;
  253.         }
  254.     }
  255. }
  256.  
  257. //All else fails: sell
  258. sell(Item);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement