SHOW:
|
|
- or go back to the newest paste.
| 1 | //===== rAthena Script ========================================================== | |
| 2 | //= Custom Shop | |
| 3 | //===== By: ===================================================================== | |
| 4 | //= Emistry | |
| 5 | //===== Current Version: ======================================================== | |
| 6 | //= 2.0 | |
| 7 | //===== Compatible With: ======================================================== | |
| 8 | //= rAthena | |
| 9 | //===== Additional Comments: ==================================================== | |
| 10 | //= 1.0 Initial Script | |
| 11 | - | //= 2.0 Optimized. Cleaned script. Added Currency Trader [Boom] |
| 11 | + | |
| 12 | //Shop Currency can be either ItemID or Variable Name, but must write within Quotation Marks ( "" ) | |
| 13 | //Zeny , #CASHPOINTS , #KAFRAPOINTS , CustomVariable , #CustomVariable | |
| 14 | ||
| 15 | ||
| 16 | - shop cshop1 -1,512:100 | |
| 17 | ||
| 18 | prontera,150,165,2 script Shop 564,{
| |
| 19 | ||
| 20 | set .npcname$, "Premium item dealer"; | |
| 21 | function ShopSettings; | |
| 22 | function ValidateCost; | |
| 23 | function CurrencyInfo; | |
| 24 | function ClearData; | |
| 25 | function ValueConvert; | |
| 26 | function ErrorNotice; | |
| 27 | ||
| 28 | // Menu Selection | |
| 29 | select("Upper Headgears","Middle Headgears","Lower Headgears");
| |
| 30 | ||
| 31 | ClearData(); | |
| 32 | ShopSettings( @menu ); | |
| 33 | ||
| 34 | ||
| 35 | npcshopitem "cshop1",512,100; | |
| 36 | npcshopdelitem "cshop1",512; | |
| 37 | ||
| 38 | for(set .@i,0; .@i < getarraysize( @ItemLists ); set .@i,.@i+1) | |
| 39 | npcshopadditem "cshop1",@ItemLists[.@i],@ItemCost[.@i]; | |
| 40 | ||
| 41 | mes "ok, shop now !"; | |
| 42 | mes "^00FF00----------------------------^000000"; | |
| 43 | CurrencyInfo( @Currency$ ); | |
| 44 | mes "^00FF00----------------------------^000000"; | |
| 45 | close2; | |
| 46 | npcshopattach "cshop1"; | |
| 47 | callshop "cshop1",1; | |
| 48 | end; | |
| 49 | ||
| 50 | function ShopSettings | |
| 51 | {
| |
| 52 | switch( getarg(0) ){
| |
| 53 | ||
| 54 | case 1: | |
| 55 | // Currency [ Item ID / Variable Name ] | |
| 56 | set @Currency$,"674"; | |
| 57 | // Item ID Lists | |
| 58 | setarray @ItemLists[0],5105,5106,5407,5406,5011; | |
| 59 | // Item Price | |
| 60 | setarray @ItemCost[0],100,100,100,100,100; | |
| 61 | break; | |
| 62 | end; | |
| 63 | case 2: | |
| 64 | // Currency [ Item ID / Variable Name ] | |
| 65 | set @Currency$,"674"; | |
| 66 | // Item ID Lists | |
| 67 | setarray @ItemLists[0],5788,5794,5786,5389; | |
| 68 | // Item Price | |
| 69 | setarray @ItemCost[0],100,100,100,100; | |
| 70 | break; | |
| 71 | end; | |
| 72 | case 3: | |
| 73 | // Currency [ Item ID / Variable Name ] | |
| 74 | set @Currency$,"674"; | |
| 75 | // Item ID Lists | |
| 76 | setarray @ItemLists[0],5521,5054,5110,2240; | |
| 77 | // Item Price | |
| 78 | setarray @ItemCost[0],100,100,100,100; | |
| 79 | break; | |
| 80 | end; | |
| 81 | ||
| 82 | default: | |
| 83 | ErrorNotice( "Invalid Menu Selection for Menu "+@menu+"." ); | |
| 84 | close; | |
| 85 | } | |
| 86 | ||
| 87 | if( @Currency$ == "" ) | |
| 88 | ErrorNotice( "Invalid Currency Setting in Menu "+@menu+" ." ); | |
| 89 | if( getarraysize( @ItemCost ) != getarraysize( @ItemLists ) || getarraysize( @ItemLists ) != getarraysize( @ItemCost ) ) | |
| 90 | ErrorNotice( "Missing or Extra Value of Item or Cost Settings in Menu "+@menu+" ." ); | |
| 91 | return; | |
| 92 | } | |
| 93 | ||
| 94 | function ErrorNotice | |
| 95 | {
| |
| 96 | mes "^FF0000ERROR^000000 - "+getarg(0); | |
| 97 | mes "^00FF00----------------------------^000000"; | |
| 98 | mes "Please inform the ^0000FFGame Masters^000000 immediately !"; | |
| 99 | close; | |
| 100 | } | |
| 101 | ||
| 102 | function CurrencyInfo | |
| 103 | {
| |
| 104 | if( getitemname( atoi( getarg(0) ) ) != "null" ){
| |
| 105 | mes "Item Currency : ^FF0000"+getitemname( atoi( getarg(0) ) )+"^000000"; | |
| 106 | mes "Available Amount : ^0000FF"+ValueConvert( countitem( atoi( getarg(0) ) ) )+"^000000"; | |
| 107 | }else if( getitemname( atoi( getarg(0) ) ) == "null" ){
| |
| 108 | mes "Variable Currency : ^FF0000"+getarg(0)+"^000000"; | |
| 109 | mes "Available Amount : ^0000FF"+ValueConvert( getd( getarg(0) ) )+"^000000"; | |
| 110 | } | |
| 111 | return; | |
| 112 | } | |
| 113 | ||
| 114 | function ValidateCost | |
| 115 | {
| |
| 116 | if( getitemname( atoi( getarg(0) ) ) != "null" ){
| |
| 117 | if( countitem( atoi( getarg(0) ) ) < getarg(1) ) return 1; | |
| 118 | }else{
| |
| 119 | if( getd( getarg(0) ) < getarg(1) ) return 1; | |
| 120 | } | |
| 121 | return 0; | |
| 122 | } | |
| 123 | ||
| 124 | function ClearData | |
| 125 | {
| |
| 126 | set @Currency$,""; | |
| 127 | set @TotalCost,0; | |
| 128 | deletearray @bought_nameid[0],getarraysize( @bought_nameid ); | |
| 129 | deletearray @bought_quantity[0],getarraysize( @bought_quantity ); | |
| 130 | deletearray @ItemLists[0],getarraysize( @ItemLists ); | |
| 131 | deletearray @ItemCost[0],getarraysize( @ItemCost ); | |
| 132 | return; | |
| 133 | } | |
| 134 | ||
| 135 | function ValueConvert | |
| 136 | {
| |
| 137 | set .@num, atoi(""+getarg(0));
| |
| 138 | if ( .@num == 0 || .@num >= 2147483647 ) return getarg(0); | |
| 139 | set .@l, getstrlen(""+.@num);
| |
| 140 | for ( set .@i,0; .@i < .@l; set .@i, .@i + 1 ) {
| |
| 141 | set .@num$, .@num % pow(10,.@i+1) / pow(10,.@i) + .@num$; | |
| 142 | if ( (.@i+1) % 3 == 0 && .@i+1 != .@l ) set .@num$, ","+ .@num$; | |
| 143 | } | |
| 144 | return .@num$; | |
| 145 | } | |
| 146 | ||
| 147 | OnBuyItem: | |
| 148 | ShopSettings( @menu ); | |
| 149 | for(set @i,0; @i < getarraysize( @bought_nameid ); set @i,@i+1) | |
| 150 | for(set @j,0; @j < getarraysize( @ItemLists ); set @j,@j+1) | |
| 151 | if( @ItemLists[@j] == @bought_nameid[@i] ) | |
| 152 | set @TotalCost,@TotalCost + ( @ItemCost[@j] * @bought_quantity[@i] ); | |
| 153 | mes "^FF0000[Cash Shop Cart]^000000"; | |
| 154 | mes "Cart Contents:^000000"; | |
| 155 | for( set @i,0; @i < getarraysize( @bought_nameid ); set @i,@i+1 ) | |
| 156 | mes "^FF0000"+@bought_quantity[@i]+" x ^0000FF"+getitemname( @bought_nameid[@i] )+"^000000"; | |
| 157 | mes ""; | |
| 158 | ||
| 159 | if( getitemname( atoi( @Currency$ ) ) != "null" ) | |
| 160 | mes "Cost : ^0000FF"+ValueConvert( @TotalCost )+" x "+getitemname( atoi( @Currency$ ) )+"^000000"; | |
| 161 | else if( getitemname( atoi( @Currency$ ) ) == "null" ){
| |
| 162 | mes "Cost : ^0000FF"+ValueConvert( @TotalCost )+" "+@Currency$+"^000000"; | |
| 163 | } | |
| 164 | ||
| 165 | if( ValidateCost( @Currency$,@TotalCost ) ){
| |
| 166 | if( getitemname( atoi( @Currency$ ) ) != "null" ) | |
| 167 | mes "[ ^FF0000X^000000 ] Insufficient ^0000FF"+getitemname( atoi( @Currency$ ) )+"^000000"; | |
| 168 | else{
| |
| 169 | mes "[ ^FF0000X^000000 ] Insufficient ^0000FF"+@Currency$+"^000000"; | |
| 170 | } | |
| 171 | }else{
| |
| 172 | if( select( "^0000FFPurchase^000000:Cancel" ) == 1 ){
| |
| 173 | if( getitemname( atoi( @Currency$ ) ) != "null" ) | |
| 174 | delitem atoi( @Currency$ ),@TotalCost; | |
| 175 | else{
| |
| 176 | set getd( @Currency$ ),getd( @Currency$ ) - @TotalCost; | |
| 177 | } | |
| 178 | for(set @i,0; @i < getarraysize( @bought_nameid ); set @i,@i+1) | |
| 179 | getitem @bought_nameid[@i],@bought_quantity[@i]; | |
| 180 | //message strcharinfo(0),"Received "+getarraysize( @bought_nameid )+" Items."; | |
| 181 | message strcharinfo(0),"[Cash Shop] Transaction completed."; | |
| 182 | mes "thx!"; | |
| 183 | } | |
| 184 | } | |
| 185 | ClearData(); | |
| 186 | close; | |
| 187 | } |