summaryrefslogtreecommitdiff
path: root/npc/commands/zeny.txt
blob: 560c7a948d6ec73442342e07ec5b5cc24be0b24a (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
// @esp atcommand
// changes the number of Esperin
//
// group lv: 3
// group char lv: 99
// log: True
//
// usage:
//    @esp <delta>
//    #esp "char" <delta>
//
// example:
//    @esp +5
//    @esp -5
//    @esp +++

-	script	@esp	32767,{
    end;

OnCall:
    .@delta$ = .@atcmd_parameters$[0];

    if (startswith(.@delta$, "--"))
    {
        Zeny = 0;
        if (.@delta$ == "---")
        {
            #MerchantBank = 0;
        }
    }
    else if (startswith(.@delta$, "++"))
    {
        Zeny = 0x7FFFFFFE;
        if (.@delta$ == "+++")
        {
            #MerchantBank = 0x7FFFFFFF;
        }
    }
    else
    {
        .@d = atoi(.@delta$);
        if (.@d < 0)
        {
            .@a = Zeny + .@d; // The amount of zeny remaining after
            if (.@a < 0) // If we can't remove that much zeny, try removing from bank too
            {
                Zeny = 0;
                .@b = #MerchantBank + .@a; // amount remaining in bank after
                if (.@b < 0)
                {
                    #MerchantBank = 0;
                }
                else
                {
                    #MerchantBank += .@a;
                }
            }
            else // We can remove that much zeny
            {
                Zeny += .@d;
            }
        }
        else
        {
            .@a = Zeny + .@d; // The amount of zeny after
            if (.@a < 0 || .@a >= 0x7FFFFFFE) // If we can't add that much zeny, try adding to bank
            {
                .@c = .@d - (.@a - Zeny); // the amount to put in bank
                Zeny = 0x7FFFFFFE;
                .@b = #MerchantBank + .@c; // amout in bank after
                if (.@b < 0 || .@b == 0x7FFFFFFF)
                {
                    #MerchantBank = 0x7FFFFFFF;
                }
                else
                {
                    #MerchantBank += .@c;
                }
            }
            else // We can add that much zeny
            {
                Zeny += .@d;
            }
        }
    }
    end;

OnInit:
    bindatcmd "esp", "@esp::OnCall", 3, 99, 1;
}