.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Bot Coding (http://forums.bots-united.com/forumdisplay.php?f=24)
-   -   Getting teams in CS - "TeamInfo" (http://forums.bots-united.com/showthread.php?t=4938)

The Storm 12-02-2006 00:53

Getting teams in CS - "TeamInfo"
 
OK yesterday some hours I had making a tests with the "TeamInfo" CS message to get the teams without using a models. Here what I got.
Code:

// This message is sent whenever information for the teams is sended.
void BotClient_CS_TeamInfo (void *p, int index)
{

    if (strcmp((char *) p, "UNASSIGNED") == 0)
    {
        ThreatTab[index].iTeam = TEAM_UNASSIGNED;
    }
    else if (strcmp((char *) p, "TERRORIST") == 0)
    {
        ThreatTab[index].iTeam = TEAM_T;
    }
    else if (strcmp((char *) p, "CT") == 0)
    {
        ThreatTab[index ].iTeam = TEAM_CT;
    }
    else if (strcmp((char *) p, "SPECTATOR") == 0)
    {
        ThreatTab[index].iTeam = TEAM_SPECTATOR;
    }
    state++;
}

The message is hooked fine in engine.cpp like all others clients messages but it seems to not work propertie.
I tryed to debug it. So I putted this line at the start of the function:
Code:

{ fp=fopen("EPB.txt","a"); fprintf(fp,"BotClient_CS_TeamInfo: %s\n",p); fclose(fp); }
and now the function looks like this:
Code:

// This message is sent whenever information for the teams is sended.
void BotClient_CS_TeamInfo (void *p, int index)
{

{ fp=fopen("EPB.txt","a"); fprintf(fp,"BotClient_CS_TeamInfo: %s\n",p); fclose(fp); }

    if (strcmp((char *) p, "UNASSIGNED") == 0)
    {
        ThreatTab[index].iTeam = TEAM_UNASSIGNED;
    }
    else if (strcmp((char *) p, "TERRORIST") == 0)
    {
        ThreatTab[index].iTeam = TEAM_T;
    }
    else if (strcmp((char *) p, "CT") == 0)
    {
        ThreatTab[index ].iTeam = TEAM_CT;
    }
    else if (strcmp((char *) p, "SPECTATOR") == 0)
    {
        ThreatTab[index].iTeam = TEAM_SPECTATOR;
    }
    state++;
}

and after I opened the EPB.txt file I got this:
Code:

BotClient_CS_TeamInfo: 
BotClient_CS_TeamInfo: UNASSIGNED
BotClient_CS_TeamInfo: 
BotClient_CS_TeamInfo: UNASSIGNED
BotClient_CS_TeamInfo: 
BotClient_CS_TeamInfo: TERRORIST
BotClient_CS_TeamInfo: 
BotClient_CS_TeamInfo: CT
BotClient_CS_TeamInfo: 
BotClient_CS_TeamInfo: UNASSIGNED
BotClient_CS_TeamInfo: 
BotClient_CS_TeamInfo: TERRORIST
BotClient_CS_TeamInfo: 
BotClient_CS_TeamInfo: CT
BotClient_CS_TeamInfo: 
BotClient_CS_TeamInfo: CT
BotClient_CS_TeamInfo: 
BotClient_CS_TeamInfo: UNASSIGNED
BotClient_CS_TeamInfo: 
BotClient_CS_TeamInfo: TERRORIST
BotClient_CS_TeamInfo: 
BotClient_CS_TeamInfo: CT
BotClient_CS_TeamInfo: 
BotClient_CS_TeamInfo: CT
BotClient_CS_TeamInfo: 
BotClient_CS_TeamInfo: TERRORIST
BotClient_CS_TeamInfo: 
BotClient_CS_TeamInfo: UNASSIGNED
BotClient_CS_TeamInfo: 
BotClient_CS_TeamInfo: TERRORIST
BotClient_CS_TeamInfo: 
BotClient_CS_TeamInfo: CT
BotClient_CS_TeamInfo: 
BotClient_CS_TeamInfo: CT
BotClient_CS_TeamInfo: 
BotClient_CS_TeamInfo: TERRORIST
BotClient_CS_TeamInfo: 
BotClient_CS_TeamInfo: CT
BotClient_CS_TeamInfo: 
BotClient_CS_TeamInfo: UNASSIGNED

This message is called when a player or bot change a team and on each round start.
I moved the debug info in to the if {} else {} to see if my checks for the messages are ok and it seems that all is work just fine but when I try to get the teams of the players it's just not work. I can't get the players and bots teams. The message is sended correct and I get it correct but it seems that this lines are not working correct:
Code:

ThreatTab[index].iTeam = TEAM_UNASSIGNED;
ThreatTab[index].iTeam = TEAM_T;
ThreatTab[index].iTeam = TEAM_SPECTATOR;

If someone can tell me where I wrong I will be very happy. :clap:

KWo 12-02-2006 15:46

Re: Getting teams in CS - "TeamInfo"
 
For debug info write also index, to be sure if it is called with ALL parameters correctly.
[EDIT1]
Code:

static cell AMX_NATIVE_CALL cs_set_user_team(AMX *amx, cell *params) // cs_set_user_team(index, team, model = 0); = 3 params
{
    // Set user team
    // params[1] = user index
    // params[2] = team
    // params[3] = model = 0

    // Valid entity should be within range
    CHECK_PLAYER(params[1]);

    // Make into edict pointer
    edict_t *pPlayer = MF_GetPlayerEdict(params[1]);

    int model = params[3];

    // Just set team. Removed check of 1-2-3, because maybe scripters want to create new teams, 4, 5 etc?
    *((int *)pPlayer->pvPrivateData + OFFSET_TEAM) = params[2];
    if (model != 0)
        *((int *)pPlayer->pvPrivateData + OFFSET_INTERNALMODEL) = model;
   
    // This makes the model get updated right away.
    MDLL_ClientUserInfoChanged(pPlayer, GETINFOKEYBUFFER(pPlayer)); //  If this causes any problems for WON, do this line only in STEAM builds.

    // And update scoreboard by sending TeamInfo msg.
    char teaminfo[32];
    switch (params[2]) {
        case TEAM_UNASSIGNED:
            strcpy(teaminfo, "UNASSIGNED");
            break;
        case TEAM_T:
            strcpy(teaminfo, "TERRORIST");
            break;
        case TEAM_CT:
            strcpy(teaminfo, "CT");
            break;
        case TEAM_SPECTATOR:
            strcpy(teaminfo, "SPECTATOR");
            break;
        default:
            int team_nr = (int)params[2];
            sprintf(teaminfo, "TEAM_%i", team_nr);
    }
    MESSAGE_BEGIN(MSG_ALL, GET_USER_MSG_ID(PLID, "TeamInfo", NULL));
    WRITE_BYTE(params[1]);
    WRITE_STRING(teaminfo);
    MESSAGE_END();
(...)
}

I believe You need to get it as message sent to ALL, and You need to catch also this what is written as WRITE_BYTE (params[1]) - this is the player index. Before You will not show how Your function gets called, nothing more helpful for You will be written here...
[/EDIT1]
[EDIT2]
You need to use:
Code:

static int iPlayerIndex;
switch (state)
 {
 case 0:
    iPlayerIndex = *(int *)p;
    break;
 case 1:
    if (strcmp((char *) p, "UNASSIGNED") == 0)
    {
        ThreatTab[iPlayerIndex].iTeam = TEAM_UNASSIGNED;
    }
    else if (strcmp((char *) p, "TERRORIST") == 0)
    {
        ThreatTab[iPlayerIndex].iTeam = TEAM_T;
    }
    else if (strcmp((char *) p, "CT") == 0)
    {
        ThreatTab[iPlayerIndex].iTeam = TEAM_CT;
    }
    else if (strcmp((char *) p, "SPECTATOR") == 0)
    {
        ThreatTab[iPlayerIndex].iTeam = TEAM_SPECTATOR;
    }
    break;
}

Or maybe You need to use iPlayerIndex-1 as index in ThreatTab.
[/EDIT2]

The Storm 12-02-2006 18:13

Re: Getting teams in CS - "TeamInfo"
 
KWo thanks you so much. I was forgot that I must get the player index via the message. :)
So here the right function:
Code:

// This message is sent whenever information for the teams is sended. - THE STORM
void Client_CS_TeamInfo (void *p, int/* iPlayerIndex*/)
{

    static int iPlayerIndex;

    switch (state++)
    {
    case 0:
        iPlayerIndex = *(int *)p;
        break;
    case 1:
        if (strcmp((char *) p, "UNASSIGNED") == 0)
        {
            clients[iPlayerIndex - 1].iTeam = TEAM_CS_UNASSIGNED;
        }
        else if (strcmp((char *) p, "TERRORIST") == 0)
        {
            clients[iPlayerIndex - 1].iTeam = TEAM_CS_TERRORIST;
        }
        else if (strcmp((char *) p, "CT") == 0)
        {
            clients[iPlayerIndex - 1].iTeam = TEAM_CS_COUNTER;
        }
        else if (strcmp((char *) p, "SPECTATOR") == 0)
        {
            clients[iPlayerIndex - 1].iTeam = TEAM_CS_SPECTATOR;
        }
        break;
    }
}

No more team detection with models. :clap:


All times are GMT +2. The time now is 01:44.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.