What is wrong with this?

Questions, comments, and news on the server side plug-ins and it's API
Post Reply
User avatar
LouMan
Chief Sgt. of Cartography
Chief Sgt. of Cartography
Posts: 338
Joined: Mon Jan 31, 2005 3:05 am
Location: Michigan, USA

What is wrong with this?

Post 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)
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 :)
User avatar
JeffM
Staff Sergeant
Staff Sergeant
Posts: 5196
Joined: Fri Dec 13, 2002 4:11 am

Post 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.
ImageJeffM
User avatar
LouMan
Chief Sgt. of Cartography
Chief Sgt. of Cartography
Posts: 338
Joined: Mon Jan 31, 2005 3:05 am
Location: Michigan, USA

Post 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...
User avatar
JeffM
Staff Sergeant
Staff Sergeant
Posts: 5196
Joined: Fri Dec 13, 2002 4:11 am

Post by JeffM »

log out what the flag function is returning. I don't remember the code for the teams.
ImageJeffM
User avatar
LouMan
Chief Sgt. of Cartography
Chief Sgt. of Cartography
Posts: 338
Joined: Mon Jan 31, 2005 3:05 am
Location: Michigan, USA

Post 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.
trepan
Dev Wizard
Dev Wizard
Posts: 704
Joined: Fri Feb 21, 2003 7:50 pm

Post 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.
User avatar
LouMan
Chief Sgt. of Cartography
Chief Sgt. of Cartography
Posts: 338
Joined: Mon Jan 31, 2005 3:05 am
Location: Michigan, USA

Post 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.

LouMan

** Just tried it and that was the trick :) Thanks for your help JeffM and trepan!
User avatar
L4m3r
Hater of Everything
Hater of Everything
Posts: 724
Joined: Tue Feb 08, 2005 5:15 am
Location: Los Angeles

Post 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...
Optimism is just a milder alternative to denial.
Post Reply