IPlayerInfo: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 1: Line 1:
'''<code>IPlayerInfo</code>''' is an [[interface]] used to access server information about connected users from other libraries. It is accessed through an '''<code>IPlayerInfoManager</code>''' global.
'''<code>IPlayerInfo</code>''' is an [[interface]] that provides server-held data about connected users. It is accessed through an '''<code>IPlayerInfoManager</code>''' global.


{{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 you may have missed ClientConnect() calls. <code>[[INetChannelInfo]]</code> provides some information, but otherwise...{{todo|solution?}}}}

Revision as of 15:22, 18 October 2010

IPlayerInfo is an interface that provides server-held data about connected users. It is accessed through an IPlayerInfoManager global.

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 you may have missed ClientConnect() calls. INetChannelInfo provides some information, but otherwise...
Todo: solution?

Example

#include "game/server/iplayerinfo.h"

static IPlayerInfoManager* playerinfomanager; // recommended

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;
}