okay, i have fixed my bug. Here is my code now:
Code:
void BotClient_CS_SayText(void *p, int bot_index)
{
static unsigned char ucEntIndex;
static int state = 0; // current state machine state
// Different Counter-Strike versions mean different
// handling of this "SayText" thingy.
if (counterstrike==0)
{
if (state == 0)
{
ucEntIndex = *(unsigned char *)p;
}
else if (state == 1)
{
cBot *pBot=&bots[bot_index];
if (ENTINDEX(pBot->pEdict) != ucEntIndex)
{
log("Dunno\n");
char sentence[80];
char chSentence[80];
char netname[30];
memset (sentence, 0, sizeof (sentence));
memset (chSentence, 0, sizeof (chSentence));
memset (netname, 0, sizeof (netname));
strcpy(sentence,(char *)p);
int length=0;
// FIXED: In any case that this might return NULL, do not crash the server
if (strstr (sentence, " : "))
length = strlen (sentence) - strlen (strstr (sentence, " : "));
int tc=0,c;
for (c=length; c < 80; c++)
{
chSentence[tc] = sentence[c];
tc++;
}
edict_t *pPlayer = INDEXENT (ucEntIndex);
strcpy(netname, STRING(pPlayer->v.netname));
ChatEngine.set_sentence(netname, chSentence);
state = -1;
}
}
}
else if (counterstrike==1)
{
// CS 1.6
if (state == 0)
{
// who sent this message?
ucEntIndex = *(unsigned char *)p;
}
// to who?
else if (state == 1)
{
// here must be some team check so we do not let bots
// of the other team react to this somehow..
}
// don't know?
else if (state == 2)
{
// do nothing here
}
// the actual sentence
else if (state == 3)
{
// sentence
char sentence[80];
char netname[30];
// init
memset (sentence, 0, sizeof (sentence));
memset (netname, 0, sizeof (netname));
// copy in memory
strcpy(sentence,(char *)p);
// copy netname
edict_t *pPlayer = INDEXENT (ucEntIndex);
strcpy(netname, STRING(pPlayer->v.netname));
// and give chatengine something to do
ChatEngine.set_sentence(netname, sentence);
state=-1;
}
}
state++;
}
note, it still needs to be optimized so that bots do NOT hear you when you are talking on team messages and such, but that should not be a real problem. Its just a bit of comparing strings "#Cstrike_Chat_All" and such. I might post an update of my source when that works too
