prontera,155,179,5 script kjdhfkjshf 100,{
mes "this is an exchanger shop";
mes "make sure you selected 2 items";
close2;
callshop "testshop", 1;
end;
OnBuyItem:
if ( getarraysize( @bought_nameid ) != 2 ) {
mes "please select only 2 items";
close;
}
while ( .@i < 2 ) {
while ( @bought_nameid[.@i] != .exchange_list[ .@j[.@i] ] && .@j[.@i] < .shop_size ) .@j[.@i] += 2;
if ( .@j[.@i] >= .shop_size ) end; // error
.@i++;
}
mes "selected :-";
mes .exchange_list[ .@j[0] +1 ]+"x "+ getitemname( .exchange_list[ .@j[0] ] );
mes .exchange_list[ .@j[1] +1 ]+"x "+ getitemname( .exchange_list[ .@j[1] ] );
next;
.@s = select (
.exchange_list[ .@j[0] +1 ]+"x "+ getitemname( .exchange_list[ .@j[0] ] ) +" -> "+ .exchange_list[ .@j[1] +1 ]+"x "+ getitemname( .exchange_list[ .@j[1] ] ),
.exchange_list[ .@j[1] +1 ]+"x "+ getitemname( .exchange_list[ .@j[1] ] ) +" -> "+ .exchange_list[ .@j[0] +1 ]+"x "+ getitemname( .exchange_list[ .@j[0] ] ) ) -1;
mes "selected :-";
mes .exchange_list[ .@j[.@s] +1 ]+"x "+ getitemname( .exchange_list[ .@j[.@s] ] ) +" -> "+ .exchange_list[ .@j[!.@s] +1 ]+"x "+ getitemname( .exchange_list[ .@j[!.@s] ] );
mes " ";
if ( countitem( .exchange_list[ .@j[.@s] ] ) < .exchange_list[ .@j[.@s] +1 ] ) {
mes "not enough "+ getitemname( .exchange_list[ .@j[.@s] ] );
close;
}
mes "input the amount that you can change";
mes "max = "+( .@max = countitem( .exchange_list[ .@j[.@s] ] ) / .exchange_list[ .@j[.@s] +1 ] );
next;
if ( input( .@input, 1, .@max ) ) {
mes "invalid amount";
close;
}
delitem .exchange_list[ .@j[.@s] ], .@input * .exchange_list[ .@j[.@s] +1 ];
getitem .exchange_list[ .@j[!.@s] ], .@input * .exchange_list[ .@j[!.@s] +1 ];
close;
OnInit:
setarray .exchange_list,
501, 1, // rate of exchange, 1x red potion
502, 1,
503, 5; // rate of exchange, 5x yellow potions
npcshopdelitem "testshop", 501;
.shop_size = getarraysize( .exchange_list );
for ( .@i = 0; .@i < .shop_size; .@i += 2 )
npcshopadditem "testshop", .exchange_list[.@i], .exchange_list[.@i +1];
npcshopattach "testshop";
end;
}
- shop testshop -1,501:1000