akbare

Multi Currency Shop

Aug 17th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.70 KB | None | 0 0
  1. // Settings :
  2. // - Only required to edit the ShopSetting() Function
  3. // Notes : You may also add / remove Menu ( If any )
  4. // - Shop Currency can be either ItemID or Variable Name, but must write within Quotation Marks ( "" )
  5. // Ex. of Variable. -> Zeny , #CASHPOINTS , #KAFRAPOINTS , CustomVariable , #CustomVariable
  6. // - ERROR Message are used to show Invalid Settings in your NPC.
  7.  
  8.  
  9. // Leave this alone...
  10. - shop Emistry_Shop -1,512:100
  11.  
  12.  
  13. prontera,155,181,5 script Sample 757,{
  14. function ShopSettings;
  15. function ValidateCost;
  16. function CurrencyInfo;
  17. function ClearData;
  18. function ValueConvert;
  19. function ErrorNotice;
  20.  
  21. mes "Each Shop from the Menu may purchase using ^FF0000Different Currency^000000.";
  22. mes "^00FF00____________________________^000000";
  23. mes "So,Which shop you would like to look at it";
  24. next;
  25. // Menu Selection
  26. select("Shop 1","Shop 2","Shop 3");
  27.  
  28. ClearData();
  29. ShopSettings( @menu );
  30. npcshopitem "Emistry_Shop",512,100;
  31. npcshopdelitem "Emistry_Shop",512;
  32. for(set .@i,0; .@i < getarraysize( @ItemLists ); set .@i,.@i+1)
  33. npcshopadditem "Emistry_Shop",@ItemLists[.@i],@ItemCost[.@i];
  34. mes "Okay...wait awhile";
  35. mes "^00FF00____________________________^000000";
  36. CurrencyInfo( @Currency$ );
  37. mes "^00FF00____________________________^000000";
  38. callshop "Emistry_Shop",1;
  39. npcshopattach "Emistry_Shop";
  40. end;
  41.  
  42.  
  43. function ShopSettings {
  44. switch( getarg(0) ){
  45. Case 1:
  46. // Currency [ Item ID / Variable Name ]
  47. set @Currency$,"7179";
  48. // Item ID Lists
  49. setarray @ItemLists[0],6153,7227;
  50. // Item Price
  51. setarray @ItemCost[0],100,1;
  52. break;
  53. Case 2:
  54. // Currency [ Item ID / Variable Name ]
  55. set @Currency$,"7227";
  56. // Item ID Lists
  57. setarray @ItemLists[0],2306,2302,2303,2304,2305,2301;
  58. // Item Price
  59. setarray @ItemCost[0],2,2,3,4,5,6;
  60. break;
  61. Case 3:
  62. // Currency [ Item ID / Variable Name ]
  63. set @Currency$,"#CASHPOINTS";
  64. // Item ID Lists
  65. setarray @ItemLists[0],2306,2302,2303,2304,2305,2301;
  66. // Item Price
  67. setarray @ItemCost[0],20,22,34,445,52,641;
  68. break;
  69. // Case 4,5,6.....etc...
  70. default:
  71. ErrorNotice( "Invalid Menu Selection for Menu "+@menu+"." );
  72. close;
  73. }
  74.  
  75.  
  76. if( @Currency$ == "" )
  77. ErrorNotice( "Invalid Currency Setting in Menu "+@menu+" ." );
  78. if( getarraysize( @ItemCost ) != getarraysize( @ItemLists ) || getarraysize( @ItemLists ) != getarraysize( @ItemCost ) )
  79. ErrorNotice( "Missing or Extra Value of Item or Cost Settings in Menu "+@menu+" ." );
  80. return;
  81. }
  82.  
  83. function ErrorNotice {
  84. mes "^FF0000ERROR^000000 - "+getarg(0);
  85. mes "^00FF00____________________________^000000";
  86. mes "Inform this Message to ^0000FFGame Staffs^000000 immediately !";
  87. close;
  88. }
  89.  
  90. function CurrencyInfo {
  91. if( getitemname( atoi( getarg(0) ) ) != "null" ){
  92. mes "Item Currency : ^FF0000"+getitemname( atoi( getarg(0) ) )+"^000000";
  93. mes "Available Amount : ^0000FF"+ValueConvert( countitem( atoi( getarg(0) ) ) )+"^000000";
  94. }else if( getitemname( atoi( getarg(0) ) ) == "null" ){
  95. mes "Variable Currency : ^FF0000"+getarg(0)+"^000000";
  96. mes "Available Amount : ^0000FF"+ValueConvert( getd( getarg(0) ) )+"^000000";
  97. }
  98. return;
  99. }
  100.  
  101. function ValidateCost {
  102. if( getitemname( atoi( getarg(0) ) ) != "null" ){
  103. if( countitem( atoi( getarg(0) ) ) < getarg(1) ) return 1;
  104. }else{
  105. if( getd( getarg(0) ) < getarg(1) ) return 1;
  106. }
  107. return 0;
  108. }
  109.  
  110. function ClearData {
  111. set @Currency$,"";
  112. set @TotalCost,0;
  113. deletearray @bought_nameid[0],getarraysize( @bought_nameid );
  114. deletearray @bought_quantity[0],getarraysize( @bought_quantity );
  115. deletearray @ItemLists[0],getarraysize( @ItemLists );
  116. deletearray @ItemCost[0],getarraysize( @ItemCost );
  117. return;
  118. }
  119.  
  120. function ValueConvert {
  121. set .@num, atoi(""+getarg(0));
  122. if ( .@num == 0 || .@num >= 2147483647 ) return getarg(0);
  123. set .@l, getstrlen(""+.@num);
  124. for ( set .@i,0; .@i < .@l; set .@i, .@i + 1 ) {
  125. set .@num$, .@num % pow(10,.@i+1) / pow(10,.@i) + .@num$;
  126. if ( (.@i+1) % 3 == 0 && .@i+1 != .@l ) set .@num$, ","+ .@num$;
  127. }
  128. return .@num$;
  129. }
  130.  
  131. OnBuyItem:
  132. ShopSettings( @menu );
  133. for(set @i,0; @i < getarraysize( @bought_nameid ); set @i,@i+1)
  134. for(set @j,0; @j < getarraysize( @ItemLists ); set @j,@j+1)
  135. if( @ItemLists[@j] == @bought_nameid[@i] )
  136. set @TotalCost,@TotalCost + ( @ItemCost[@j] * @bought_quantity[@i] );
  137. mes "^FF0000 BILLING LIST^000000";
  138. mes "^00FF00____________________________^000000";
  139. for( set @i,0; @i < getarraysize( @bought_nameid ); set @i,@i+1 )
  140. mes "^FF0000"+@bought_quantity[@i]+" x ^0000FF"+getitemname( @bought_nameid[@i] )+"^000000";
  141. mes "^00FF00____________________________^000000";
  142.  
  143. if( getitemname( atoi( @Currency$ ) ) != "null" )
  144. mes "Total Cost : ^0000FF"+ValueConvert( @TotalCost )+" x "+getitemname( atoi( @Currency$ ) )+"^000000";
  145. else if( getitemname( atoi( @Currency$ ) ) == "null" ){
  146. mes "Total Cost : ^0000FF"+ValueConvert( @TotalCost )+" "+@Currency$+"^000000";
  147. }
  148.  
  149. mes "^00FF00____________________________^000000";
  150. if( ValidateCost( @Currency$,@TotalCost ) ){
  151. if( getitemname( atoi( @Currency$ ) ) != "null" )
  152. mes "[ ^FF0000X^000000 ] Insufficient ^0000FF"+getitemname( atoi( @Currency$ ) )+"^000000";
  153. else{
  154. mes "[ ^FF0000X^000000 ] Insufficient ^0000FF"+@Currency$+"^000000";
  155. }
  156. }else{
  157. if( select( "^0000FFPurchase^000000:Cancel" ) == 1 ){
  158. if( getitemname( atoi( @Currency$ ) ) != "null" )
  159. delitem atoi( @Currency$ ),@TotalCost;
  160. else{
  161. set getd( @Currency$ ),getd( @Currency$ ) - @TotalCost;
  162. }
  163. for(set @i,0; @i < getarraysize( @bought_nameid ); set @i,@i+1)
  164. getitem @bought_nameid[@i],@bought_quantity[@i];
  165. message strcharinfo(0),"Purchased "+getarraysize( @bought_nameid )+" Items.";
  166. mes "Thank you for shopping.";
  167. }
  168. }
  169. ClearData();
  170. close;
  171.  
  172. }
Add Comment
Please, Sign In to add comment