Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Careful when using this as it messes with and manages your inventory/equipment a bit,
- Duplicates mess with it a tad bit.
- */
- //Options
- var GoldThreshold = 20000;
- var SwapIfHigherRarity = true; //Currently not dynamic, this may get you killed if it swaps
- //Notifications
- var EnableSellNotifications = false;
- var EnableCraftingNotifications = true;
- var EnableChromeNotifications = {
- Crafting: false,
- Sell: false,
- };
- var IncludeColorsInNames = true;
- //Autoselling
- var SellIfRarityIsLowerThan = 0; //Set to 0 to disable
- //Storage Options
- var StoreEachType = true;
- //Crafting Options
- var EnableArmorCrafting = true;
- var EnableWeaponCrafting = true;
- var EnableCraftingGrinder = true;
- var RestrictToSameRarity = false;
- //Edit things below with caution
- //Variables
- var ActionTaken = false;
- var Equipment = character.equipment;
- var Inventory = ScriptAPI.$user.inventory.items;
- var Item = items[0];
- var ItemVsSlot;
- var PlayerGold = ScriptAPI.$user.money;
- //Slots (Assign as [inventory/equip,slotnumber,item]
- var ArmorToSubtype = {
- Helmet: "HEAD",
- Armor: "BODY",
- Leggings: "LEGS",
- };
- var Slots = {
- HEAD: null,
- BODY: null,
- LEGS: null,
- BOW: null,
- LARGE_SHIELD: null,
- SMALL_SHIELD: null,
- STAFF: null,
- SWORD: null,
- TWO_HANDED_SWORD: null,
- WAND: null,
- };
- var RarityColorFromNumber = ["Undefined","Gray","Green","Blue","Red","Orange"];
- //functions
- function craft(primary, consumed) {
- //Check if you can even craft
- if (primary.plus<(5+(5*primary.rarity)-1)) {
- API.inventory.craft(primary,consumed);
- //notify if enabled
- if (EnableCraftingNotifications) {
- API.notifications.create("Crafted a "+LocalizeItem(consumed)+" into your "+LocalizeItem(primary));
- if (EnableChromeNotifications.Crafting) {
- chromeNotify("Item successfully crafted!","Crafted a "+consumed.name+" into your "+primary.name+"+"+Math.floor(primary.plus));
- }
- }
- return true;
- }
- return false;
- }
- //To clean up later code
- function createSlotObject(_area,_slot,_item) {
- return {
- area: _area,
- slot: _slot,
- item: _item,
- };
- }
- //Thanks to FallenAdvent for pointing out that there is still access to chrome libraries for these scripts, and thanks for the snippet!
- function chromeNotify(Title,Message) {
- // Checks to see if Chrome is allowed to create notifications from this page
- if (Notification.permission !== "granted") {
- // No, Request Permission.
- Notification.requestPermission();
- } else {
- // Yes, Create Notification
- var n = new Notification(Title, {
- body: Message,
- });
- }
- }
- function LocalizeItem(i) {
- var localName = i.name+"+"+Math.floor(i.plus);
- if (IncludeColorsInNames) {
- return RarityColorFromNumber[i.rarity]+" "+localName;
- } else {
- return localName;
- }
- }
- function sell(i) {
- API.inventory.sell(i);
- //Notify if enabled
- if (EnableSellNotifications) {
- API.notifications.create("Sold a "+LocalizeItem(i));
- if (EnableChromeNotifications.Sell) {
- chromeNotify("Item sold!","Sold a "+LocalizeItem(i));
- }
- }
- }
- //Rarity based autosell, if it meets this exit the script
- if (Item.rarity<SellIfRarityIsLowerThan) {
- sell(Item);
- return;
- }
- //Find slots
- //Equips
- for (slotNum = 0; slotNum < Equipment.length; slotNum++) {
- //Check if it's a weapon
- if (Equipment[slotNum].subType!="ARMOR"){
- Slots[Equipment[slotNum].subType] = createSlotObject("Equip",slotNum,Equipment[slotNum]);
- } else { //if not assign armors
- Slots[ArmorToSubtype[Equipment[slotNum].name]] = createSlotObject("Equip",slotNum,Equipment[slotNum]);
- }
- }
- //Inventory (And if it's fully crafted while crafting grinder is on, sell it)
- for (slotNum = 0; slotNum < Inventory.length; slotNum++) {
- if (Inventory[slotNum].id != Item.id) {
- //if item is max level and crafting grinder is enabled, sell to open the slot
- if ((EnableCraftingGrinder) && (Inventory[slotNum].plus>=(5+(5*Inventory[slotNum].rarity)-1))) {
- sell(Inventory[slotNum]);
- } else {
- Slots[Inventory[slotNum].subType] = createSlotObject("Inventory",slotNum,Inventory[slotNum]);
- }
- }
- }
- //Assign VS Slot
- if (Item.subType!="ARMOR"){
- ItemVsSlot = Slots[Item.subType];
- } else {
- ItemVsSlot = Slots[ArmorToSubtype[Item.name]];
- }
- //Now actually do stuff with the new item
- //Check if a similar one is owned, if not: keep and exit
- if (StoreEachType) {
- //Check if it's a weapon
- if (Item.subType!="ARMOR"){
- if (Slots[Item.subType] == null){
- return;
- }
- } else {
- //If it's armor, and none is equipped, it'll be equipped
- if (Slots[ArmorToSubtype[Item.name]] == null){
- API.inventory.equip(Item);
- return;
- }
- }
- }
- //Swap here
- if (SwapIfHigherRarity) {
- if (Item.rarity>ItemVsSlot.item.rarity) {
- //Equip if needed
- if (ItemVsSlot.area == "Equip") {
- API.inventory.unequip(ItemVsSlot.item);
- API.inventory.equip(Item);
- }
- //if the old item's plus value is 0, swap and treat it as a dropped item for crafting/selling purposes, otherwise sell
- if (ItemVsSlot.item.plus==0) {
- var local = ItemVsSlot.item;
- ItemVsSlot.item = Item;
- Item = local;
- } else {
- sell(ItemVsSlot.item);
- return;
- }
- }
- }
- //Gold Threshold
- if (PlayerGold < GoldThreshold) {
- sell(Item);
- return;
- }
- //Craft
- if ((EnableWeaponCrafting && Item.subType!="ARMOR") || (EnableArmorCrafting && Item.subType=="ARMOR")) {
- //If crafting fails, sell it
- if (RestrictToSameRarity == false || (RestrictToSameRarity == true && Item.rarity == ItemVsSlot.item.rarity)) {
- if (!craft(ItemVsSlot.item,Item)) {
- sell(Item);
- return;
- } else {
- return;
- }
- }
- }
- //All else fails: sell
- sell(Item);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement