viewing paste topic/4516- shop exchanger | Athena

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
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
Viewed 1430 times, submitted by AnnieRuru.