Raised This Month: $51 Target: $400
 12% 

Team Question


Post New Thread Reply   
 
Thread Tools Display Modes
API
Veteran Member
Join Date: May 2006
Old 07-09-2007 , 00:50   Re: Team Question
Reply With Quote #11

In my opinion you shouldn't use cbase.h, if you MUST use it (you don't, trust me), do:
Code:
#define GAME_DLL 1
#include "cbase.h"
__________________
API is offline
Send a message via AIM to API
BAILOPAN
Join Date: Jan 2004
Old 07-09-2007 , 11:31   Re: Team Question
Reply With Quote #12

If you need to include cbase you're probably already going in the wrong direction.
__________________
egg
BAILOPAN is offline
Aidan
Junior Member
Join Date: Jul 2007
Old 07-09-2007 , 12:00   Re: Team Question
Reply With Quote #13

Quote:
Originally Posted by BAILOPAN View Post
If you need to include cbase you're probably already going in the wrong direction.

Okay, so now that I'm good and lost....

Here's what I'm trying to do.

CTeam *t, *ct;

t = CBasePlayer->GetTeam( );
ct = CBasePlayer2->GetTeam( );

int score[2];
score[0] = t->GetScore( );
score[1] = ct->GetScore( );

Anyone have any suggestions on where to start since I'm going the wrong way?

(The code above is very rough and in no way comparable to what I'm writing, its just an example.)
Aidan is offline
BAILOPAN
Join Date: Jan 2004
Old 07-09-2007 , 12:57   Re: Team Question
Reply With Quote #14

We're going in circles here... including this post I've now made 4 total that tell you to use network properties. You simply can't do normal calls against the SDK since CS:S changes class layouts.

Recap: All you need is a few CBaseEntity pointers and you can grab everything you need from network props. A network property is a named offset from the CBaseEntity pointer, i.e. grabbing an int looks like:
Code:
int val = *(int *)((char *)pEntity + offset);
1) Get a player's team index with the "m_iTeamNum" prop
2) Loop through all entities and find one that a) Has a "CCSTeam" network class and b) Has an "m_iTeamNum" property value that matches the number
3) Get the "m_iScore" property of that CCSTeam entity
__________________
egg
BAILOPAN is offline
L. Duke
Veteran Member
Join Date: Apr 2005
Location: Walla Walla
Old 07-09-2007 , 13:09   Re: Team Question
Reply With Quote #15

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.
L. Duke is offline
Aidan
Junior Member
Join Date: Jul 2007
Old 07-09-2007 , 14:01   Re: Team Question
Reply With Quote #16

Thanks Bailopan and L. Duke. I just got some free time so I'm going to work on that now.

Bailopan, my apologies for the misunderstanding. I am still trying to learn the SDK and its not the easiest thing to work with. I wasn't trying to be an ignorant pain.

I'll let you all know how it goes.

Thanks!
-Rob
Aidan is offline
Aidan
Junior Member
Join Date: Jul 2007
Old 07-09-2007 , 14:17   Re: Team Question
Reply With Quote #17

Quote:
Originally Posted by L. Duke View Post
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.

Can I ask where pEdictList comes from? I can't find anything in what I have that says where it is. All I can find is ServerActivate(edict_t *pEdictList), yet nothing defines what it is.

Thanks
Rob
Aidan is offline
L. Duke
Veteran Member
Join Date: Apr 2005
Location: Walla Walla
Old 07-09-2007 , 14:26   Re: Team Question
Reply With Quote #18

That's exactly where it comes from. It's just the list of edicts. You can get the same thing by looping through engine->PEntityOfEntIndex(i) up to the maximum number of entities.
L. Duke is offline
Aidan
Junior Member
Join Date: Jul 2007
Old 07-09-2007 , 14:33   Re: Team Question
Reply With Quote #19

Quote:
Originally Posted by L. Duke View Post
That's exactly where it comes from. It's just the list of edicts. You can get the same thing by looping through engine->PEntityOfEntIndex(i) up to the maximum number of entities.
Hrm, thats odd. I can't use edictCount either. Maybe I'm missing a header file?

Last edited by Aidan; 07-09-2007 at 15:08.
Aidan is offline
Aidan
Junior Member
Join Date: Jul 2007
Old 07-09-2007 , 15:14   Re: Team Question
Reply With Quote #20

durh, i'm an idiot. I just figured out what I did wrong. -.-
Aidan is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:35.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode