What is wrong with this?
Posted: Fri Dec 22, 2006 11:36 pm
I am in the process of hacking out a simple plugin to reset flags when a team's flag has been idle too long. Ideally, the plugin would reset the team flags individually, but since the only function available is a general flag reset, that's what I am using.
I am having trouble in only one area of the code - I have looked at this 100 times and can't see what I am doing wrong. For some reason that I cannot fathom, the conditional statements testing for the flag a player is holding, e.g.:
if (player->currentFlag == "R*")
RedLastTime = bz_getCurrentTime();
never are true, even though I know that a player has the red flag (e.g). Am I using the wrong type of argument?
The surrounding code is below:
void TeamFlagResetHandler::process ( bz_EventData *eventData )
{
if (eventData->eventType != bz_eTickEvent)
return;
bzAPIIntList *playerList = bz_newIntList();
bz_getPlayerIndexList ( playerList );
RedTeamCount = 0;
GreenTeamCount = 0;
BlueTeamCount = 0;
PurpleTeamCount = 0;
// check to see if anyone has picked up a team flag & count players per team
for ( unsigned int i = 0; i < playerList->size(); i++ ){
bz_PlayerRecord *player = bz_getPlayerByIndex(i);
if (player->currentFlag == "R*")
RedLastTime = bz_getCurrentTime();
if (player->currentFlag == "G*")
GreenLastTime = bz_getCurrentTime();
if (player->currentFlag == "B*")
BlueLastTime = bz_getCurrentTime();
if (player->currentFlag == "P*")
PurpleLastTime = bz_getCurrentTime();
if (player->team == eRedTeam)
RedTeamCount++;
if (player->team == eGreenTeam)
RedTeamCount++;
if (player->team == eBlueTeam)
RedTeamCount++;
if (player->team == ePurpleTeam)
RedTeamCount++;
bz_freePlayerRecord(player);
}
bz_deleteIntList(playerList); ... and so on ...
Any help on this would be appreciated
I am having trouble in only one area of the code - I have looked at this 100 times and can't see what I am doing wrong. For some reason that I cannot fathom, the conditional statements testing for the flag a player is holding, e.g.:
if (player->currentFlag == "R*")
RedLastTime = bz_getCurrentTime();
never are true, even though I know that a player has the red flag (e.g). Am I using the wrong type of argument?
The surrounding code is below:
void TeamFlagResetHandler::process ( bz_EventData *eventData )
{
if (eventData->eventType != bz_eTickEvent)
return;
bzAPIIntList *playerList = bz_newIntList();
bz_getPlayerIndexList ( playerList );
RedTeamCount = 0;
GreenTeamCount = 0;
BlueTeamCount = 0;
PurpleTeamCount = 0;
// check to see if anyone has picked up a team flag & count players per team
for ( unsigned int i = 0; i < playerList->size(); i++ ){
bz_PlayerRecord *player = bz_getPlayerByIndex(i);
if (player->currentFlag == "R*")
RedLastTime = bz_getCurrentTime();
if (player->currentFlag == "G*")
GreenLastTime = bz_getCurrentTime();
if (player->currentFlag == "B*")
BlueLastTime = bz_getCurrentTime();
if (player->currentFlag == "P*")
PurpleLastTime = bz_getCurrentTime();
if (player->team == eRedTeam)
RedTeamCount++;
if (player->team == eGreenTeam)
RedTeamCount++;
if (player->team == eBlueTeam)
RedTeamCount++;
if (player->team == ePurpleTeam)
RedTeamCount++;
bz_freePlayerRecord(player);
}
bz_deleteIntList(playerList); ... and so on ...
Any help on this would be appreciated