Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'NWNX_Player_SetBicFileName' #1727

Open
Rapophage opened this issue Jan 19, 2024 · 3 comments
Open

Add 'NWNX_Player_SetBicFileName' #1727

Rapophage opened this issue Jan 19, 2024 · 3 comments
Labels
good first issue Good for newcomers RFE: plugin New feature or request

Comments

@Rapophage
Copy link

Rapophage commented Jan 19, 2024

Tried doing this myself, but I can't get nwnx to compile and I figured this would be something that fits right in with the player plugin.

NSS

/// @brief Sets the player's bic file's name
/// @param oPlayer The player
/// @param sBicName The filename
void NWNX_Player_SetBicFileName(object oPlayer, string sBicName);
void NWNX_Player_SetBicFileName(object oPlayer, string sBicName)
{
    string sFunc = "SetBicFileName";

    NWNX_PushArgumentString(sBicName);
    NWNX_PushArgumentObject(oPlayer);

    NWNX_CallFunction(NWNX_Player, sFunc);
}

CPP

NWNX_EXPORT ArgumentStack SetBicFileName(ArgumentStack&& args)
{
    if (auto *pPlayer = Utils::PopPlayer(args))
    {
        auto name = args.extract<std::string>();
        const uint8_t chartype = 4; // servervault subdir

        pPlayer->m_resFileName = name.c_str();
        pPlayer->m_nCharacterType = chartype;

        pPlayer->SaveServerCharacter();
    }
    return {};
}
@mtijanic mtijanic added RFE: plugin New feature or request good first issue Good for newcomers labels Jan 19, 2024
@Rapophage
Copy link
Author

Rapophage commented Jan 20, 2024

Modified the code slightly.

I managed to get nwnx to compile and I've been running some tests. The function works fine, though only when a player already has a folder in the server vault. If a new player logs in and selects a character that's in the server vault's root folder, a player folder isn't created the changed character won't save. A player folder needs to be created first, though I currently have no idea how to do that.

@Daztek
Copy link
Member

Daztek commented Jan 20, 2024

You can try adding:

CExoString sDirectory;
CNetLayerPlayerInfo *pPlayerInfo = Globals::AppManager()->m_pServerExoApp->GetNetLayer()->GetPlayerInfo(pPlayer->m_nPlayerID);
CExoString sSubdirectory = pPlayerInfo->m_lstKeys[0].sPublic;
if (Globals::AppManager()->m_pServerExoApp->GetServerInfo()->m_PersistantWorldOptions.bServerVaultByPlayerName)
    sSubdirectory = pPlayer->GetPlayerName();

if (sSubdirectory.IsEmpty())
    sDirectory.Format( "SERVERVAULT:%s", "lost+found");
else
    sDirectory.Format( "SERVERVAULT:%s", sSubdirectory.CStr());

Globals::ExoResMan()->CreateDirectory(sDirectory);

before the SaveServerCharacter() call.

@Rapophage
Copy link
Author

You can try adding:

CExoString sDirectory;
CNetLayerPlayerInfo *pPlayerInfo = Globals::AppManager()->m_pServerExoApp->GetNetLayer()->GetPlayerInfo(pPlayer->m_nPlayerID);
CExoString sSubdirectory = pPlayerInfo->m_lstKeys[0].sPublic;
if (Globals::AppManager()->m_pServerExoApp->GetServerInfo()->m_PersistantWorldOptions.bServerVaultByPlayerName)
    sSubdirectory = pPlayer->GetPlayerName();

if (sSubdirectory.IsEmpty())
    sDirectory.Format( "SERVERVAULT:%s", "lost+found");
else
    sDirectory.Format( "SERVERVAULT:%s", sSubdirectory.CStr());

Globals::ExoResMan()->CreateDirectory(sDirectory);

before the SaveServerCharacter() call.

Yep, that worked!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers RFE: plugin New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants