summaryrefslogtreecommitdiff
path: root/doc/sample/npc_dynamic_shop.txt
blob: 1e4ac77e40529acd994ebb3b593cfc8b90b8a61e (plain) (blame)
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
//===== Hercules Script ======================================
//= Sample: Dynamic Shop
//===== By: ==================================================
//= Hercules Dev Team
//===== Current Version: =====================================
//= 20131225
//===== Description: =========================================
//= Contains commands needed for a dynamic shop.
//============================================================

// Dummy shop to insert items into:
-	shop	dyn_shop1	-1,501:50.

prontera,181,200,4	script	Dynamic Shop	2_F_MAGICMASTER,{
	callshop "dyn_shop1",0;
	npcshopattach "dyn_shop1";
	end;

OnSellItem:
	for (.@i = 0; .@i < getarraysize(@sold_nameid); ++.@i) {
		if(countitem(@sold_nameid[.@i]) < @sold_quantity[.@i] || @sold_quantity[.@i] <= 0) {
			mes "omgh4x!";
			close;
		} else if (@sold_nameid[.@i] == Red_Potion) {
			delitem Red_Potion, @sold_quantity[.@i];
			$@rpotsleft += @sold_quantity[.@i];
			Zeny += @sold_quantity[.@i]*20;
		} else if (@sold_nameid[.@i] == Orange_Potion){
			delitem Orange_Potion, @sold_quantity[.@i];
			$@opotsleft += @sold_quantity[.@i];
			Zeny += @sold_quantity[.@i]*100;
		} else {
			mes "Sorry, I don't need your items.";
			close;
		}
	}
	deletearray @sold_quantity, getarraysize(@sold_quantity);
	deletearray @sold_nameid, getarraysize(@sold_nameid);
	mes "Deal completed.";
	close;

OnBuyItem:
	for (.@i = 0; .@i < getarraysize(@bought_nameid); ++.@i) {
		if (@bought_quantity[.@i] <= 0) {
			mes "omgh4x!";
			close;
		} else if (@bought_nameid[.@i] == Red_Potion) {
			if (@bought_quantity[.@i] > $@rpotsleft) {
				if($@rpotsleft > 0) {
					@bought_quantity[.@i] = $@rpotsleft;
				} else {
					mes "We are out of red potions!";
					close;
				}
			}
			if(Zeny >= 40*@bought_quantity[.@i]) {
				Zeny -= 40*@bought_quantity[.@i];
				getitem Red_Potion, @bought_quantity[.@i];
				$@rpotsleft -= @bought_quantity[.@i];
			} else {
				mes "You have insufficient cash.";
				close;
			}
		} else /*if (@bought_nameid[.@i] == Orange_Potion)*/ {
			if(@bought_quantity[.@i] > $@opotsleft) {
				if($@opotsleft > 0) {
					@bought_quantity[.@i] = $@opotsleft;
				} else {
					mes "We are out of orange potions!";
					close;
				}
			}
			if(Zeny >= 200*@bought_quantity[.@i]) {
				Zeny -= 200*@bought_quantity[.@i];
				getitem Orange_Potion, @bought_quantity[.@i];
				$@opotsleft -= @bought_quantity[.@i];
			} else {
				mes "You have insufficient cash.";
				close;
			}
		}
	}
	deletearray @bought_quantity, getarraysize(@bought_quantity);
	deletearray @bought_nameid, getarraysize(@bought_nameid);
	mes "Trade done.";
	close;

OnInit:
	npcshopitem "dyn_shop1", Red_Potion, 40, Orange_Potion, 200;
	$@rpotsleft = 10;
	$@opotsleft = 10;
	end;
}