src/map/script.c | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 136 insertions(+)
diff --git a/src/map/script.c b/src/map/script.c
index 0887b7f..28d6a9c 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -18525,10 +18525,146 @@ bool script_hp_add(char *name, char *args, bool (*func)(struct script_state *st)
return script->add_builtin(&buildin, true);
}
+BUILDIN(sendmail) {
+ struct map_session_data *sd;
+ struct mail_message mail;
+ int charid, zeny = 0, refine = 0, identify = 0, attribute = 0;
+ short itemid = 0, amount = 0, card0 = 0, card1 = 0, card2 = 0, card3 = 0;
+ const char *send_name, *title, *body;
+
+ charid = script_getnum(st,2);
+ if ( !( sd = map->charid2sd( charid ) ) ) {
+ ShowError( "buildin_sendmail: Player CID %d is not online, destination could not reach.\n", charid );
+ script_pushint(st,-1);
+ return false;
+ }
+
+ send_name = script_getstr(st,3);
+ if ( strlen(send_name) >= NAME_LENGTH ) {
+ ShowError( "buildin_sendmail: Send name must not more than %d length !\n", NAME_LENGTH -1 );
+ script_pushint(st,-2);
+ return false;
+ }
+
+ title = script_getstr(st,4);
+ if ( strlen(title) > MAIL_TITLE_LENGTH ) {
+ ShowError( "buildin_sendmail: Mail Title must not more than %d length !\n", MAIL_TITLE_LENGTH );
+ script_pushint(st,-3);
+ return false;
+ }
+
+ body = script_getstr(st,5);
+ if ( strlen(body) > MAIL_BODY_LENGTH ) {
+ ShowError( "buildin_sendmail: Mail message must not more than %d length !\n", MAIL_BODY_LENGTH );
+ script_pushint(st,-4);
+ return false;
+ }
+
+ if ( script_hasdata(st,6) ) {
+ zeny = script_getnum(st,6);
+ if ( zeny < 0 || zeny > MAX_ZENY ) {
+ ShowError( "buildin_sendmail: Invalid Zeny value %d !\n", zeny );
+ script_pushint(st,-5);
+ return false;
+ }
+ }
+
+ if ( script_hasdata(st,7) ) {
+ if ( data_isstring( script_getdata(st,7) ) ) {
+ const char *item_name = script_getstr(st,7);
+ struct item_data *idata = itemdb->search_name(item_name);
+ if ( idata == NULL ) {
+ ShowError( "buildin_sendmail: Unknown item name %s.\n", item_name );
+ script_pushint(st,-6);
+ return false;
+ }
+ itemid = idata->nameid;
+ if ( idata->type == IT_WEAPON || idata->type == IT_ARMOR )
+ identify = 1;
+ }
+ else {
+ itemid = script_getnum(st,7);
+ if ( itemdb->exists(itemid) == 0 ) {
+ ShowError( "buildin_sendmail: Unknown item ID %d.\n", itemid );
+ script_pushint(st,-6);
+ return false;
+ }
+ else {
+ struct item_data *idata = itemdb->search(itemid);
+ if ( idata->type == IT_WEAPON || idata->type == IT_ARMOR )
+ identify = 1;
+ }
+ }
+ }
+
+ if ( script_hasdata(st,8) ) {
+ if ( itemdb->isstackable(itemid) )
+ amount = script_getnum(st,8);
+ else
+ amount = 1;
+ if ( amount < 0 || amount > MAX_AMOUNT ) {
+ ShowError( "buildin_sendmail: Invalid item amount %d given.\n", amount );
+ script_pushint(st,-7);
+ return false;
+ }
+ }
+ else if ( script_hasdata(st,7) )
+ amount = 1;
+
+ if ( script_hasdata(st,9) ) {
+ refine = script_getnum(st,9);
+ if ( refine < 0 || refine > MAX_REFINE ) {
+ ShowError( "buildin_sendmail: Invalid refine amount %d given.\n", refine );
+ script_pushint(st,-8);
+ return false;
+ }
+ if ( script_hasdata(st,10) && script_hasdata(st,11) && script_hasdata(st,12) && script_hasdata(st,13) && script_hasdata(st,14) ) {
+ attribute = script_getnum(st,10);
+ if ( attribute < 0 )
+ attribute = 0;
+ else if ( attribute > 1 )
+ attribute = 1;
+ card0 = (short)script_getnum(st,11);
+ card1 = (short)script_getnum(st,12);
+ card2 = (short)script_getnum(st,13);
+ card3 = (short)script_getnum(st,14);
+ }
+ else {
+ ShowError( "buildin_sendmail: Not enough arguments for attibute or cards !\n" );
+ script_pushint(st,-9);
+ return false;
+ }
+ }
+
+ memset( &mail, 0, sizeof(mail) );
+ mail.dest_id = charid;
+ safestrncpy( mail.send_name, send_name, NAME_LENGTH );
+ safestrncpy( mail.dest_name, sd->status.name, NAME_LENGTH );
+ safestrncpy( mail.title, title, MAIL_TITLE_LENGTH );
+ safestrncpy( mail.body, body, MAIL_BODY_LENGTH );
+ mail.zeny = zeny;
+ mail.item.nameid = itemid;
+ mail.item.amount = amount;
+ mail.item.identify = identify;
+ mail.item.refine = refine;
+ mail.item.attribute = attribute;
+ mail.item.card[0] = card0;
+ mail.item.card[1] = card1;
+ mail.item.card[2] = card2;
+ mail.item.card[3] = card3;
+ mail.timestamp = time(NULL);
+
+ intif->Mail_send( sd->status.account_id, &mail );
+ script_pushint(st,0);
+
+ return true;
+}
+
#define BUILDIN_DEF(x,args) { buildin_ ## x , #x , args }
#define BUILDIN_DEF2(x,x2,args) { buildin_ ## x , x2 , args }
void script_parse_builtin(void) {
struct script_function BUILDIN[] = {
+ BUILDIN_DEF(sendmail,"isss?????????"),
// NPC interaction
BUILDIN_DEF(mes,"s*"),
BUILDIN_DEF(next,""),