root/npc/sample/npc_dynamic_shop.txt @ 11

Revision 1, 2.2 kB (checked in by jinshiro, 17 years ago)
Line 
1-       shop    dyn_shop1       -1,501:50
2
3prontera,181,200,4      script  Dynamic Shop    123,{
4callshop "dyn_shop1",0;
5npcshopattach "dyn_shop1";
6end;
7
8OnSellItem:
9for(set @i, 0; @i < getarraysize(@sold_nameid); set @i, @i + 1){
10        if(countitem(@sold_nameid[@i]) < @sold_quantity[@i] && @sold_quantity[@i] <= 0){
11                mes "omgh4x!";
12                close;
13        }
14        if(@sold_nameid[@i] == 501){
15                set $@rpotsleft, $@rpotsleft + @sold_quantity[@i];
16                set Zeny, Zeny + @sold_quantity[@i]*20;
17                delitem 501, @sold_quantity[@i];
18        } else {
19                if(@sold_nameid[@i] == 502){
20                        set $@opotsleft, $@opotsleft + @sold_quantity[@i];
21                        set Zeny, Zeny + @sold_quantity[@i]*100;
22                        delitem 502, @sold_quantity[@i];
23                } else {
24                        mes "Sorry, I don't need your items.";
25                }
26        }
27}
28deletearray @sold_quantity, getarraysize(@sold_quantity);
29deletearray @sold_nameid, getarraysize(@sold_nameid);
30mes "Deal completed.";
31close;
32
33OnBuyItem:
34for(set @i, 0; @i < getarraysize(@bought_nameid); set @i, @i + 1){
35        if(@bought_quantity[@i] <= 0){
36                mes "omgh4x!";
37                end;
38        }
39        if(@bought_nameid[@i] == 501){
40                if(@bought_quantity[@i] > $@rpotsleft){
41                        if($@rpotsleft > 0){
42                                set @bought_quantity[@i], $@rpotsleft;
43                        } else {
44                                mes "We are out of red potions!";
45                                close;
46                        }
47                }
48                if(Zeny >= 40*@bought_quantity[@i]){
49                        set Zeny, Zeny - 40*@bought_quantity[@i];
50                        getitem 501, @bought_quantity[@i];
51                        set $@rpotsleft, $@rpotsleft - @bought_quantity[@i];
52                } else {
53                        mes "You have insufficient cash.";
54                        close;
55                }
56        } else {
57                if(@bought_quantity[@i] > $@opotsleft){
58                        if($@opotsleft > 0){
59                                set @bought_quantity[@i], $@opotsleft;
60                        } else {
61                                mes "We are out of orange potions!";
62                                close;
63                        }
64                }
65                if(Zeny >= 200*@bought_quantity[@i]){
66                        set Zeny, Zeny - 200*@bought_quantity[@i];
67                        getitem 502, @bought_quantity[@i];
68                        set $@opotsleft, $@opotsleft - @bought_quantity[@i];
69                } else {
70                        mes "You have insufficient cash.";
71                        close;
72                }
73        }
74}
75deletearray @bought_quantity, getarraysize(@bought_quantity);
76deletearray @bought_nameid, getarraysize(@bought_nameid);
77mes "Trade done.";
78close;
79
80OnInit:
81npcshopitem "dyn_shop1", 501,40,502,200;
82set $@rpotsleft, 10;
83set $@opotsleft, 10;
84end;
85}
Note: See TracBrowser for help on using the browser.