Is there a script that...

zarqon

Well-known member
Yes -- use these functions.

Then you could do something like this:

Code:
// This example will attempt to send 1000 meat and
// 11 batguts to each of the players listed in "recipients".

// copy the kmail functions here

string recipients = "Zarqon,Kaluna,Macatoni,Uggh";    // commas, no spaces
string message = "Hello, here is a bit of meat and a ridiculous amount of batguts!";
int meattosend = 1000;             // how much meat to send in each kmail
int[item] stufftosend;
stufftosend[$item[batgut]] = 11;  // you can add items following this format

string[int] recipmap = split_string(recipients,",");
foreach r in recipmap
   if (!kmail(recipmap[r],message,meattosend,stufftosend)) abort("Unable to send.");
 
Last edited:

zarqon

Well-known member
Combine the kmail functions and the code I posted above in a text editor (such as Notepad if you're running Windows) and save it with an .ash extension in your scripts directory.

Also, unless you want to send the leaders of my clan 1000 meat and 11 batguts each, change the variables to suit your needs.
 

The Botter

New member
This is what my script looks like and I keep getting errors.

Code:
boolean kmail(string to, string message, int meat, int[item] goodies) {
   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] = "";
  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;

{string recipients = "name,name";    
string message = "Hey I am testing this out!";
int meattosend = 1;             
int[item] stufftosend;
stufftosend[$item[batgut]] = 1;

string[int] recipmap = split_string(recipients,",");
foreach r in recipmap
   if (!kmail(recipmap[r],message,meattosend,stufftosend)) abort("Unable to send.");

What am I writing wrong?
 

zarqon

Well-known member
1. You also need the send_gift() function from that other post, and it needs to be above the kmail function, because kmail() attempts to send a gift if the target is in Ronin/HC.

2. You have an opening bracket instead of a closing bracket at the end of the kamil function.

3. I'm assuming you're not really sending to "name" twice...
 

The Botter

New member
Okay I fixed what needed to be fixed. (no I am not trying to send to the same person twice). I copied the whole list over, and I still get the error: Expected ), found >

It's the same one as before. It's been a while since I have scripted and coded things (3 1/2 years) and I feel like a complete idiot when asking this question. What exactly is a line because when it says something like: Expected ), found > Line 5, I look over what I assume line 5 is and see if there is anything wrong, and I don't see anything wrong.

If it helps this is what my code looks like now,

Code:
(Copied and pasted functions)
string recipients = "name,name2";    
string message = "This is my message";
int meattosend = 1;             
int[item] stufftosend;
stufftosend[$item[batgut]] = 1;

string[int] recipmap = split_string(recipients,",");
foreach r in recipmap
   if (!kmail(recipmap[r],message,meattosend,stufftosend)) abort("Unable to send.");
 

zarqon

Well-known member
I'm thinking the problem is that you are not saving this as a flat text file. Evidently some HTML tags or something are in the saved file, because there are no >'s in what you pasted above. What editor are you using to make this file?
 

The Botter

New member
I am using Microsoft Notepad. I copied the whole function thing, deleted the part that wasn't supposed to be copied (your signature). I also deleted the //(text here) because I am almost sure that it doesn't matter whether it's there or not. When I go to save it I change it from text file (.txt) to All files and save it as kmail.ash in my scripts folder. I am not using HTML in this at all.

So I am using notepad. Here is the whole thing.

Code:
boolean send_gift(string to, string message, int meat, int[item] goodies) {
   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;
  }
   string url = visit_url("town_sendgift.php?pwd=&towho="+to+"&note="+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) {
  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] = "";
  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;
}
string recipients = "name1,name2";    
string message = "Hey I am testing this out!";
int meattosend = 0;             
int[item] stufftosend;
stufftosend[$item[batgut]] = 0;

string[int] recipmap = split_string(recipients,",");
foreach r in recipmap
   if (!kmail(recipmap[r],message,meattosend,stufftosend)) abort("Unable to send.");

That is exactly what I am trying to use and it isn't working. (name1 and name2 are just me hiding the real names I am actually going to use more than that so....)

I tried using this and I get the error Expected ), found > (test.ash, line 5)

Also I am so sorry, I feel like I'm wasting your time.
 

Bale

Minion
That's a bad copy-paste error. Here's the solution. Do a global search and replace on the function.

> replace with >
< replace with <
 

zarqon

Well-known member
Ha! I suspect that's actually a forum error. <'s and >'s didn't get properly converted over when the forum software switched to vBulletin. I'll edit that post to avoid any further confusion.
 

The Botter

New member
Wow, I can't believe I didn't catch that after all the work I did with HTML and constantly using & and whatever the thing I had to do to add multiple spaces it was like &spbr; or something anyway thanks for your help I really appreciate it. Here later on I am going to make a user form and re-code it to make easier so I don't have to go in and change the code to match what I need constantly. And if it's good and works like it's supposed to I'll see if I can get your permission to upload the folder.
 
Top