Friday, July 27, 2007

Respawn Instantly

Brought to you by blogger, Someone

Someone actually brought this to us a while back, and I apologize for taking so long to post it. Anyway, here's a tip that will allow you to respawn instantly after exploding. In LocalPlayer.cxx (in /src/bzflag/ of the extracted source), search for "else if (location == Exploding)" and you will find this section:

} else if (location == Exploding) {
// see if explosing time has expired
if (lastTime - getExplodeTime() >= BZDB.eval(StateDatabase::BZDB_EXPLODETIME)) {
dt -= float((lastTime - getExplodeTime()) - BZDB.eval(StateDatabase::BZDB_EXPLODETIME));
if (dt < 0.0f) {
dt = 0.0f;
}
setStatus(PlayerState::DeadStatus);
location = Dead;
if (isAutoPilot()) {
CMDMGR.run("restart");
}
}

// can't control explosion motion
newVelocity[2] += BZDBCache::gravity * dt;
newAngVel = 0.0f; // or oldAngVel to spin while exploding
} else if ((location == OnGround) || (location == OnBuilding) ||

First, let's look at the first through tenth lines from above:

} else if (location == Exploding) {
// see if explosing time has expired
if (lastTime - getExplodeTime() >= BZDB.eval(StateDatabase::BZDB_EXPLODETIME)) {
dt -= float((lastTime - getExplodeTime()) - BZDB.eval(StateDatabase::BZDB_EXPLODETIME));
if (dt < 0.0f) {
dt = 0.0f;
}
setStatus(PlayerState::DeadStatus);

Let's remove the second through seventh lines so that it now reads like this:

} else if (location == Exploding) {
setStatus(PlayerState::DeadStatus);

Next, notice this section:

setStatus(PlayerState::DeadStatus);
location = Dead;
if (isAutoPilot()) {
CMDMGR.run("restart");

Let's remove "location = Dead;" and "if (isAutoPilot()) {". Below the line "location = Dead;", add the following:

LocalPlayer *myTank = LocalPlayer::getMyTank();

Below that line, add this line:

myTank->setJumpPressed(false);

The above edits should now read like this:

setStatus(PlayerState::DeadStatus);
LocalPlayer *myTank = LocalPlayer::getMyTank();
myTank->setJumpPressed(false);
CMDMGR.run("restart");

Next, notice this section:

CMDMGR.run("restart");
}
}

// can't control explosion motion
newVelocity[2] += BZDBCache::gravity * dt;
newAngVel = 0.0f; // or oldAngVel to spin while exploding
} else if ((location == OnGround) || (location == OnBuilding) ||

Let's remove the lines between "CMDMGR.run("restart");" and " } else if ((location == OnGround) || (location == OnBuilding) ||" so that the section now reads like this:

CMDMGR.run("restart");
} else if ((location == OnGround) || (location == OnBuilding) ||

All of the above edits should now look like this:

} else if (location == Exploding) {
setStatus(PlayerState::DeadStatus);
LocalPlayer *myTank = LocalPlayer::getMyTank();
myTank->setJumpPressed(false);
CMDMGR.run("restart");
} else if ((location == OnGround) || (location == OnBuilding) ||

When you are finished, compile your client and you're done. To view Someone's original instructions, read his comment to "HOWTO: Drop Bad Flags Instantly" at the original blog, Cheating BZFlag.

As always...

Have fun!

No comments: