GetPCPlayerName(object)

From NWN Lexicon
Revision as of 23:00, 4 July 2022 by Jasperre (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Retrieves the login name of the player of a PC.

string GetPCPlayerName(
    object oPlayer
);

Parameters

oPlayer
The player whose controller's login name is to be retrieved.


Description

Returns the login account name of the player controlling oPlayer. Returns a blank string on error (such as using it on another object).

Note this login name can be arbitrarily changed in NWN:EE in the game options, and will start blank so may be blank in singleplayer. It must be set to enter multiplayer servers.

In NWN:EE you can now use GetObjectUUID to get a more unique reference for individual characters a player uses if required.


Known Bugs

Not a bug, but a caveat. OnClientLeave, the PC object (GetExitingObject) is still valid, but the player object (i.e. the human being logged into the server) is not. This means that there are a few things you can't do OnClientLeave. Namely, the GetPCPlayerName, GetPCIPAddress, and GetPCPublicCDKey will not work, since the player is no longer around to get that information from. This can be worked around by storing them as local strings on the PC, for instance OnClientEnter. See workaround below.


Example

//Workaround for the caveat above

void main()
{
    object oPC=GetEnteringObject();
    string sPlayerName=GetPCPlayerName(oPC);
    string sIP=GetPCIPAddress(oPC);
    string sKey=GetPCPublicCDKey(oPC);
    SetLocalString(oPC, "player_name", sPlayerName);
    SetLocalString(oPC, "player_ip", sIP);
    SetLocalString(oPC, "player_cdkey", sKey);
}

See Also

functions: GetPCIPAddress GetPCPublicCDKey GetObjectUUID
events: OnClientEnter OnClientLeave

 author: Sarev0k, editor: Lilac Soul, additional contributor(s): Sam Featherston, Lilac Soul