Page 1 of 1

flagHeldWhenKilled not percise?

Posted: Fri Mar 24, 2023 5:24 pm
by Grue
Hey all,

I've noticed a bug on my map Castle Scarwall which several people have brought to my attention.

If someone has a flag (lets say Quick Turn), drops it, and then gets shot by another player, the variable "flagHeldWhenKilled" will be "QT". However, in this scenario, the player dropped Quick Turn before they got shot, and the "flagHeldWhenKilled" variable should be "". Any idea why this variable has some kind of latency?

Most of the time this variable is accurate and works well when detecting the flag the player had when they died. However, sometimes like this, the variable will remain with the flag even if they drop it before they die.

Thanks,
Grue

Re: flagHeldWhenKilled not precise?

Posted: Fri Mar 24, 2023 6:43 pm
by Zehra
Tanks drop flags before death. You might want to keep track of the flag dropped event and death event.
So you might want to do something like the following:

Code: Select all

dropEvent: {
    droptime[playerID]=dropEvent->eventTime;
}

deathEvent: {
    if ((deathEvent->eventTime - droptime[playerID]) <= 0.5) { // half a second or less
    	// do stuff as if the flag is held.
    }
}
^The following should work, but needs to be adapted and an array.

---

For the code on why flagHeldWhenKilled has some latency to it.
In bzfs.cxx, if you search for the following:

Code: Select all

void playerKilled(int victimIndex, int killerIndex, int reason,
                  int16_t shotIndex, const FlagType* flagType, int phydrv, bool respawnOnBase )
Within this function, you'll find the following:

Code: Select all

    if (victim->haveFlag())   // this may not return true in the current protocol since tanks drop flags before death, when that's fixed the else wont' be needed
    {
        int flagid = victim->getFlag();
        if (flagid >= 0)
            dieEvent.flagHeldWhenKilled = flagid;
    }
    else if (victimData->lastHeldFlagID >= 0)
    {
        auto f = FlagInfo::get(victimData->lastHeldFlagID);

        if (f->flag.status != FlagOnGround) // if the last held flag was just a moment ago, they probably died with this.
            dieEvent.flagHeldWhenKilled = victimData->lastHeldFlagID;
    }
-Zehra