summaryrefslogtreecommitdiff
path: root/npc/commands/zeny.txt
blob: 77f6d2dea8d12c4760352873eaf1d83987a0a2b4 (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
94
95
96
97
98
// @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 (debug && startswith(.@delta$, "--"))
    {
        Zeny = 0;
        if (.@delta$ == "---")
        {
            BankVault = 0;
        }
    }
    else if (debug && (startswith(.@delta$, "++") || .@delta$ == ""))
    {
        Zeny = MAX_ZENY;
        if (.@delta$ == "+++")
        {
            BankVault = MAX_BANK_ZENY;
        }
    }
    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 = BankVault + .@a; // amount remaining in bank after
                if (.@b < 0)
                {
                    BankVault = 0;
                }
                else
                {
                    BankVault += .@a;
                }
            }
            else // We can remove that much zeny
            {
                Zeny += .@d;
            }
        }
        else
        {
            .@a = Zeny + .@d; // The amount of zeny after
            if (.@a < 0 || .@a >= MAX_ZENY) // If we can't add that much zeny, try adding to bank
            {
                .@c = .@d - (.@a - Zeny); // the amount to put in bank
                Zeny = MAX_ZENY;
                .@b = BankVault + .@c; // amout in bank after
                if (.@b < 0 || .@b == MAX_BANK_ZENY)
                {
                    BankVault = MAX_BANK_ZENY;
                }
                else
                {
                    BankVault += .@c;
                }
            }
            else // We can add that much zeny
            {
                Zeny += .@d;
            }
        }
    }
    end;

OnInit:
    if (debug > 0)
    {
        bindatcmd "e", "@esp::OnCall", 0, 99, 0;
        bindatcmd "esp", "@esp::OnCall", 0, 99, 0;
        bindatcmd "money", "@esp::OnCall", 0, 99, 0;
        end;
    }

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