Page 1 of 1

What is wrong with this?

Posted: Fri Dec 22, 2006 11:36 pm
by LouMan
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)

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)
if (player->team == eGreenTeam)
if (player->team == eBlueTeam)
if (player->team == ePurpleTeam)


bz_deleteIntList(playerList); ... and so on ...

Any help on this would be appreciated :)

Posted: Sat Dec 23, 2006 1:54 am
by JeffM
you want to probably use BZF_API const char* bz_getPlayerFlag( int playerID );

the field in the player record has the full flag name, not the abbreviation.

Posted: Sat Dec 23, 2006 3:52 am
by LouMan
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...

Posted: Sat Dec 23, 2006 4:07 am
by JeffM
log out what the flag function is returning. I don't remember the code for the teams.

Posted: Sat Dec 23, 2006 5:29 am
by LouMan
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.

Posted: Sat Dec 23, 2006 6:55 am
by trepan
Unfortunately, it looks like bz_getPlayerFlag() can return
NULL pointers (rather then returning a pointer to an empty
string). The strcmp() call looks right, just check for a NULL
value before doing it.

Posted: Sat Dec 23, 2006 1:50 pm
by LouMan
trepan - long time no see :wink: 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.


** Just tried it and that was the trick :) Thanks for your help JeffM and trepan!

Posted: Sat Dec 23, 2006 8:42 pm
by L4m3r
For future reference, iirc the player record data member for the flag uses "Red Team flag" (or some variant with different capitalization) for team flags. Took me a while to figure that one out...