Skip to content

Commit 980c373

Browse files
committed
Plugin: Vault
1 parent ba4646c commit 980c373

File tree

5 files changed

+630
-1
lines changed

5 files changed

+630
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ https://github.com/nwnxee/unified/compare/build8193.34...HEAD
1111
- N/A
1212

1313
##### New Plugins
14-
- N/A
14+
- Vault: a plugin that provides various character/servervault functions.
1515

1616
##### New NWScript Functions
1717
- N/A

Plugins/Vault/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
add_plugin(Vault
2+
"Vault.cpp")

Plugins/Vault/NWScript/nwnx_vault.nss

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/// @addtogroup vault Vault
2+
/// @brief Provides various character/servervault related functions.
3+
/// @{
4+
/// @file nwnx_vault.nss
5+
#include "nwnx"
6+
7+
const string NWNX_Vault = "NWNX_Vault"; ///< @private
8+
9+
/// @brief A structure containing vault character data.
10+
struct NWNX_Vault_Character
11+
{
12+
string sFileName;
13+
string sUUID; ///< May be empty
14+
15+
string sFirstName;
16+
string sLastName;
17+
18+
int nPortraitId;
19+
string sPortrait;
20+
21+
int nClass1Id; ///< Will be CLASS_TYPE_INVALID on error.
22+
int nClass1Level;
23+
int nClass2Id; ///< Will be CLASS_TYPE_INVALID if no second class.
24+
int nClass2Level;
25+
int nClass3Id; ///< Will be CLASS_TYPE_INVALID if no third class.
26+
int nClass3Level;
27+
28+
int nRace;
29+
int nGender;
30+
int nExperience;
31+
int nGold;
32+
};
33+
34+
/// @brief Get the number of characters in oPlayer's vault.
35+
/// @param oPlayer The player.
36+
/// @return The number of characters in the vault or 0 on error.
37+
int NWNX_Vault_GetVaultSize(object oPlayer);
38+
39+
40+
/// @brief Load the character vault of oPlayer.
41+
/// @note Will overwrite a previously loaded vault. Will return 0 for (Player)DMs.
42+
/// @param oPlayer The player.
43+
/// @return The number of characters in the vault or 0 on error.
44+
int NWNX_Vault_LoadVault(object oPlayer);
45+
46+
/// @brief Get the data of the character at nIndex in the last loaded vault.
47+
/// @param nIndex The index.
48+
/// @return A NWNX_Vault_Character struct.
49+
struct NWNX_Vault_Character NWNX_Vault_GetCharacterData(int nIndex);
50+
51+
/// @brief Switch oPlayer's character to another one from their vault.
52+
/// @warning THIS FUNCTION IS EXPERIMENTAL, BACKUP YOUR SERVERVAULT BEFORE EVEN ATTEMPTING TO USE THIS.
53+
/// @warning Do not switch between characters with the same UUID, bad things will happen.
54+
/// @note If something goes catastrophically wrong the player will be disconnected.
55+
/// @param oPlayer The player.
56+
/// @param sBICFileName The bic filename without .bic.
57+
/// @return The new creature object or OBJECT_INVALID on error.
58+
object NWNX_Vault_SwitchCharacter(object oPlayer, string sBICFileName);
59+
60+
/// @}
61+
62+
int NWNX_Vault_GetVaultSize(object oPlayer)
63+
{
64+
NWNX_PushArgumentObject(oPlayer);
65+
NWNX_CallFunction(NWNX_Vault, "GetVaultSize");
66+
67+
return NWNX_GetReturnValueInt();
68+
}
69+
70+
int NWNX_Vault_LoadVault(object oPlayer)
71+
{
72+
NWNX_PushArgumentObject(oPlayer);
73+
NWNX_CallFunction(NWNX_Vault, "LoadVault");
74+
75+
return NWNX_GetReturnValueInt();
76+
}
77+
78+
struct NWNX_Vault_Character NWNX_Vault_GetCharacterData(int nIndex)
79+
{
80+
NWNX_PushArgumentInt(nIndex);
81+
NWNX_CallFunction(NWNX_Vault, "GetCharacterData");
82+
83+
struct NWNX_Vault_Character str;
84+
str.nGold = NWNX_GetReturnValueInt();
85+
str.nExperience = NWNX_GetReturnValueInt();
86+
str.nGender = NWNX_GetReturnValueInt();
87+
str.nRace = NWNX_GetReturnValueInt();
88+
str.nClass3Level = NWNX_GetReturnValueInt();
89+
str.nClass3Id = NWNX_GetReturnValueInt();
90+
str.nClass2Level = NWNX_GetReturnValueInt();
91+
str.nClass2Id = NWNX_GetReturnValueInt();
92+
str.nClass1Level = NWNX_GetReturnValueInt();
93+
str.nClass1Id = NWNX_GetReturnValueInt();
94+
str.sPortrait = NWNX_GetReturnValueString();
95+
str.nPortraitId = NWNX_GetReturnValueInt();
96+
str.sLastName = NWNX_GetReturnValueString();
97+
str.sFirstName = NWNX_GetReturnValueString();
98+
str.sUUID = NWNX_GetReturnValueString();
99+
str.sFileName = NWNX_GetReturnValueString();
100+
101+
return str;
102+
}
103+
104+
object NWNX_Vault_SwitchCharacter(object oPlayer, string sBICFileName)
105+
{
106+
NWNX_PushArgumentString(sBICFileName);
107+
NWNX_PushArgumentObject(oPlayer);
108+
NWNX_CallFunction(NWNX_Vault, "SwitchCharacter");
109+
return NWNX_GetReturnValueObject();
110+
}

Plugins/Vault/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@page vault Readme
2+
@ingroup vault
3+
4+
Provides various character/servervault functions.
5+
6+
## NWNX_Vault_SwitchCharacter Notes
7+
8+
### Before even attempting to do anything with this function, make sure to (regularly) backup your servervault. You have been warned.
9+
10+
Things of note:
11+
12+
* **Regularly backup your servervault.**
13+
* Disable the NWNX_TWEAKS_TURD_BY_CDKEY tweak, NWNX_Vault will associate TURDs by CDKey+UUID/CharacterName instead.
14+
* Do not switch between characters with the same UUID, bad things will happen.
15+
* Will disconnect the player if something goes catastrophically wrong.
16+
* OnClientEnter/Leave and OnAreaEnter/Exit will fire for the appropriate creature objects.
17+
* Probably has weird quirks and/or bugs.
18+
* **Regularly backup your servervault.**

0 commit comments

Comments
 (0)