Advertisement
thommas

Battle INF Item Handler 3.3

Oct 17th, 2015
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**************************************************************************************************************************************************************************************************************/
  2. //      Battle INF item handler
  3. //      Author: Thommas
  4. //      version 3.3
  5. /**************************************************************************************************************************************************************************************************************/
  6. //User settings
  7. var die                 = 0;        //Items of this rarity and lower will be crafted together mindlessly and then sold                  0 to disable
  8. var beCareful               = 0;        //Items of this rarity will be crafted together with items of the same rarity and name/subclass     0 to disable
  9. var itsDangerousAlone           = 0;        //Items of this rarity will be crafted together with items of the same rarity and name/subclass     0 to disable
  10. var sellDezeNuts            = 0;        //Items of this rarity and lower will be sold if no other action is assigned to them                0 to disable
  11. var timeOut             = 5;        //Notification timeout. 5 is default
  12. var getOld              = 0;        //If 3, will attempt to age ALL items, inventory AND equipment. If 2, will attempt to age items equipped. If 1 will attempt to age ALL items in inventory. 0 to disable
  13. //Settings be done
  14. /**************************************************************************************************************************************************************************************************************/
  15.  
  16. //Functions start here
  17. //New item related functions
  18. //Grind new item with item in inventory. Both must be of equal or lower rarity than defined by variable die
  19. var grind = function(item)
  20. {
  21.     //Cycles through items in inventory
  22.     for (var i = 0; i < ScriptAPI.$user.inventory.items.length; i++)
  23.     {
  24.         //If current item matches requirements
  25.         if ((ScriptAPI.$user.inventory.items[i] != item) && (ScriptAPI.$user.inventory.items[i].rarity <= die) && !ScriptAPI.$user.inventory.items[i].lock)
  26.         {
  27.             //Then items will be grinded and notification
  28.             API.notifications.create("♺ " + ScriptAPI.$user.inventory.items[i].name + " ☆" + ScriptAPI.$user.inventory.items[i].rarity + " ↔ " + item.name + " ☆" + item.rarity + ".", timeOut);
  29.             ScriptAPI.$craftingService.craftItems(ScriptAPI.$user.inventory.items[i], item);
  30.             ScriptAPI.$userService.sellItem(ScriptAPI.$user.inventory.items[i]);
  31.             //Item has been processed. Script needs not run other new item related functions. By returning true, var done = true
  32.             return true;
  33.         }
  34.     }
  35. }
  36.  
  37. //Merge new item with item in inventory. Both must be of the same rarity and have the same name. E.g. Sword, or Armor
  38. var merge = function(item)
  39. {
  40.     //Cycles through items in inventory
  41.     for (var i = 0; i < ScriptAPI.$user.inventory.items.length; i++) //Cycles through items in inventory
  42.     {
  43.         //If current item matches requirements
  44.         if ((ScriptAPI.$user.inventory.items[i] != item) && (ScriptAPI.$user.inventory.items[i].rarity == item.rarity) && (ScriptAPI.$user.inventory.items[i].name == item.name) && (ScriptAPI.$user.inventory.items[i].plus + item.plus < (5*item.rarity+5)) && !ScriptAPI.$user.inventory.items[i].lock)
  45.         {
  46.             //Then items will be merged and notification. Note that time stampt is not required. Script is triggered by item drop, as such the new item will always be newer than the item selected in the inventory
  47.             API.notifications.create("✦ " + ScriptAPI.$user.inventory.items[i].name + "☆" + ScriptAPI.$user.inventory.items[i].rarity + "+" + ScriptAPI.$user.inventory.items[i].plus + " ↔ " + item.name + " ☆" + item.rarity + ".", timeOut);
  48.             ScriptAPI.$craftingService.craftItems(ScriptAPI.$user.inventory.items[i], item);
  49.             //Item has been processed. Script needs not run other new item related functions. By returning true, var done = true
  50.             return true;
  51.         }
  52.     }
  53. }
  54.  
  55. //Sells item
  56. var sell = function(item)
  57. {
  58.     //Sells item and notification
  59.     API.notifications.create("☄ " + item.name + " ☆" + item.rarity + ".", timeOut);
  60.     ScriptAPI.$userService.sellItem(item);
  61.     //Item has ben processed. Script needs not run other new item related functions. By returning true, var done = true
  62.     return true;
  63. }
  64.  
  65. //Triggered when no other new item related function was run
  66. var keep = function(item)
  67. {
  68.     //Notification
  69.     API.notifications.create("❤ " + item.name + " ☆" + item.rarity + ".", timeOut);
  70.     //With this, new item has been processed. This is the new item related function which runs last, returns true, new item handling is done
  71.     return true;
  72. }
  73. //New item related functions end
  74.  
  75. //Function which ages items
  76. var ageing = function(setting)
  77. {
  78.     //Determining what to do
  79.     //If setting 1 or 3, age ALL items in inventory
  80.     if (setting == 1 || setting == 3)
  81.     {
  82.         //Cycle through items in inventory
  83.         for (var i = 0; i < ScriptAPI.$user.inventory.items.length; i++)
  84.         {
  85.             //Ageing up item
  86.             ScriptAPI.$craftingService.ageUpItem(ScriptAPI.$user.inventory.items[i]);
  87.         }
  88.     }
  89.     //If setting 2 or 3, age items currently equipped
  90.     if (setting == 2 || setting == 3)
  91.     {
  92.         //Cycle through items currently equipped
  93.         for (var i = 0; i < ScriptAPI.$user.character.equipment.length; i++)
  94.         {
  95.             //Ageing up item
  96.             ScriptAPI.$craftingService.ageUpItem(ScriptAPI.$user.character.equipment[i]);
  97.         }
  98.     }
  99. }
  100. //No more functions
  101.  
  102. //Function triggers start here
  103. //Loops equal amount of items received, as such script can handle any amount of items
  104. for (var i = 0; i < items.length; i++)
  105. {
  106.    
  107.     //var newItemDone equals true when new item has been processed. No other new item related function will be run then
  108.     var newItemDone = false;
  109.     //Check if item meets requirements for grinding
  110.     if (items[i].rarity <= die) {
  111.         newItemDone = grind(items[i]); }
  112.     //Checks if item meets requirements for merging
  113.     if (!newItemDone && ((items[i].rarity == beCareful) || (items[i].rarity == itsDangerousAlone))) {
  114.         newItemDone = merge(items[i]); }
  115.     //Checks if item meets requirements for selling
  116.     if (!newItemDone && (items[i].rarity <= sellDezeNuts)) {
  117.         newItemDone = sell(items[i]); }
  118.     //If no function has been run, item will be kept
  119.     if (!newItemDone) {
  120.         newItemDone = keep(items[i]); }
  121.    
  122. }
  123. //Triggers item ageing function
  124. if (getOld > 0) {
  125.     ageing(getOld); }
  126. //No more function triggers
  127.  
  128.  
  129.  
  130. /*
  131. *****************************************************************Changelog*****************************************************************
  132.  
  133. Version 3.3
  134. Fixed attempt to merge/grind locked items
  135.  
  136. Version 3.2
  137. Added automagic item ageing
  138. Adjusted comments
  139. Note: Automagic ageing appears to be quite resource intensive. I myself experience a small stutter whenever it cycles through 80+ items.
  140.  
  141. Version 3.1:
  142. Added changelog
  143. Added notification timeout variable
  144.  
  145. *****************************************************************Changelog*****************************************************************
  146. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement