summaryrefslogtreecommitdiff
path: root/npc/functions/vault.txt
blob: 17f0457b9b589fa00082def70e082761a4a21a4d (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// TODO: create a Vault hercules plugin for native support

// NOTE: no script other than the functions in this file should EVER access
//       ##VAULT[] or the vault-bound variables

/**
 * Gets the Vault account ID of the provided or attached player.
 * If the server does not use Vault, it returns a virtual Vault ID.
 *
 * Example:
 *     getvaultid("player name");
 *
 * @param 0? - char name / account id (defaults to attached player)
 * @return the Vault ID
 */
function	script	getvaultid	{
    if (SERVER_USES_VAULT) {
        // we dereference the variable to avoid accidental assignment
        return 0+ getvariableofpc(##VAULT[0], nameid2id(getarg(0, "")));
    } else {
        return nameid2id(getarg(0, ""));
    }
}

/**
 * gets a (fake) vault account-bound variable.
 * right now these are map-server global variables so they should be used
 * sparingly
 *
 * Example:
 *     set(getvaultvar(VAR$), "foo bar");
 *
 * @param 0 - a variable name without prefix
 * @param 1? - char name / account id (defaults to attached player)
 * @return a reference to the variable
 */
function	script	getvaultvar	{
    if ((getdatatype(getarg(0)) & DATATYPE_VAR) == 0) {
        consolemes(CONSOLEMES_ERROR, "getvaultvar: first argument should be a variable");
        end;
    }

    .@var$ = data_to_string(getarg(0));

    if (charat(.@var$, 0) == "." || charat(.@var$, 0) == "@" ||
        charat(.@var$, 0) == "$" || charat(.@var$, 0) == "#") {
        consolemes(CONSOLEMES_ERROR, "getvaultvar: the variable must be unprefixed");
        end;
    }

    if (SERVER_USES_VAULT) {
        .@vault = getvaultid(getarg(1, ""));
        return getd(sprintf("$VAULT_%s[%i]", .@var$, .@vault));
    } else {
        return getvariableofpc(getd(sprintf("##%s", .@var$)), nameid2id(getarg(1, "")));
    }
}

/**
 * sets a (fake) vault account-bound variable.
 * right now these are map-server global variables so they should be used
 * sparingly
 *
 * Example:
 *     setvaultvar(FOO$, "bar");
 *
 * @param 0 - a variable name without prefix
 * @param 1 - the value to set
 * @param 2? - char name / account id (defaults to attached player)
 * @return a reference to the variable
 */
function	script	setvaultvar	{
    return set(getvaultvar(getarg(0), getarg(2, "")), getarg(1));
}

// This function comes from Moubootaur Legends
// getvaultexp(Exp)
function	script	getvaultexp	{
    .@exp=getarg(0);
    // Illegal, do nothing
    if (.@exp > 100)
        return;
    // Illegal, do nothing
    if (!SERVER_USES_VAULT)
        return;
    // Assign the Experience
    if (getvaultid()) {
        ##VAULT_EXP+=.@exp;
        consolemes(CONSOLEMES_INFO,
                 "Granting %d Soul Exp to %d under the rEvolution's authority.",
                 .@exp, getvaultid());
    }
    return;
}

// This function comes from Moubootaur Legends
// MirrorLakeSendTo(World, Lake)
function	script	MirrorLakeSendTo	{
    .@w=getarg(0);
    .@t=getarg(1);
    // Illegal, do nothing
    if (!SERVER_USES_VAULT)
        return;
    ##VAULT_GOTO=.@w;
    ##VAULT_MLTO=.@t;
    closeclientdialog;
    dispbottom l("Darkness fills your vision...");
    sleep2(1000);
    kick(getcharid(3), 7); // 7 is not a valid kick reason
    //atcommand("@kick "+strcharinfo(0));
    end;
}

/**
 * handles Vault hooks on player login
 */
-	script	VaultHandler	NPC_HIDDEN,{
    public function OnDualLogin {
        .@toKick$ = strcharinfo(PC_NAME, "", getarg(0, 0));

        if (.@toKick$ != "") {
            .@msg$ = sprintf("Kicking player %s (Vault dual-login)", .@toKick$);
            consolemes(CONSOLEMES_INFO, .@msg$); // log this
            dispbottom(.@msg$); // tell the player

            return kick(.@toKick$, 2); // reason 2 is dual-login
        }

        return false;
    }

OnInit:
    if (SERVER_USES_VAULT) {
        "playerCache"::addVaultHandler("OnDualLogin");
    }
}