zarqon
Well-known member
Here are some manual kmail functions in case you want to send specific text along with the items/meat. I wrote these for our clan tradebot/treasurer and decided others might find them useful.
It mirrors the behavior of cli_execute("send xx to xx"), in that it will send gifts if the target is in Ronin/hardcore.
It mirrors the behavior of cli_execute("send xx to xx"), in that it will send gifts if the target is in Ronin/hardcore.
Code:
boolean send_gift(string to, string message, int meat, int[item] goodies) {
// parse items into query string
string itemstring = "";
int j = 0;
int[item] extra;
if (count(goodies) > 0)
foreach i in goodies {
if (is_tradeable(i)) {
j = j+1;
if (j < 4)
itemstring = itemstring + "&howmany"+j+"="+goodies[i]+"&whichitem"+j+"="+to_int(i);
else extra[i] = goodies[i];
}
}
int shipping = 200;
int pnum = 3;
if (count(goodies) < 3) {
shipping = 50*count(goodies);
pnum = count(goodies);
}
if (my_meat() < meat+shipping) {
print("Not enough meat to send the package.","red");
return false;
}
// send gift
string url = visit_url("town_sendgift.php?pwd=&towho="+to+"¬e="+message+"&insidenote=&whichpackage="+pnum+"&fromwhere=0&sendmeat="+meat+"&action=Yep."+itemstring);
if (!contains_text(url,"Package sent.")) {
print("The message didn't send for some reason.","red");
return false;
}
if (count(extra) > 0) return send_gift(to,"Here are your remaining items that would not fit in the previous message.",0,extra);
return true;
}
boolean kmail(string to, string message, int meat, int[item] goodies) {
// parse items into query strings
string itemstring = "";
int j = 0;
string[int] itemstrings;
if (count(goodies) > 0)
foreach i in goodies {
if (is_tradeable(i)) {
j = j+1;
itemstring = itemstring + "&howmany"+j+"="+goodies[i]+"&whichitem"+j+"="+to_int(i);
if (j > 10) {
itemstrings[count(itemstrings)] = itemstring;
itemstring = '';
j = 0;
}
}
}
if (itemstring != "") itemstrings[count(itemstrings)] = itemstring;
if (count(itemstrings) == 0) itemstrings[0] = "";
// send message(s)
string msg;
foreach q in itemstrings {
if (q == 0) { msg = message; } else msg = 'Here are your remaining items that would not fit in the previous message.';
string url = visit_url("sendmessage.php?pwd=&action=send&towho="+url_encode(to)+"&message="+url_encode(msg)+"&sendmeat="+meat+itemstrings[q]);
if (contains_text(url,"That player cannot receive Meat or items"))
return send_gift(to, message, meat, goodies);
if (!contains_text(url,"Message sent.")) {
print("The message didn't send for some reason.","red");
return false;
}
}
return true;
}
Last edited: