summaryrefslogtreecommitdiff
path: root/npc/functions/vault.txt
diff options
context:
space:
mode:
authorJesusaves <cpntb1@ymail.com>2021-04-09 11:00:49 -0300
committerJesusaves <cpntb1@ymail.com>2021-04-09 11:00:49 -0300
commit8a4bf716002a017de77fe7df301ef8e4aaf00a2e (patch)
tree4947d0b015baad639fa07133369e9a09c8a468bc /npc/functions/vault.txt
downloadserverdata-8a4bf716002a017de77fe7df301ef8e4aaf00a2e.tar.gz
serverdata-8a4bf716002a017de77fe7df301ef8e4aaf00a2e.tar.bz2
serverdata-8a4bf716002a017de77fe7df301ef8e4aaf00a2e.tar.xz
serverdata-8a4bf716002a017de77fe7df301ef8e4aaf00a2e.zip
Initial commit
Diffstat (limited to 'npc/functions/vault.txt')
-rw-r--r--npc/functions/vault.txt98
1 files changed, 98 insertions, 0 deletions
diff --git a/npc/functions/vault.txt b/npc/functions/vault.txt
new file mode 100644
index 00000000..1cfe7c99
--- /dev/null
+++ b/npc/functions/vault.txt
@@ -0,0 +1,98 @@
+// 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));
+}
+
+/**
+ * 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");
+ }
+}