Advertisement
Emistry

[RO] Mail NPC

Jul 3rd, 2016
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.15 KB | None | 0 0
  1.  
  2. prt_vilg01,98,76,5 script Mail NPC 4_F_KAFRA9,{
  3. doevent "mail_main::OnTalk";
  4. end;
  5. }
  6.  
  7. - script mail_main -1,{
  8.  
  9. function func_getitemname {
  10. .@refine = getarg(0,0);
  11. .@nameid = getarg(1,0);
  12. .@amount = getarg(2,0);
  13.  
  14. if ( .@nameid >= 1 && .@amount >= 1 ) {
  15. .@name$ = getitemname( .@nameid );
  16. .@itemtype = getiteminfo( .@nameid,2 );
  17. if ( .@itemtype == IT_WEAPON || .@itemtype == IT_WEAPON ) {
  18. if ( .@refine )
  19. .@name$ = "+"+.@refine+" "+.@name$;
  20. .@name$ = .@name$+" ["+getitemslots( .@nameid )+"]";
  21. }
  22. }
  23. return .@name$;
  24. }
  25.  
  26. OnTalk:
  27. switch( select(
  28. "Read mail",
  29. "Compose Mail",
  30. "Cancel"
  31. )) {
  32. case 1:
  33. .@sql$ = "SELECT `id`,`send_name`,`title`,`message`,`zeny`,`nameid`,`amount`,`refine`,`attribute`,`identify`,`card0`,`card1`,`card2`,`card3`"
  34. + "FROM `mail` "
  35. + "WHERE `dest_name` = '"+escape_sql( strcharinfo(0) )+"' "
  36. + "ORDER BY `time` DESC "
  37. + "LIMIT "+.max_size;
  38. query_sql( .@sql$,.@id,.@send_name$,.@title$,.@message$,.@zeny,.@nameid,.@amount,.@refine,.@attribute,.@identify,.@card0,.@card1,.@card2,.@card3 );
  39. .@id_size = getarraysize( .@id );
  40. if ( !.@id_size ) {
  41. mes "Didn't have any email.";
  42. }
  43. else {
  44. for ( .@i = 0; .@i < .@id_size; .@i++ )
  45. .@menu$ = .@menu$ + replacestr( .@title$[.@i], ":", " " ) + "by " + replacestr( .@send_name$[.@i], ":", " " ) + ":";
  46. .@i = select( .@menu$ ) - 1;
  47. mes "Sender: "+.@send_name$[.@i];
  48. mes "Title: "+.@title$[.@i];
  49. mes "Message: "+.@message$[.@i];
  50. if ( .@nameid[.@i] && .@amount[.@i] )
  51. mes "Item: "+func_getitemname( .@refine[.@i],.@nameid[.@i],.@amount[.@i] );
  52. if ( .@zeny[.@i] )
  53. mes "Zeny: "+F_InsertComma( .@zeny[.@i] )+"z";
  54.  
  55. if ( select( (( .@nameid[.@i] && .@amount[.@i] ) || .@zeny[.@i] ) ? "Retrieve Item(s) & Delete Mail":"Delete Mail","Cancel" ) ) {
  56. mes "This action cant be undo, are you sure ?";
  57. if ( select( "Confirm","Cancel" ) == 1 ) {
  58. if ( .@nameid[.@i] && .@amount[.@i] ) {
  59. if ( !checkweight( .@nameid[.@i],.@amount[.@i] ) ) {
  60. mes "You're overweight.";
  61. break;
  62. }
  63. else {
  64. getitem2 .@nameid[.@i],.@amount[.@i],.@identify[.@i],.@refine[.@i],.@attribute[.@i],.@card0[.@i],.@card1[.@i],.@card2[.@i],.@card3[.@i];
  65. }
  66. }
  67. if ( .@zeny[.@i] )
  68. Zeny += .@zeny[.@i];
  69. query_sql( "DELETE FROM `mail` WHERE `id` = '"+.@id[.@i]+"' LIMIT 1" );
  70. }
  71. }
  72. }
  73. break;
  74. case 2:
  75. disable_items;
  76. do {
  77.  
  78. .@is_complete = (
  79. .@dest_id != 0
  80. && .@dest_name$ != ""
  81. && .@title$ != ""
  82. && .@message$ != ""
  83. );
  84.  
  85. mes "Receiver: "+.@dest_name$;
  86. mes "Title: "+.@title$;
  87. mes "Message: "+.@message$;
  88. if ( .@nameid && .@amount )
  89. mes "Item: "+func_getitemname( .@refine,.@nameid,.@amount );
  90. if ( .@zeny )
  91. mes "Zeny: "+F_InsertComma( .@zeny )+"z";
  92. next;
  93. switch ( select(
  94. "Edit Receiver",
  95. "Edit Title",
  96. "Edit Message",
  97. "Edit Item",
  98. "Edit Zeny",
  99. ( .@is_complete ) ? "Complete":""
  100. )) {
  101. case 1:
  102. mes "Enter Player Name";
  103. input .@input$;
  104. query_sql( "SELECT `account_id`,`name` FROM `char` WHERE `name` LIKE '"+escape_sql( .@input$ )+"' LIMIT 1",.@dest_id,.@dest_name$ );
  105. if ( !.@dest_id ) {
  106. mes "Char not found.";
  107. }
  108. break;
  109. case 2:
  110. mes "Enter Title";
  111. input .@title$,0,45;
  112. break;
  113. case 3:
  114. mes "Enter Message";
  115. input .@message$;
  116. break;
  117. break;
  118. case 4:
  119. .@temp_menu$ = "";
  120. .@temp_count = 0;
  121. getinventorylist;
  122. for ( .@i = 0; .@i < @inventorylist_count; .@i++ ) {
  123. if ( !@inventorylist_bound[.@i] && !@inventorylist_expire[.@i] && !@inventorylist_equip[.@i] && @inventorylist_amount[.@i] > 0 ) {
  124. .@temp_menu$ = .@temp_menu$ + func_getitemname( @inventorylist_refine[.@i],@inventorylist_id[.@i],@inventorylist_amount[.@i] );
  125. .@temp_count++;
  126. }
  127. .@temp_menu$ = .@temp_menu$ + ":";
  128. }
  129. if ( !.@temp_count ) {
  130. mes "Dont have available item(s) for mail.";
  131. }
  132. else {
  133. mes "Pick an item from your inventory.";
  134. .@i = select( .@temp_menu$+"None" ) - 1;
  135.  
  136. if ( .@i < @inventorylist_count ) {
  137. .@nameid = @inventorylist_id[.@i];
  138. .@amount = @inventorylist_amount[.@i];
  139. .@refine = @inventorylist_refine[.@i];
  140. .@identify = @inventorylist_identify[.@i];
  141. .@attribute = @inventorylist_attribute[.@i];
  142. .@card0 = @inventorylist_card1[.@i];
  143. .@card1 = @inventorylist_card2[.@i];
  144. .@card2 = @inventorylist_card3[.@i];
  145. .@card3 = @inventorylist_card4[.@i];
  146. }
  147. else {
  148. .@nameid = 0;
  149. .@amount = 0;
  150. }
  151. }
  152. break;
  153. case 5:
  154. mes "Enter Zeny";
  155. input .@zeny,0,Zeny;
  156. break;
  157. case 6:
  158. mes "Confirm your action.";
  159. if ( select( "Confirm","Cancel" ) == 1 ) {
  160. if ( .@nameid && .@amount > 0 ) {
  161. delitem2 .@nameid,.@amount,.@identify,.@refine,.@attribute,.@card0,.@card1,.@card2,.@card3;
  162. }
  163. if ( .@zeny[.@i] )
  164. Zeny -= .@zeny;
  165.  
  166. .@sql$ = sprintf( "INSERT INTO `mail` ( %s ) VALUES ( %s ) ",
  167. "`send_name`,`send_id`,`dest_name`,`dest_id`,`title`,`message`,`time`,`status`,`zeny`,`nameid`,`amount`,`refine`,`attribute`,`identify`,`card0`,`card1`,`card2`,`card3`",
  168. "'"+escape_sql( .@send_name$ )+"',"+getcharid(3)+",'"+escape_sql( .@dest_name$ )+"',"+.@dest_id+",'"+escape_sql( .@title$ )+"','"+escape_sql( .@message$ )+"',"+gettimetick(2)+",1,"+.@zeny+","+.@nameid+","+.@amount+","+.@refine+","+.@attribute+","+.@identify+","+.@card0+","+.@card1+","+.@card2+","+.@card3
  169. );
  170. query_sql( .@sql$ );
  171. mes "Done";
  172. close;
  173. }
  174. break;
  175. }
  176. next;
  177. } while ( 1 );
  178. break;
  179. default:
  180. break;
  181. }
  182. close;
  183.  
  184. OnInit:
  185. .max_size = 30;
  186. end;
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement