StoreKeeper
New member
Is there any function/script to return the current price of an item I have in my own mall store? I went looking for it and have not found anything that will return my store's price.
int ShopPrice(item Widget)
{
matcher shopmatch;
//matcher for single
shopmatch = create_matcher( "<td>"+widget+"</td><td>(.+?)<" ,storecache );
if (shopmatch.find()) return shopmatch.group(1).to_int();
//matcher for multiple
shopmatch = create_matcher( "<td>"+widget+" \\((\\d+)\\)</td><td>(.+?)<" ,storecache );
if (shopmatch.find()) return shopmatch.group(2).to_int();
//matcher for multiple at limit
//shopmatch = create_matcher( "<td>"+widget+" \\((\\d+)\\)</td><td>(.+?)</td><td>(\\d+)</td>" ,storecache );
//if (shopmatch.find()) return shopmatch.group(2).to_int();
return 0;
}
record shopinfo
{
int amount;
int price;
int limit;
};
string storecache= visit_url("managestore.php");
storecache=substring(storecache,index_of(storecache,"Store Inventory:")+202);
int ShopPrice(item Widget)
{
matcher shopmatch;
//matcher for single
shopmatch = create_matcher( "<td>"+widget+"</td><td>(.+?)<" ,storecache );
if (shopmatch.find()) return shopmatch.group(1).to_int();
//matcher for multiple
shopmatch = create_matcher( "<td>"+widget+" \\((\\d+)\\)</td><td>(.+?)<" ,storecache );
if (shopmatch.find()) return shopmatch.group(2).to_int();
//matcher for multiple at limit
//shopmatch = create_matcher( "<td>"+widget+" \\((\\d+)\\)</td><td>(.+?)</td><td>(\\d+)</td>" ,storecache );
//if (shopmatch.find()) return shopmatch.group(2).to_int();
return 0;
}
shopinfo ShopInfo(item Widget)
{
shopinfo thingy;
matcher shopmatch;
//match single
shopmatch = create_matcher( "<td>"+widget+"</td><td>(.+?)<" ,storecache );
if (shopmatch.find())
{
thingy.amount=1;
thingy.price=shopmatch.group(1).to_int();
thingy.limit=0;
return thingy;
}
//match multiple
shopmatch = create_matcher( "<td>"+widget+" \\((\\d+)\\)</td><td>(.+?)<" ,storecache );
if (shopmatch.find())
{
thingy.amount=shopmatch.group(1).to_int();
thingy.price=shopmatch.group(2).to_int();
thingy.limit=0;
return thingy;
}
//match limit
//shopmatch = create_matcher( "<td>"+widget+" \\((\\d+)\\)</td><td>(.+?)</td><td>(\\d+)</td>" ,storecache );
//if (shopmatch.find())
//{
// thingy.amount=shopmatch.group(1).to_int();
// thingy.price=shopmatch.group(2).to_int();
// thingy.limit=shopmatch.group(3).to_int();
// return thingy;
//}
return thingy;
}
shopinfo[item] ShopParse()
{
shopinfo[item] thingy;
matcher shopmatch;
boolean done=false;
foreach i in $items[]
{
if(is_tradeable(i) && shop_amount(i)>0)
{
done=false;
if(!done)
{
shopmatch = create_matcher( "<td>"+i+"</td><td>(.+?)<" ,storecache );
if (shopmatch.find())
{
thingy[i].amount=1;
thingy[i].price=shopmatch.group(1).to_int();
thingy[i].limit=0;
done=true;
}
}
if(!done)
{
shopmatch = create_matcher( "<td>"+i+" \\((\\d+)\\)</td><td>(.+?)<" ,storecache );
if (shopmatch.find())
{
thingy[i].amount=shopmatch.group(1).to_int();
thingy[i].price=shopmatch.group(2).to_int();
thingy[i].limit=0;
done=true;
}
}
//if(!done)
//{
// shopmatch = create_matcher( "<td>"+i+" \\((\\d+)\\)</td><td>(.+?)</td><td>(\\d+)</td>" ,storecache );
// if (shopmatch.find())
// {
// thingy[i].amount=shopmatch.group(1).to_int();
// thingy[i].price=shopmatch.group(2).to_int();
// thingy[i].limit=shopmatch.group(3).to_int();
// done=true;
// }
//}
}
}
return thingy;
}
void main()
{
//single request test
item dude=$item[hamethyst];
print("Test1","blue");
print("The shop price for a "+dude+" = "+ShopPrice(dude));
print("");
//parse test
print("Test2","blue");
shopinfo [item] MyShop= ShopParse();
map_to_file(MyShop, "MyShop.txt");
print("Check MyShop.txt in your data folder","blue");
dude=$item[mr. accessory];
print(dude);
print("amount="+myshop[dude].amount);
print("price="+myshop[dude].price);
print("limit="+myshop[dude].limit);
}
record mall_item {
item thing;
int price;
int qty;
int limit;
};
int parse_num(string n) {
string t; matcher m;
t = replace_string(n, ",", "").to_string();
m = create_matcher("\\d{1,9}",t);
if (m.find()) return t.to_int();
return -1;
}
int limit_parse(string l) {
if (!contains_text(l, ">(unlimited)<"))
return (is_integer(l)) ? l.to_int() : 0;
return 0;
}
mall_item[item] ShopParse()
{
//define return value
mall_item [item] my_mallstore;
//clip page
string page = visit_url("managestore.php");
matcher m1 = create_matcher("<div.+?><b>Store Inventory:</b>(.+?)</table></div>",page);
if (m1.find())
{
page = m1.group(1);
matcher m2 = create_matcher("<tr><td><img.+?></td><td>(.+?(?:\\s\\(\\d{1,3}(?:,\\d{3}){0,2}\\))?)</td><td>(\\d{1,3}(?:,\\d{3}){0,2})</td><td>(.+?)</td>.+?</tr>",page);
matcher m3;
item thing;
int qty;
while (m2.find())
{
//print(m2.group(1),"blue"); print(m2.group(2));
m3 = create_matcher("(.+?)\\s\\((\\d{1,9})\\)", m2.group(1));
if (m3.find())
{
thing = m3.group(1).to_item();
qty = parse_num(m3.group(2));
}
else
{
thing = m2.group(1).to_item();
qty = 1;
}
my_mallstore[thing].price = parse_num(m2.group(2));
my_mallstore[thing].qty=qty;
my_mallstore[thing].limit= limit_parse(m2.group(3));
} // while loop through ea. line of store stuff / qty
//save map
if (map_to_file(my_mallstore, my_name().to_lower_case() + "_mall.txt")) print("Store snapshot saved.", "green");
else print("Error saving store snapshot; please try again.", "red");
}
else { print("Unable to find any mall items.","red");}
return my_mallstore;
}
//Test
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
mall_item [item] myshop = ShopParse();
int totalvalue=0;
print("Your Shop Contains","blue");
foreach i in myshop
{
if(myshop[i].limit>0) print(i+" ("+myshop[i].qty+" limit "+myshop[i].limit+" @ "+myshop[i].price+")");
else print(i+" ("+myshop[i].qty+" @ "+myshop[i].price+")");
totalvalue=totalvalue+(myshop[i].price*myshop[i].qty);
}
print("Total Shop Value= "+totalvalue,"blue");
int ShopPrice(item widget)
{
mall_item [item] myshop = ShopParse();
if (myshop contains widget) return myshop[widget].price;
return 0;
}