Here's some example code of how I do it.
In
ServerActivate I find the team pointers and save them for later use:
Code:
// find team entities and store in teamT and teamCT pointers
int i;
edict_t* pEnt=pEdictList;
CBaseEntity *pBase=NULL;
CTeam *tmpTeam = NULL;
for (i=0;i<edictCount;i++)
{
if(V_stricmp(pEnt->GetClassName(),"cs_team_manager")==0)
{
int team_number;
team_number = gDBUtils->GetTeamTeamNum(pEnt);
META_CONPRINTF(" team: %d\n", team_number);
if (team_number == TERRORISTS)
{
teamT = pEnt;
META_CONPRINTF("TeamT found");
}
if (team_number == COUNTERTERRORISTS)
{
teamCT = pEnt;
META_CONPRINTF("TeamCT found");
}
}
pEnt++;
}
Then my function for getting team score looks like:
Code:
int DBUtils::GetTeamScore(edict_t *team)
{
static int Offset = 0;
if (Offset==0)
{
Offset = FindOffset("CTeam", "m_iScore");
}
if (Offset==0)
return 0;
CBaseEntity *pBase = team->GetUnknown()->GetBaseEntity();
if (pBase)
{
return *(int *)((char *)pBase + Offset );
}
else
{
return 0;
}
}
You'll also need something like this to find the offset from the server class table:
Code:
// find an offset for PropertyName listed in the server class send table for ClassName
int DBUtils::FindOffset(const char *ClassName, const char *PropertyName)
{
ServerClass *sc = m_ServerDll->GetAllServerClasses();
while (sc)
{
if (FStrEq(sc->GetName(), ClassName))
{
int NumProps = sc->m_pTable->GetNumProps();
for (int i=0; i<NumProps; i++)
{
if (stricmp(sc->m_pTable->GetProp(i)->GetName(), PropertyName) == 0)
{
return sc->m_pTable->GetProp(i)->GetOffset();
}
}
return 0;
}
sc = sc->m_pNext;
}
return 0;
}
Note that if you try to change the team score it will be reset when the round restarts, but you should be able to read the score at any time.