viewing paste Coin Trader | Athena

Posted on the | Last edited on
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
prontera,164,174,3  script  Coin Trader::cointrader 4_M_04,{
 
    /*-----------------------------------------------------
    Script
    -----------------------------------------------------*/
    mes .npc_name$;
    mes "Good "+ (isday() ? "day" : "evening") +", "+ strcharinfo(0) +"! "+
        "What can I help you with?";
    cutin "valen_arle01", 2;
    next;
 
    switch (select(implode(.main_menu$, ":"))) {
        // Build coin menu options
        for (.@i = 0; .@i < getarraysize(.coin_id); .@i += 2) {
            .@options$[.@i / 2] = getitemname(.coin_id[.@i]);
        }
        
        mes .npc_name$;
        
        case 1:
            mes "Which coin would you like to purchase?";
            next;
            
            menu implode(.@options$, ":"), -;
            .@index = (@menu - 1) * 2;
            
            mes .npc_name$;
            mes "How many "+ getitemname(.coin_id[.@index]) +" do you want to buy?";
            next;
            
            input .@amount;
            .@total = .coin_id[.@index + 1] * .@amount;
            
            mes .npc_name$;
            
            // Verify zeny
            if (Zeny < .@total) {
                mes "Sorry, but you need "+ .@total +"z to purchase "+ .@amount +" "+ getitemname(.coin_id[.@index]) +".";
                cutin "valen_arle04", 2;
                break;
            }
            
            mes "Okay, here you are! You've received "+ .@amount +" "+ getitemname(.coin_id[.@index]) +" "+
                "in exchange for "+ .@total +"z.";
            cutin "valen_arle02", 2;
                
            Zeny -= .@total;
            getitem .coin_id[.@index], .@amount;
            
            break;
            
        case 2:
            mes "Which coin would you like to exchange?";
            next;
            
            menu implode(.@options$, ":"), -;
            .@index = (@menu - 1) * 2;
            
            mes .npc_name$;
            mes "How many "+ getitemname(.coin_id[.@index]) +" do you want trade in?";
            next;
            
            input .@amount;
            .@total = .coin_id[.@index + 1] * .@amount;
            
            mes .npc_name$;
            
            // Verify coins
            if (countitem(.coin_id[.@index]) < .@amount) {
                mes "Sorry, but you don't have "+ .@amount +" "+ getitemname(.coin_id[.@index]) +". "+
                    "Come back when you do!";
                cutin "valen_arle04", 2;
                break;
            }
            
            mes "Okay, here you are! You've received "+ .@total +"z in exchange for "+ .@amount +" "+
                getitemname(.coin_id[.@index]) +".";
            cutin "valen_arle02", 2;
                
            delitem .coin_id[.@index], .@amount;
            Zeny += .@total;
            break;
            
        case 3:
            mes "Please select the type of coin you are trading in.";
            next;
            
            menu implode(.@options$, ":"), -;
            .@in = (@menu - 1) * 2;
            
            mes .npc_name$;
            mes "How many "+ getitemname(.coin_id[.@in]) +" will be converted?";
            next;
            
            input .@amount;
            
            mes .npc_name$;
            
            // Negate divison by zero
            if (!.@amount) {
                mes "Sorry, but you cannot convert nothing.";
                cutin "valen_arle04", 2;
                break;
            }
            
            // Verify coins
            if (countitem(.coin_id[.@in]) < .@amount) {
                mes "Sorry, but you do not have "+ .@amount +" "+ getitemname(.coin_id[.@in]) +". "+
                    "Come back when you do!";
                cutin "valen_arle04", 2;
                break;
            }
            
            mes "Which type of coin do you want in exchange?";
            next;
            
            menu implode(.@options$, ":"), -;
            .@out = (@menu - 1) * 2;
            
            // Calculate values
            .@in_value = .coin_id[.@in + 1];
            .@out_value = .coin_id[.@out + 1];
            .@total = .@amount * .@in_value / .@out_value;
            .@remainder = .@amount * .@in_value % .@out_value;
            .@rate = .@out_value / .@in_value;
            
            mes .npc_name$;
            
            // Verify conversion
            if (.@amount * .@in_value < .@out_value) {
                mes "Sorry, but you need at least "+ .@rate +" "+ getitemname(.coin_id[.@in]) +" to complete this conversion.";
                cutin "valen_arle04", 2;
                break;
            }
            
            // Negate surplus coin loss
            if (.@remainder) {
                mes "Sorry, but conversion of "+ getitemname(.coin_id[.@in]) +" into "+ getitemname(.coin_id[.@out]) +" "+
                "can only be done in multiples of "+ .@rate +".";
                cutin "valen_arle04", 2;
                break;
            }
            
            mes "Okay, here you are! You've received "+ .@total +" "+ getitemname(.coin_id[.@out]) +" in exchange for "+
                .@amount +" "+ getitemname(.coin_id[.@in]) +".";
            cutin "valen_arle02", 2;
            
            delitem .coin_id[.@in], .@amount;
            getitem .coin_id[.@out], .@total;
            break;
        
        case 4:
            // Build exchange rates
            for (.@i = 0; .@i < getarraysize(.coin_id); .@i += 2) {
                mes getitemname(.coin_id[.@i]) +": "+ .coin_id[.@i + 1] +"z";
            }
            
            break;
    }
    
    close2;
    cutin "", 255;
    end;
 
    
    /*-----------------------------------------------------
    Configuration
    -----------------------------------------------------*/
    OnInit:
        .npc_name$ = "[Coin Trader]";
    
        // Coin item constant/ID, value in zeny
        setarray .coin_id[0],   Copper_Coin, 1000,
                                Silver_Coin, 10000,
                                Gold_Coin, 100000,
                                White_Gold_Coin, 1000000,
                                Mithril_Coin, 10000000;
                
        setarray .main_menu$[0],    "Purchase coins",
                                    "Exchange coins",
                                    "Convert coins",
                                    "Rates";
                                
        end;
 
}
Viewed 1163 times, submitted by mumbles.