flagHeldWhenKilled not percise?

Questions, comments, and news on the server side plug-ins and it's API
Post Reply
Grue
Private First Class
Private First Class
Posts: 27
Joined: Tue Apr 08, 2014 12:23 am
Contact:

flagHeldWhenKilled not percise?

Post 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
User avatar
Zehra
Private First Class
Private First Class
Posts: 914
Joined: Sun Oct 18, 2015 3:36 pm
Location: Within the BZFS API and Beyond it
Contact:

Re: flagHeldWhenKilled not precise?

Post 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
Those who are critical of me, I'll likely be the same of them. ~Zehra
The decisions we make are the ones we look forward too and the ones we regret. ~Zehra
There's a difference between knowing my name and knowing me, one shows respect to my name and the other is to who I am. ~Zehra

See where I've last been active at Strayers.
Visit BZList.net for a modern HTML5 server stats site.

Click here to view the 101 Leaderboard & Score Summaries Last updated 2021-01-12 (YYYY-MM-DD)
Latest 101 thread
Post Reply