PDA

View Full Version : [Script] Wildcard Question



MadameNova
05-23-2019, 05:23 PM
I've been using the below script for CC, but now that I'm done, I'm thinking of using it for something else. (Anything else, depending on what I want.)

I was going to ask if any of you thought that it would pick up any nerkmid I found if I simply put the word in the "var items" section, but considering it wouldn't buy something that wasn't capitalized (unless that was when I had the price set wrong and didn't know it), I'm not so sure.

Ideas?


// ==UserScript==
// name Charity Corner - Auto Buy
// namespace [Only registered and activated users can see links]
[Only registered and activated users can see links]
// Description Auto Buy items that is below certain amount for Charity Corner '18
[Only registered and activated users can see links]
// Match [Only registered and activated users can see links]*
// Match [Only registered and activated users can see links]*

[Only registered and activated users can see links]
// ==/UserScript==

// NOTE:
// 1. SET 'xPrice' to any value that you would love to buy below
// 2. You may face some error, but that's normal, just click back to check,
// if there's anything else there to buy
// 3. If you want to set to buy things faster, you can change the minTO and maxTO
// to your desired value
// 4. If you want to buy things that is in within the list (Good to buy from a
// list of R102-179), you can change "searchWithin" to "true", and change the
// "items" list to your own list.

var xPrice = 3000;
var minTO = 1000;
var maxTO = 3000;
var searchWithin = true;
var showAlert = false;


var items = ["Ice Shield", "Poison Snowball Wand", "Yellow Sticky Hand", "Green Sticky Hand", "Tyrannian Skeith Plushie", "Chomby Rocket Belt", "Bruce Fish Slingshot", "GX-4 Oscillabot", "N-4 Info Retrieval Bot", "Ice Dagger"];

var arr = [];
var arrStr = [];
var totalItems = 0;
var totalNP = 0;
$('a[href*="buy_item.phtml"]').each(function() {
var str = $(this).attr("href");
var rex = /old_price=(.*?)\&feat/;
var matches = str.match(rex);
if (matches[1] <= xPrice) {
if (arrStr.indexOf(str) == -1) {
var stock = {};
stock.el = $(this);
stock.el.attr("onclick", "location.href=this.href;return false;");
stock.np = parseInt(matches[1]);
arrStr.push(str);
str = $(this).parent("td").html();
rex = /<\/b><br>(.*?)\ in stock/;
matches = str.match(rex);
stock.total = parseInt(matches[1]);

rex = /<\/a> <br> <b>(.*?)<\/b><br>/;
matches = str.match(rex);
var itemName = matches[1];
if ((searchWithin && items.indexOf(itemName) != -1) || !searchWithin) {
totalItems = totalItems + stock.total;
totalNP = totalNP + (stock.total * stock.np);
arr.push(stock);
}
}
}
});


function buy(idx) {
var timeout = Math.floor(Math.random() * (maxTO - minTO + 1) + minTO);
arr[idx].el.click();
if (arr[idx].total > 1) {
arr[idx].total--;
} else {
idx--;
}
if (idx >= 0) {
setTimeout(function() {
buy(idx);
}, timeout);
} else {
if (showAlert) {
alert("You have bought " + totalItems + " items with " + totalNP + " NP.");
}
}
}

if (arr.length > 0) {
buy(arr.length - 1);
}

j03
05-23-2019, 05:59 PM
I've been using the below script for CC, but now that I'm done, I'm thinking of using it for something else. (Anything else, depending on what I want.)

I was going to ask if any of you thought that it would pick up any nerkmid I found if I simply put the word in the "var items" section, but considering it wouldn't buy something that wasn't capitalized (unless that was when I had the price set wrong and didn't know it), I'm not so sure.

Ideas?


I briefly skimmed over the code... this auto-buys items from the shop wizard? If so, looks like the items variable is feeding the script what items to buy, and I think if you replace one of the items (well, you'd probably want to get rid of the cheap items and put the ones you want) with the nerkmids/whichever items you want to buy, it will do it. You'll have to change some of the limitations, if any, like the max NP to spend and increasing the delay.

MadameNova
05-23-2019, 10:03 PM
Sort of. You select the shops you want from the wizard, and once you're in the user's shop, it will go searching for whatever you ask it for. (It has cheap stuff listed right now because I just left in the r90+ stuff I was picking up to use with Odd's donator.)

So you think if I change the cap to 75k (or so) and put in nerkmid, it will work? What kind of timing increase should I consider?

Bat
05-23-2019, 10:17 PM
Yes - if you modify the list to search for specific Nerkmids that you want to buy and increase the maximum purchasing limit, the script should be able to buy them for you. I would recommend bumping up your delays to 2-4 seconds for safety's sake, and make sure to take breaks occasionally!

MadameNova
05-24-2019, 07:49 PM
Something I forgot to mention yesterday: I have no idea which string controls timing. (But a complete lack of pauses would explain why it occasionally errors out.)

Thank you for your help.

Bat
05-24-2019, 08:16 PM
The variables that control the script's time delays are maxTO and minTO, MadameNova. Here's an adjusted version of the script. I've modified the delay variables to 2-4 seconds, the maximum price to 75,000 NP and the target items to all of the nerkmids.


// ==UserScript==
// name Charity Corner - Auto Buy
// namespace [Only registered and activated users can see links]
[Only registered and activated users can see links]
// Description Auto Buy items that is below certain amount for Charity Corner '18
[Only registered and activated users can see links]
// Match [Only registered and activated users can see links]*
// Match [Only registered and activated users can see links]*

[Only registered and activated users can see links]
// ==/UserScript==

// NOTE:
// 1. SET 'xPrice' to any value that you would love to buy below
// 2. You may face some error, but that's normal, just click back to check,
// if there's anything else there to buy
// 3. If you want to set to buy things faster, you can change the minTO and maxTO
// to your desired value
// 4. If you want to buy things that is in within the list (Good to buy from a
// list of R102-179), you can change "searchWithin" to "true", and change the
// "items" list to your own list.

var xPrice = 75000;
var minTO = 2000;
var maxTO = 4000;
var searchWithin = true;
var showAlert = false;

var items = ["Aluminium Nerkmid", "Average Nerkmid", "Basic Golden Nerkmid", "Basic Platinum Nerkmid", "Copper Nerkmid", "Golden Nerkmid X", "Golden Nerkmid XX", "Good Nerkmid", "Lesser Nerkmid", "Magical Golden Nerkmid", "Magical Platinum Nerkmid", "Normal Golden Nerkmid", "Normal Platinum Nerkmid", "Platinum Nerkmid X", "Platinum Nerkmid XX", "Super Nerkmid", "Ultimate Nerkmid", "Ultra Golden Nerkmid", "Ultra Nerkmid", "Ultra Platinum Nerkmid"];

var arr = [];
var arrStr = [];
var totalItems = 0;
var totalNP = 0;
$('a[href*="buy_item.phtml"]').each(function() {
var str = $(this).attr("href");
var rex = /old_price=(.*?)\&feat/;
var matches = str.match(rex);
if (matches[1] <= xPrice) {
if (arrStr.indexOf(str) == -1) {
var stock = {};
stock.el = $(this);
stock.el.attr("onclick", "location.href=this.href;return false;");
stock.np = parseInt(matches[1]);
arrStr.push(str);
str = $(this).parent("td").html();
rex = /<\/b><br>(.*?)\ in stock/;
matches = str.match(rex);
stock.total = parseInt(matches[1]);

rex = /<\/a> <br> <b>(.*?)<\/b><br>/;
matches = str.match(rex);
var itemName = matches[1];
if ((searchWithin && items.indexOf(itemName) != -1) || !searchWithin) {
totalItems = totalItems + stock.total;
totalNP = totalNP + (stock.total * stock.np);
arr.push(stock);
}
}
}
});


function buy(idx) {
var timeout = Math.floor(Math.random() * (maxTO - minTO + 1) + minTO);
arr[idx].el.click();
if (arr[idx].total > 1) {
arr[idx].total--;
} else {
idx--;
}
if (idx >= 0) {
setTimeout(function() {
buy(idx);
}, timeout);
} else {
if (showAlert) {
alert("You have bought " + totalItems + " items with " + totalNP + " NP.");
}
}
}

if (arr.length > 0) {
buy(arr.length - 1);
}

MadameNova
05-24-2019, 09:20 PM
Oh my gosh, I thought min/max had to do with price! Wow, thank you for telling me about that...I almost feel embarrassed.

ETA: I adjusted the original for 2000-4000 and made yours a fresh copy entitled "nerkmid sniffer" so I wouldn't mess up your work. :)