//========================================================= // InitHUD //========================================================= void CTeamplayRules::InitHUD( CBasePlayer *pPlayer ) { SetDefaultPlayerTeam( pPlayer ); BaseClass::InitHUD( pPlayer ); RecountTeams(); char *mdls = engine->InfoKeyValue( engine->GetInfoKeyBuffer( pPlayer->edict() ), "model" ); // update the current player of the team he is joining char text[1024]; if ( !strcmp( mdls, pPlayer->TeamName() ) ) { Q_snprintf( text,sizeof(text), "You are on team \'%s\'\n", pPlayer->TeamName() ); } else { Q_snprintf( text,sizeof(text), "You were assigned to team %s\n", pPlayer->TeamName() ); } ChangePlayerTeam( pPlayer, pPlayer->TeamName(), false, false ); if ( Q_strlen( pPlayer->TeamName() ) > 0 ) { UTIL_SayText( text, pPlayer ); } RecountTeams(); }
//========================================================= // InitHUD //========================================================= void CHalfLifeTeamplay::InitHUD( CBasePlayer *pPlayer ) { int i; SetDefaultPlayerTeam( pPlayer ); CHalfLifeMultiplay::InitHUD( pPlayer ); // Send down the team names MESSAGE_BEGIN( MSG_ONE, gmsgTeamNames, NULL, pPlayer->edict() ); WRITE_BYTE( num_teams ); for ( i = 0; i < num_teams; i++ ) { WRITE_STRING( team_names[ i ] ); } MESSAGE_END(); RecountTeams(); char *mdls = g_engfuncs.pfnInfoKeyValue( g_engfuncs.pfnGetInfoKeyBuffer( pPlayer->edict() ), "model" ); // update the current player of the team he is joining char text[1024]; if ( !strcmp( mdls, pPlayer->m_szTeamName ) ) { sprintf( text, "* you are on team \'%s\'\n", pPlayer->m_szTeamName ); } else { sprintf( text, "* assigned to team %s\n", pPlayer->m_szTeamName ); } ChangePlayerTeam( pPlayer, pPlayer->m_szTeamName, FALSE, FALSE ); UTIL_SayText( text, pPlayer ); int clientIndex = pPlayer->entindex(); RecountTeams(); // update this player with all the other players team info // loop through all active players and send their team info to the new client for ( i = 1; i <= gpGlobals->maxClients; i++ ) { CBaseEntity *plr = UTIL_PlayerByIndex( i ); if ( plr && IsValidTeam( plr->TeamID() ) ) { MESSAGE_BEGIN( MSG_ONE, gmsgTeamInfo, NULL, pPlayer->edict() ); WRITE_BYTE( plr->entindex() ); WRITE_STRING( plr->TeamID() ); MESSAGE_END(); } } }
//========================================================= // InitHUD //========================================================= void CTeamplayRules::InitHUD( CBasePlayer *pPlayer ) { SetDefaultPlayerTeam( pPlayer ); BaseClass::InitHUD( pPlayer ); RecountTeams(); /* TODO this has to be rewritten, maybe add a new USERINFO cvar "team" const char *team = engine->GetClientConVarValue( pPlayer->entindex(), "cl_team" ); // update the current player of the team he is joining char text[1024]; if ( !strcmp( mdls, pPlayer->TeamName() ) ) { Q_snprintf( text,sizeof(text), "You are on team \'%s\'\n", pPlayer->TeamName() ); } else { Q_snprintf( text,sizeof(text), "You were assigned to team %s\n", pPlayer->TeamName() ); } ChangePlayerTeam( pPlayer, pPlayer->TeamName(), false, false ); if ( Q_strlen( pPlayer->TeamName() ) > 0 ) { UTIL_SayText( text, pPlayer ); } RecountTeams(); */ }
const char *CHalfLifeTeamplay::SetDefaultPlayerTeam( CBasePlayer *pPlayer ) { // copy out the team name from the model char *mdls = g_engfuncs.pfnInfoKeyValue( g_engfuncs.pfnGetInfoKeyBuffer( pPlayer->edict() ), "model" ); pPlayer->SetTeamID(mdls); RecountTeams(); // update the current player of the team he is joining const char* theTeamName = pPlayer->TeamID(); if ( theTeamName == '\0' || !IsValidTeam( theTeamName ) || defaultteam.value ) { const char *pTeamName = NULL; if ( defaultteam.value ) { pTeamName = team_names[0]; } else { pTeamName = TeamWithFewestPlayers(); } pPlayer->SetTeamID(pTeamName); } return pPlayer->TeamID(); }
CHalfLifeTeamplay :: CHalfLifeTeamplay() { m_DisableDeathMessages = FALSE; m_DisableDeathPenalty = FALSE; memset( team_names, 0, sizeof(team_names) ); memset( team_scores, 0, sizeof(team_scores) ); num_teams = 0; // Copy over the team from the server config m_szTeamList[0] = 0; // Cache this because the team code doesn't want to deal with changing this in the middle of a game strncpy( m_szTeamList, teamlist.string, TEAMPLAY_TEAMLISTLENGTH ); edict_t *pWorld = INDEXENT(0); if ( pWorld && pWorld->v.team ) { if ( teamoverride.value ) { const char *pTeamList = STRING(pWorld->v.team); if ( pTeamList && strlen(pTeamList) ) { strncpy( m_szTeamList, pTeamList, TEAMPLAY_TEAMLISTLENGTH ); } } } // Has the server set teams if ( strlen( m_szTeamList ) ) m_teamLimit = TRUE; else m_teamLimit = FALSE; RecountTeams(); }
const char *CHalfLifeTeamplay::SetDefaultPlayerTeam( CBasePlayer *pPlayer ) { // copy out the team name from the model char *mdls = g_engfuncs.pfnInfoKeyValue( g_engfuncs.pfnGetInfoKeyBuffer( pPlayer->edict() ), "model" ); strncpy( pPlayer->m_szTeamName, mdls, TEAM_NAME_LENGTH ); RecountTeams(); // update the current player of the team he is joining if ( pPlayer->m_szTeamName[0] == '\0' || !IsValidTeam( pPlayer->m_szTeamName ) || defaultteam.value ) { const char *pTeamName = NULL; if ( defaultteam.value ) { pTeamName = team_names[0]; } else { pTeamName = TeamWithFewestPlayers(); } strncpy( pPlayer->m_szTeamName, pTeamName, TEAM_NAME_LENGTH ); } return pPlayer->m_szTeamName; }
const char *CTeamplayRules::SetDefaultPlayerTeam( CBasePlayer *pPlayer ) { // copy out the team name from the model char *mdls = engine->InfoKeyValue( engine->GetInfoKeyBuffer( pPlayer->edict() ), "model" ); pPlayer->SetTeamName( mdls ); RecountTeams(); // update the current player of the team he is joining if ( (pPlayer->TeamName())[0] == '\0' || !IsValidTeam( pPlayer->TeamName() ) || defaultteam.GetFloat() ) { const char *pTeamName = NULL; if ( defaultteam.GetFloat() ) { pTeamName = team_names[0]; } else { pTeamName = TeamWithFewestPlayers(); } pPlayer->SetTeamName( pTeamName ); } return pPlayer->TeamName(); }
//========================================================= //========================================================= void CTeamplayRules::PlayerKilled( CBasePlayer *pVictim, const CTakeDamageInfo &info ) { if ( !m_DisableDeathPenalty ) { BaseClass::PlayerKilled( pVictim, info ); RecountTeams(); } }
//========================================================= //========================================================= void CHalfLifeTeamplay :: PlayerKilled( CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pInflictor ) { if ( !m_DisableDeathPenalty ) { CHalfLifeMultiplay::PlayerKilled( pVictim, pKiller, pInflictor ); RecountTeams(); } }
//========================================================= // ClientUserInfoChanged //========================================================= void CHalfLifeTeamplay::ClientUserInfoChanged( CBasePlayer *pPlayer, char *infobuffer ) { char text[1024]; // prevent skin/color/model changes char *mdls = g_engfuncs.pfnInfoKeyValue( infobuffer, "model" ); if ( !stricmp( mdls, pPlayer->TeamID() ) ) return; if ( defaultteam.value ) { int clientIndex = pPlayer->entindex(); g_engfuncs.pfnSetClientKeyValue( clientIndex, g_engfuncs.pfnGetInfoKeyBuffer( pPlayer->edict() ), "model", pPlayer->TeamID() ); g_engfuncs.pfnSetClientKeyValue( clientIndex, g_engfuncs.pfnGetInfoKeyBuffer( pPlayer->edict() ), "team", pPlayer->TeamID() ); sprintf( text, "* Not allowed to change teams in this game!\n" ); UTIL_SayText( text, pPlayer ); return; } if ( defaultteam.value || !IsValidTeam( mdls ) ) { int clientIndex = pPlayer->entindex(); g_engfuncs.pfnSetClientKeyValue( clientIndex, g_engfuncs.pfnGetInfoKeyBuffer( pPlayer->edict() ), "model", pPlayer->TeamID() ); sprintf( text, "* Can't change team to \'%s\'\n", mdls ); UTIL_SayText( text, pPlayer ); sprintf( text, "* Server limits teams to \'%s\'\n", m_szTeamList ); UTIL_SayText( text, pPlayer ); return; } // notify everyone of the team change sprintf( text, "* %s has changed to team \'%s\'\n", STRING(pPlayer->pev->netname), mdls ); UTIL_SayTextAll( text, pPlayer ); UTIL_LogPrintf( "\"%s<%i><%s><%s>\" joined team \"%s\"\n", STRING(pPlayer->pev->netname), GETPLAYERUSERID( pPlayer->edict() ), #ifdef USE_UPP UPPUtil_GetNetworkID(pPlayer->edict()).c_str(), #else AvHSUGetPlayerAuthIDString( pPlayer->edict() ).c_str(), #endif pPlayer->TeamID(), mdls ); ChangePlayerTeam( pPlayer, mdls, TRUE, TRUE ); // recound stuff RecountTeams(); }
CTeamplayRules :: CTeamplayRules() { m_DisableDeathMessages = false; m_DisableDeathPenalty = false; memset( team_names, 0, sizeof(team_names) ); memset( team_scores, 0, sizeof(team_scores) ); num_teams = 0; // Copy over the team from the server config m_szTeamList[0] = 0; RecountTeams(); }
//========================================================= // ClientUserInfoChanged //========================================================= void CTeamplayRules::ClientUserInfoChanged( CBasePlayer *pPlayer, char *infobuffer ) { char text[1024]; // prevent skin/color/model changes char *mdls = engine->InfoKeyValue( infobuffer, "model" ); if ( !stricmp( mdls, pPlayer->TeamName() ) ) return; if ( defaultteam.GetFloat() ) { int clientIndex = pPlayer->entindex(); engine->SetClientKeyValue( clientIndex, engine->GetInfoKeyBuffer( pPlayer->edict() ), "model", pPlayer->TeamName() ); engine->SetClientKeyValue( clientIndex, engine->GetInfoKeyBuffer( pPlayer->edict() ), "team", pPlayer->TeamName() ); UTIL_SayText( "Not allowed to change teams in this game!\n", pPlayer ); return; } if ( defaultteam.GetFloat() || !IsValidTeam( mdls ) ) { int clientIndex = pPlayer->entindex(); engine->SetClientKeyValue( clientIndex, engine->GetInfoKeyBuffer( pPlayer->edict() ), "model", pPlayer->TeamName() ); Q_snprintf( text,sizeof(text), "Can't change team to \'%s\'\n", mdls ); UTIL_SayText( text, pPlayer ); Q_snprintf( text,sizeof(text), "Server limits teams to \'%s\'\n", m_szTeamList ); UTIL_SayText( text, pPlayer ); return; } // notify everyone of the team change if ( Q_strlen( STRING(pPlayer->pl.netname) ) > 0 ) { Q_snprintf( text,sizeof(text), "%s has changed to team \'%s\'\n", STRING(pPlayer->pl.netname), mdls ); UTIL_SayTextAll( text, pPlayer ); } UTIL_LogPrintf( "\"%s<%i>\" changed to team %s\n", STRING( pPlayer->pl.netname ), engine->GetPlayerUserId( pPlayer->edict() ), mdls ); ChangePlayerTeam( pPlayer, mdls, true, true ); // recound stuff RecountTeams(); }
//========================================================= // InitHUD //========================================================= void CHalfLifeTeamplay::InitHUD( CBasePlayer *pPlayer ) { int i; SetDefaultPlayerTeam( pPlayer ); CHalfLifeMultiplay::InitHUD( pPlayer ); // Send down the team names MESSAGE_BEGIN( MSG_ONE, gmsgTeamNames, NULL, pPlayer->edict() ); WRITE_BYTE( num_teams ); for ( i = 0; i < num_teams; i++ ) { char theTeamName[256]; strcpy(theTeamName, team_names[i]); // If the team name isn't empty, append # so team name is translated on client if(strcmp(theTeamName, "")) { sprintf(theTeamName, "#%s", team_names[i]); } WRITE_STRING(theTeamName); } MESSAGE_END(); RecountTeams(); // char *mdls = g_engfuncs.pfnInfoKeyValue( g_engfuncs.pfnGetInfoKeyBuffer( pPlayer->edict() ), "model" ); // // update the current player of the team he is joining // char text[1024]; // if ( !strcmp( mdls, pPlayer->m_szTeamName ) ) // { // sprintf( text, "* you are on team \'%s\'\n", pPlayer->m_szTeamName ); // } // else // { // sprintf( text, "* assigned to team %s\n", pPlayer->m_szTeamName ); // } ChangePlayerTeam( pPlayer, pPlayer->TeamID(), FALSE, FALSE ); // UTIL_SayText( text, pPlayer ); int clientIndex = pPlayer->entindex(); RecountTeams(); // // update this player with all the other players team info // // loop through all active players and send their team info to the new client // for ( i = 1; i <= gpGlobals->maxClients; i++ ) // { // CBasePlayer *plr = (CBasePlayer*)UTIL_PlayerByIndex( i ); // if ( plr && IsValidTeam( plr->TeamID() ) ) // { // MESSAGE_BEGIN( MSG_ONE, gmsgTeamInfo, NULL, pPlayer->edict() ); // WRITE_BYTE( plr->entindex() ); // WRITE_STRING( plr->TeamID() ); // MESSAGE_END(); // } // } pPlayer->NeedsTeamUpdate(); }