summaryrefslogtreecommitdiff
path: root/npc/033-5/shop.txt
blob: edcc72d251bf06a9d45804de493887ee9669617f (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
// Moubootaur Legends Script
// Author:
//    Jesusalva
// Description:
//  General Shop (ML Consumables)

033-5,39,26,0	script	Resourceful Seller	NPC_PLAYER,{
    mesn;
    mesq l("Hey, I can sell you any consumable which can be sold, as long that you know its name! Try to be [@@=createitems|specific@@], as I'll only show the few first results!");
    next;
	mes l("What item are you looking for?");
	input(.@name$);
	.@qty = searchitem(.@matches[0], .@name$);
    if (.@qty < 1) {
        mes l("I don't know any item by that name.");
    }
    .@menu$ = "Nothing";
	mes l("I found some items:");
	for (.@i = 0; .@i < .@qty; ++.@i) {
        // Check if this item is consumable
        if (getiteminfo(.@matches[.@i], ITEMINFO_TYPE) != IT_HEALING &&
            getiteminfo(.@matches[.@i], ITEMINFO_TYPE) != IT_USABLE &&
            getiteminfo(.@matches[.@i], ITEMINFO_TYPE) != IT_AMMO) {
            .@matches[.@i] = 0;
            continue;
        }
        // Check if this item can be acquired
        if (getiteminfo(.@matches[.@i], ITEMINFO_BUYPRICE) < 1 ||
            getiteminfo(.@matches[.@i], ITEMINFO_TRADE) > 0) {
            .@matches[.@i] = 0;
            continue;
        }

		//Display name (eg: "Apple[0]")
		mes l("%s [%d] for %s GP", getitemlink(.@matches[.@i]),
                                   .@matches[.@i],
                                   fnum(getiteminfo(.@matches[.@i], ITEMINFO_BUYPRICE)));
    }
	for (.@i = 0; .@i < .@qty; ++.@i) {
        .@menu$ += ":";
        if (.@matches[.@i] > 0)
            .@menu$ += getitemname(.@matches[.@i]);
    }
    next;
    mesn;
    mesq l("So, what do you want to buy?");
    next;
    select(.@menu$);
    .@idx = @menu - 2;
    if (.@idx < 0)
        close;
    .@it = .@matches[.@idx];
    .@price = getiteminfo(.@it, ITEMINFO_BUYPRICE);
    .@max = Zeny / .@price;
    if (.@max < 1) {
        mesn;
        mesc l("You cannot afford that."), 1;
        close;
    }
    mesn;
    mesq l("%s, I see! How many? (0-%s)", getitemlink(.@it), fnum(.@max));
    input(.@cur, 0, .@max);
    if (.@cur > 0 && .@cur <= .@max) {
        Zeny -= .@cur * .@price;
        getitem(.@it, .@cur);
    }
    mes "";
    mesn;
    mesq l("Pleasure doing business with you!");
    close;

OnInit:
    .@npcId = getnpcid(.name$);
    setunitdata(.@npcId, UDT_HEADTOP, NPCEyes);
    setunitdata(.@npcId, UDT_HEADMIDDLE, SilkRobe);
    //setunitdata(.@npcId, UDT_HEADBOTTOM, LeatherTrousers); // FIXME: LeatherTrousers are BROKEN!
    setunitdata(.@npcId, UDT_HAIRSTYLE, 26);
    setunitdata(.@npcId, UDT_HAIRCOLOR, 2);
    end;
}