Page MenuHomeFeedback Tracker

Add scripting command to get the name of a player
Assigned, WishlistPublic

Description

Currently, the only command (As far as I'm aware) to get names is the 'name' command.

However, that returns the name of the unit, not the player.
The name of the unit just happens to be the same name as the player, however, if you've used setIdentity on the player unit, name will now return the identity's name, and there's no longer a way to get the player name.

Details

Legacy ID
2578064276
Severity
None
Resolution
Reopened
Reproducibility
N/A
Category
Scripting
Steps To Reproduce
  1. Open mission editor, and place a player unit.
  2. Preview.
  3. Open the debug console and execute the following (It'll display the player's name, set identity, then try to display the player's name again):

[]spawn{hint format ["Local player's name is %1", name player]; sleep 3; player setIdentity "Levine"; hint "Set identity."; sleep 3; hint format ["Local player's name is %1", name player];}

Additional Information

My current work-around:

init.sqf:
{

if (isPlayer _x) then
{
    _x setVariable ["name", name _x];
};

} forEach playableUnits;

event_onPlayerConnected =
{

private ["_id", "_name", "_uid"];
_id = _this select 0;
_name = _this select 1;
_uid = _this select 2;

{
    scopeName "loop";
    if (isPlayer _x && {_uid == getPlayerUID _x}) then
    {
        _x setVariable ["name", name _x];
        breakOut "loop";
    };
} forEach playableUnits;

};

onPlayerConnected "[_id, _name, _uid] call event_onPlayerConnected";

// Then somePlayer getVariable "name"; to get the name of the player.

Event Timeline

MulleDK19 edited Steps To Reproduce. (Show Details)Jul 8 2013, 2:38 PM
MulleDK19 edited Additional Information. (Show Details)
MulleDK19 set Category to Scripting.
MulleDK19 set Reproducibility to N/A.
MulleDK19 set Severity to None.
MulleDK19 set Resolution to Reopened.
MulleDK19 set Legacy ID to 2578064276.May 7 2016, 3:22 PM
Ed added a subscriber: Ed.May 7 2016, 3:22 PM
Ed added a comment.Jul 8 2013, 3:54 PM

It even affects the multiplayer chat.

That only gets the name of the local player, not a specific player.

name player, make that a public variable for the entity and call it from the server once the public variable has been sent through

Again, that's a work-around, not a solution.

You can get a player's actual name simply by using:

name vehicle (playableUnits select _unitIndex);

With _unitIndex being the unit's position number (index number) in playableUnits.

For example, if I were the only playable unit currently on the server then,

name vehicle (playableUnits select 0);

Would return "Jamie" (me).

Works every time.

EDIT: Just tested and simply "name vehicle player" also seems to do the trick!

@JamieG

hint name player; "KK"
player setName "Bob";
hint name vehicle player
"Bob"

@JamieG: That's because you're late.

This seems to have been changed for multiplayer. The name command now returns the name of the player instead of the identity's name.

It still returns the identity's name in singleplayer, but at least profileName will do there.

But now there doesn't seem to be a way to get the character (identity)'s name in multiplayer.