zarqon
Well-known member
I'm working on an item trading script for my clan (we're building a clan treasurer, kind of like a bot to replace the stash) and looked in vain for a quick way to access whether or not an item is tradeable. I did something like this, accessing mafia's tradeitems.txt file:
But it's quite bulky and fairly slow since it foreaches through a map of records which numbers well over 2000. It seems like an ash function buffer get_item_desc(item) which returns the HTML of the popup item description would be pretty awesome. Or since most of that pertinent information is already available via other ASH functions, how about a boolean is_tradeable(item)? And for thoroughness' sake, possibly a boolean is_discardable(item), although I'm not sure what practical use that has.
I'd be grateful to anyone who can improve my is_tradeable() or point out that this functionality already exists somewhere. Or, if not, I'd be very grateful if someone deems it worthy to add to ASH.
Code:
print("Loading item list...");
record m_item {
string name; // item name
int something; // no idea
string use; // item type (possible: all, display, gift, none (=quest))
int autosell; // listed autosell price
};
m_item[int] itemlist;
if (!file_to_map("tradeitems.txt", itemlist)) {
print("Unable to load item list. Updating...");
cli_execute("update");
abort("We at the Society of Recommending Things recommend that you restart mafia and try this script again.");
}
if (count(itemlist) == 0) abort("Sorry, but tradeitems.txt is corrupt or empty or somesuch.");
print(count(itemlist)+" items loaded.");
m_item blank_item() {
m_item result; return result;
}
m_item find_item(item which) {
string s = to_string(which);
foreach i in itemlist
if (itemlist[i].name == s) return itemlist[i];
return blank_item();
}
m_item find_item(string which) { return find_item(to_item(which)); }
boolean is_tradeable(m_item which) {
return (which.use == "all" || which.use == "gift");
}
boolean is_tradeable(item which) { return is_tradeable(find_item(which)); }
But it's quite bulky and fairly slow since it foreaches through a map of records which numbers well over 2000. It seems like an ash function buffer get_item_desc(item) which returns the HTML of the popup item description would be pretty awesome. Or since most of that pertinent information is already available via other ASH functions, how about a boolean is_tradeable(item)? And for thoroughness' sake, possibly a boolean is_discardable(item), although I'm not sure what practical use that has.
I'd be grateful to anyone who can improve my is_tradeable() or point out that this functionality already exists somewhere. Or, if not, I'd be very grateful if someone deems it worthy to add to ASH.