viewing paste Dynamic Shop v1.2 | 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 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 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
/*
   ||======================================================||
   ||======================================================||
   ||                         NPC:                         ||
   ||======================================================||
   ||                     Dynamic Shop                     ||
   ||======================================================||
   ||                    Version 1.2                       ||
   ||======================================================||
   ||                   Made by Streiker                   ||
   ||======================================================||
   ||                       Updates:                       ||
   ||                     (5 latests)                      ||
   ||                                                      ||
   || Version 1.1.1:                                       ||
   ||              Fixed: uploaded the wrong npc!          ||
   ||                                                      ||
   || Version 1.1.2:                                       ||
   ||              Fixed: some small mistakes.             ||
   ||              Changed the default npc id.             ||
   ||                                                      ||
   || Version 1.1.3:                                       ||
   ||              Fixed: items receive.                   ||
   ||              Fixed: while -> do while.               ||
   ||                                                      ||
   || Version 1.1.4:                                       ||
   ||              Changed: the prize is show as "0".      ||
   ||              Fixed: adding items.                    ||
   ||                                                      ||
   || Version 1.2:                                         ||
   ||             Added: items and variables in 1 item.    ||
   ||             Added: weight check.                     ||
   ||             Added: items preview.                    ||
   ||======================================================||
   ||                     Description:                     ||
   ||                                                      ||
   || A dynamic shop, allow more than 1 variables and items||
   ||======================================================||
   ||                 Additional Comments:                 ||
   ||                                                      ||
   || To Do: GM menu (add, delete...)                      ||
   || SQL variables selection.                             ||
   ||======================================================||
   ||======================================================||
 
    How to add items?
 
    Read the information of the functions and add items.
 
    Rembember I don't speak english, so don't criticise me, I did all I can!
 
    This script requires my functions collection!
*/
 
-   shop    dshop   -1,501:300
 
 
-   script  Dynamic_Shop_Conf   -1,{
 
    function Add_Item ;
    function Add_Items ;
    function Add_Vars ;
 
OnInit:
 
    set $@DS_n$, "Dynamic Shop";    // Name of the npc.
 
    set $@DS_id, 410;       // ID of the npc.
 
    setnpcdisplay ( "Dynamic Shop##DZ", $@DS_id ) ;
    // I didn't put the setnpcdisplay ("name") because the last time I checked it didn't work.
    // Maybe i've used it wrong X_x.
/*
    Examples:
    // Add_Item <id>, <price to show>.
    Add_Item ( 501, 1 ) ;
    // Add_Items <id>, <amount>.
    Add_Items ( 512, 5, 513, 3 ) ;
    // Add_Vars <"variable">, <"name to show">, <amount>.
    Add_Vars ( "#CASHPOINTS", "Cash Points", 1, "Zeny", "Zenys", 500;
*/
    npcshopitem "dshop", $@ds_1_1, $@ds_2_1 ;
    for ( set .@a, 2; .@a <= $@ds_it ; set .@a, .@a + 1 )
        npcshopadditem "dshop", getd ( "$@ds_1_"+ .@a ), getd ( "$@ds_2_"+ .@a ) ;
    end ;
 
    function Add_Item {
 
        set $@ds_it, $@ds_it + 1;
        setd "$@ds_1_"+ $@ds_it, getarg ( 0 );
        setd "$@ds_2_"+ $@ds_it, getarg ( 1 );
        return ;
 
    }
 
    function Add_Items {
 
        while ( getarg ( .@a, 0 ) != 0 ) {
            set .@b, .@b + 1;
            setd "$@ds_3_"+ $@ds_it +"_"+ .@b, getarg ( .@a );
            setd "$@ds_4_"+ $@ds_it +"_"+ .@b, getarg ( .@a + 1 );
            set .@a, .@a + 2;
        }
        setd "$@ds_5_"+ $@ds_it, .@b;
        return ;
 
    }
 
    function Add_Vars {
 
        while ( getarg ( .@a, "" ) != "" ) {
            set .@b, .@b + 1;
            setd "$@ds_6_"+ $@ds_it +"_"+ .@b +"$", getarg ( .@a );
            setd "$@ds_7_"+ $@ds_it +"_"+ .@b +"$", getarg ( .@a + 1 );
            setd "$@ds_8_"+ $@ds_it +"_"+ .@b, getarg ( .@a + 2 );
            set .@a, .@a + 3;
        }
        setd "$@ds_9_"+ $@ds_it, .@b;
        return ;
 
    }
 
 
}
 
prontera,148,167,5  script  Dynamic Shop#DZ::dyn_shop   410,{
 
    if ( ! $@DS_id ) donpcevent "Dynamic_Shop_Conf::OnInit" ;
    while ( 1 ) {
        set .@a$,"^2b86b5"+ $@DS_n$ +"^000000";
        mes .@a$;
        mes "Hi "+ strcharinfo ( 0 ) +", welcome to this shop.";
        mes "Remember I use different conditions of payment depending of the item.";
        mes "Would you like to buy or check these conditions?";
        next ;
        if ( select ( "Buy items", "Check conditions", "Preview items", "^911b1bExit^000000" ) == 1 ) {
            close2 ;
            callshop "dshop", 1 ;
            npcshopattach "dshop" ;
            end ;
        }
        mes .@a$;
        if ( @menu == 4 ) {
            mes "Have a nice day.";
            close ;
        }
        if ( @menu == 3 ) {
            mes "Which item do you want to preview?";
            deletearray .@q ;
            set .@m$, "";
            for ( set .@m, 1; .@m <= $@ds_it ; set .@m, .@m + 1 ) {
                set .@o, getiteminfo ( getd ( "$@ds_1_"+ .@m ), 5 );    // equip position.
                set .@p, getiteminfo ( getd ( "$@ds_1_"+ .@m ), 11 );   // view id.
                if ( ( .@o >= 0 ) && ( .@p ) ) {
                    set .@m$, .@m$ + getitemname ( getd ( "$@ds_1_"+ .@m ) ) +":";
                    set .@q[getarraysize ( .@q )], getd ( "$@ds_1_"+ .@m );
                }
                sleep2 ( ! ( .@m % 100 ) ) ;
            }
            set .@n, select ( .@m$ + ":^911b1bBack^000000" ) ;
            if ( .@n <= $@ds_it )
                callfunc "show_hat", getd ( "$@ds_1_"+ .@n ) ;
        }
        if ( @menu == 2 )
            for ( set .@a, 1; .@a <= $@ds_it ; set .@a, .@a + 1 ) {
                mes "^8627bc--- ^509343"+ getitemname ( getd ( "$@ds_1_"+ .@a ) ) +"^000000 ^8627bc---";
                while ( set ( .@b, .@b + 1 ) <= getd ( "$@ds_5_"+ .@a ) )
                    mes "^2731fd"+ getd ( "$@ds_4_"+ .@a +"_"+ .@b ) +" "+ getitemname ( getd ( "$@ds_3_"+ .@a +"_"+ .@b ) );
                set .@b, 0;
                while ( set ( .@b, .@b + 1 ) <= getd ( "$@ds_9_"+ .@a ) )
                    mes "^bc2727"+ getd ( "$@ds_8_"+ .@a +"_"+ .@b ) +" "+ getd ( "$@ds_7_"+ .@a +"_"+ .@b +"$" );
                sleep2 ( ! ( .@a % 100 ) ) ;
                mes " ";
                set .@b, 0;
            }
        next ;
    }
 
OnBuyItem:
 
    for ( set .@a, 0; .@a < getarraysize ( @bought_nameid ) ; set .@a, .@a + 1 )
        do {
            set .@b, .@b + 1;
            if ( getd ( "$@ds_1_"+ .@b ) == @bought_nameid[.@a] ) {
                set .@w, .@w + ( getiteminfo ( getd ( "$@ds_1_"+ .@b ), 6 ) * @bought_quantity[.@a] );
                while ( set ( .@c, .@c + 1 ) <= getd ( "$@ds_5_"+ .@b ) ) {
                    set .@d, countitem ( getd ( "$@ds_3_"+ .@b +"_"+ .@c ) );
                    if ( .@d < ( getd ( "$@ds_4_"+ .@b +"_"+ .@c ) * @bought_quantity[.@a] ) ) {
                        dispbottom "You don't have  "+ getd ( "$@ds_4_"+ .@b +"_"+ .@c ) +" "+ getitemname ( getd ( "$@ds_3_"+ .@b +"_"+ .@c ) );
                        set .@e, .@e + 1;
                    }
                }
                set .@c, 0;
                while ( set ( .@c, .@c + 1 ) <= getd ( "$@ds_9_"+ .@b ) ) {
                    set .@d, getd ( getd ( "$@ds_6_"+ .@b +"_"+ .@c +"$" ) );
                    if ( .@d < ( getd ( "$@ds_8_"+ .@b +"_"+ .@c ) * @bought_quantity[.@a] ) ) {
                        dispbottom "You don't have "+ getd ( "$@ds_6_"+ .@b +"_"+ .@c ) +" "+ getd ( "$@ds_7_"+ .@b +"_"+ .@c +"$" );
                        set .@e, .@e + 1;
                    }
                }
                if ( MaxWeight < ( Weight + .@w ) ) {
                    dispbottom "You have overweight for carry item "+ getitemname ( getd ( "$@ds_1_"+ .@a ) ) +".";
                    set .@e, .@e + 1;
                    // for save space for any other item that support your weight...
                    set .@w, .@w - ( getiteminfo ( getd ( "$@ds_1_"+ .@b ), 6 ) * @bought_quantity[.@a] );
                }
                if ( ! ( .@e ) ) {
                    set .@g[getarraysize ( .@g )], .@a;
                    set .@l[getarraysize ( .@l )], .@b;
                }
            }
            set .@e, 0;
            sleep2 ( ! ( .@b % 100 ) ) ;
        } while ( .@b < $@ds_it ) ;
        while ( .@i <= getarraysize ( .@g ) ) {
            set .@j, .@g[.@i];
            set .@i, .@i + 1;
            if ( ! ( getd ( "$@ds_1_"+ .@l[.@i - 1] ) ) ) continue ;
            while ( set ( .@k, .@k + 1 ) <= getd ( "$@ds_5_"+ .@l[.@i - 1] ) )
                delitem getd ( "$@ds_3_"+ .@l[.@i - 1] +"_"+ .@k ), getd ( "$@ds_4_"+ .@l[.@i - 1] +"_"+ .@k ) * @bought_quantity[.@j];
            while ( set ( .@n, .@n + 1 ) <= getd ( "$@ds_9_"+ .@l[.@i - 1] ) )
                setd getd ( "$@ds_6_"+ .@l[.@i - 1] +"_"+ .@n +"$" ), getd ( getd ( "$@ds_6_"+ .@l[.@i - 1] +"_"+ .@n +"$" ) ) - ( getd ( "$@ds_8_"+ .@l[.@i - 1] +"_"+ .@n ) * @bought_quantity[.@j] );
            getitem getd ( "$@ds_1_"+ .@l[.@i - 1] ), @bought_quantity[.@j];
            sleep2 ( ! ( .@i % 100 ) ) ;
        }
    deletearray @bought_quantity ;
    deletearray @bought_nameid ;
    end ;
}
Viewed 805 times, submitted by Guest.