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
What is wrong with this?
- LouMan
- Chief Sgt. of Cartography
- Posts: 338
- Joined: Mon Jan 31, 2005 3:05 am
- Location: Michigan, USA
JeffM - thanks for the quick response.
I've tried using "R*", "Red Flag", "RedFlag" with bz_getPlayerFlag( int playerID ) and still no luck. I've also tried those variations with the player record's currentFlag (player->currentFlag, above) with no luck either.
I'm sorry to keep troubling you with this; it's probably a simple thing I am missing here...
I've tried using "R*", "Red Flag", "RedFlag" with bz_getPlayerFlag( int playerID ) and still no luck. I've also tried those variations with the player record's currentFlag (player->currentFlag, above) with no luck either.
I'm sorry to keep troubling you with this; it's probably a simple thing I am missing here...
- LouMan
- Chief Sgt. of Cartography
- Posts: 338
- Joined: Mon Jan 31, 2005 3:05 am
- Location: Michigan, USA
Ok, debugged some more and my problems might be related to how I am comparing:
FlagHeld = bz_getPlayerFlag(i);
if (FlagHeld == "R*")
RedLastTime = bz_getCurrentTime();
Through debugging I have found that FlagHeld does indeed contain "R*" when the red flag is held (or "L" with laser, "GM" with guided missile and so on). It seems that the boolean comparitor == is not working in this case. I also tried strcmp(FlagHeld, "R*") == 0 and it compiled ok, but crashed bzfs when I tried to join locally. FlagHeld is declared as const char *FlagHeld;
Forgive me if I am missing something that is probably obvious here. I have only a little experience with data types and their manipulation.
FlagHeld = bz_getPlayerFlag(i);
if (FlagHeld == "R*")
RedLastTime = bz_getCurrentTime();
Through debugging I have found that FlagHeld does indeed contain "R*" when the red flag is held (or "L" with laser, "GM" with guided missile and so on). It seems that the boolean comparitor == is not working in this case. I also tried strcmp(FlagHeld, "R*") == 0 and it compiled ok, but crashed bzfs when I tried to join locally. FlagHeld is declared as const char *FlagHeld;
Forgive me if I am missing something that is probably obvious here. I have only a little experience with data types and their manipulation.
- LouMan
- Chief Sgt. of Cartography
- Posts: 338
- Joined: Mon Jan 31, 2005 3:05 am
- Location: Michigan, USA
trepan - long time no see and thanks for the tip. It dawned on me before I went to sleep last night that the null return from bz_getPlayerFlag() was probably the culprit for the crash and I was going to try that method today.
Thanks again, and I hope all is well.
LouMan
** Just tried it and that was the trick Thanks for your help JeffM and trepan!
Thanks again, and I hope all is well.
LouMan
** Just tried it and that was the trick Thanks for your help JeffM and trepan!