当前位置: 首页>>代码示例>>C++>>正文


C++ IPlayerInfo::GetMaxHealth方法代码示例

本文整理汇总了C++中IPlayerInfo::GetMaxHealth方法的典型用法代码示例。如果您正苦于以下问题:C++ IPlayerInfo::GetMaxHealth方法的具体用法?C++ IPlayerInfo::GetMaxHealth怎么用?C++ IPlayerInfo::GetMaxHealth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IPlayerInfo的用法示例。


在下文中一共展示了IPlayerInfo::GetMaxHealth方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: webspec_callback

//=================================================================================
// Callback for the 'webspec' protocol
// Manages spectator connections & sending Initial messages to new spectators
//=================================================================================
int webspec_callback(struct libwebsocket_context *ctx, struct libwebsocket *wsi, 
	enum libwebsocket_callback_reasons reason, void *user, void *in, size_t len)
{
	switch (reason) {
		case LWS_CALLBACK_ESTABLISHED:
		{
			Msg("[WS] New connection\n");
			// New connection
			ws_spectators.AddToTail(wsi);
			
			// Send basic game info to let client set up
			// MapName, Server name (may remove), current team names
			char *buffer = (char*)malloc(MAX_BUFFER_SIZE);
			char *mapName = (char*) STRING(gpGlobals->mapname);
			ConVarRef hostNameCVar = ConVarRef("hostname");
			string_t hostname;
			if (hostNameCVar.IsValid())
				hostname = MAKE_STRING(hostNameCVar.GetString());
			else
				hostname = MAKE_STRING("WebSpec Demo Server"); //Can't imagine when hostname would be invalid, but this is Source
			int length = snprintf(buffer, MAX_BUFFER_SIZE, "%c%s:%s:%s:%s", WSPacket_Init, mapName, STRING(hostname), STRING(ws_teamName[1]), STRING(ws_teamName[0]));

			SendPacketToOne(buffer, length, wsi);
			free(buffer);

			//Send connected players
			IPlayerInfo *playerInfo;
			for (int i=1; i<=gpGlobals->maxClients; i++) {
				playerInfo = playerInfoManager->GetPlayerInfo(engine->PEntityOfEntIndex(i));
				if (playerInfo != NULL && playerInfo->IsConnected()) {
					buffer = (char *)malloc(MAX_BUFFER_SIZE);
					int userid = playerInfo->GetUserID();
					int teamid = playerInfo->GetTeamIndex();
					int health = playerInfo->GetHealth();
					int maxHealth = playerInfo->GetMaxHealth();
					bool alive = !playerInfo->IsDead();
					string_t playerName = MAKE_STRING(playerInfo->GetName());
					
					//Pointer magic to get TF2 class
					CBaseEntity *playerEntity = serverGameEnts->EdictToBaseEntity(engine->PEntityOfEntIndex(i));
					int playerClass = *MakePtr(int*, playerEntity, WSOffsets::pCTFPlayer__m_iClass);

					float uberCharge = 0.0f;
					
					if (playerClass == TFClass_Medic) { 
						//Way more pointer magic to get ubercharge from medigun
						CBaseCombatCharacter *playerCombatCharacter = CBaseEntity_MyCombatCharacterPointer(playerEntity);
						CBaseCombatWeapon *slot1Weapon = CBaseCombatCharacter_Weapon_GetSlot(playerCombatCharacter, 1);
						
						uberCharge = *MakePtr(float*, slot1Weapon, WSOffsets::pCWeaponMedigun__m_flChargeLevel);
					}

					int length = snprintf(buffer, MAX_BUFFER_SIZE, "%c%d:%d:%d:%d:%d:%d:0:%d:%s", 'C', userid, teamid, playerClass,
						health, maxHealth, alive, Round(uberCharge*100.0f), STRING(playerName));

					SendPacketToOne(buffer, length, wsi);
					free(buffer);
				}
			}

			break;
		}
开发者ID:MattMcNam,项目名称:webspec,代码行数:66,代码来源:callbacks.cpp


注:本文中的IPlayerInfo::GetMaxHealth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。