viewing paste topic/4880- own-points_seller | 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
prontera,0,0,0  shop    market2#hidden  -1,501:1000
prontera,156,172,5  script  market  100,{
    dispbottom "You currently have "+ getd(.var$) +" points.";
    callshop .shopname$, 1;
    end;
OnInit:
    function    addshopitem {
        npcshopdelitem .shopname$, 501;
        .@count = getargcount();
        for ( .@i = 0; .@i < .@count; .@i++ ) {
            if ( .@i % 2 == 0 )
                .itemid[ .@i /2 ] = getarg( .@i );
            else {
                .itemcost[ .@i /2 ] = getarg( .@i );
                npcshopadditem .shopname$, .itemid[ .@i /2 ], getarg( .@i );
            }
        }
        
    }
//  ----- Configuration ------
    .shopname$ = "market2#hidden"; // shop name that match the 1st line in this script
    .var$ = "CUSTOM_POINTS"; // variable name for this shop
    addshopitem // adds shop items here
        512,10,
        513,20,
        514,30,
        515,40,
        516,50,
        607,1;
//  -------------------------
    .itemsize = getarraysize( .itemid );
    for ( .@i = 0; .@i < .itemsize; .@i++ )
        setd ".item"+ .itemid[.@i] +"cost", .itemcost[.@i];
    npcshopattach .shopname$;
    end;
OnBuyItem:
    if ( !@bought_quantity ) end;
    .@size = getarraysize( @bought_nameid );
    for ( .@i = 0; .@i < .@size; .@i++ )
        .@itemcost = .@itemcost + getd( ".item"+ @bought_nameid[.@i] +"cost" ) * @bought_quantity[.@i];
    if ( .@itemcost > getd(.var$) ) {
        mes "you don't have enough points to buy them";
        close;
    }
    if ( !checkweight2( @bought_nameid, @bought_quantity ) ) {
        mes "you can't carry all these items !";
        close;
    }
    setd .var$, getd(.var$) - .@itemcost;
    for ( .@i = 0; .@i < .@size; .@i++ )
        getitem @bought_nameid[.@i], @bought_quantity[.@i];
    end;
}
Viewed 1395 times, submitted by AnnieRuru.