IPlayerInfo: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
No edit summary
 
Line 1: Line 1:
'''<code>IPlayerInfo</code>''' is a server [[interface]] that provides data about connected users, accessed through '''<code>IPlayerInfoManager</code>'''. Since both interfaces are defined in the server library, game-specific versions are possible.
'''<code>IPlayerInfo</code>''' is a server [[interface]] that provides data about connected users, accessed through '''<code>IPlayerInfoManager</code>'''. Since both interfaces are defined in the server library, game-specific versions are possible.


{{note|A player's info is only available when they are active (usually meaning spawned in the world). Before this time access attempts will fail, which can be problematic if your plugin is loading or unpausing mid-game as you may have missed ClientConnect() calls. <code>[[INetChannelInfo]]</code> provides some information, but otherwise...{{todo|solution?}}}}
{{note|A player's info is only available when they are active (usually meaning spawned in the world). Before this time access attempts will fail, which can be problematic if your plugin is loading or unpausing mid-game as there may be clients halfway through connecting. To overcome this, use <code>[[IVEngineServer]]</code>'s <code>GetPlayerNetworkIDString()</code> or <code>GetPlayerUserId()</code> on [[entity index|entity indices]] 1 to [[maxplayers]].}}


== Example ==
== Example ==
Line 8: Line 8:
#include "game/server/iplayerinfo.h"
#include "game/server/iplayerinfo.h"


static IPlayerInfoManager* playerinfomanager; // recommended
IPlayerInfoManager* playerinfomanager; // give globals global scope


bool CMyServerPlugin::Load(CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory)
bool CMyServerPlugin::Load(CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory)

Latest revision as of 09:31, 20 October 2010

IPlayerInfo is a server interface that provides data about connected users, accessed through IPlayerInfoManager. Since both interfaces are defined in the server library, game-specific versions are possible.

Note.pngNote:A player's info is only available when they are active (usually meaning spawned in the world). Before this time access attempts will fail, which can be problematic if your plugin is loading or unpausing mid-game as there may be clients halfway through connecting. To overcome this, use IVEngineServer's GetPlayerNetworkIDString() or GetPlayerUserId() on entity indices 1 to maxplayers.

Example

#include "game/server/iplayerinfo.h"

IPlayerInfoManager* playerinfomanager; // give globals global scope

bool CMyServerPlugin::Load(CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory)
{
	playerinfomanager = (IPlayerInfoManager*)gameServerFactory(INTERFACEVERSION_PLAYERINFOMANAGER,NULL);
	if (!playerinfomanager)
	{
		Warning("Could not access IPlayerInfoManager!\n");
		return false;
	}
	
	IPlayerInfo* info = playerinfomanager->GetPlayerInfo(engine->PEntityOfEntIndex(1)); // first player
	if (info)
		Msg("Player 1 is %s, with %i health\n",info->GetName(),info->GetHealth());
	else
		Msg("Player 1 has not spawned\n");
		
	return true;
}

See also