What Actually Sets Walk/run For Players And Pets?

I’ve been trying to fix the issue of pets lagging behind but I can’t get VS to break when I press the hotkey that toggles run/walk.

I’ve set breakpoints on SetSpeed() and several others but the only break I get is HandleMovementOpCode() but nowhere does that ever call SetSpeed() or any function related to speed.

I even rewrote this: FollowMovementGenerator::_updateSpeed


	if (u.isPet() && u.GetCharmInfo())

	{

		if (u.GetCharmInfo()->IsReturning() || (u.GetDistance(u.GetCharmerOrOwner()) > PET_FOLLOW_DIST + u.GetMeleeReach()))

		{

			// Force run for these situations:

			//  * Pet returning from stay or combat

			//  * Distance from owner too far (most likely due to lag)

			//	 Note: Distance is arbitrary. Added GetMeleeReach() to allow for some slack.

			// This allows pets to catch up even if the owner is walking


			//u.SetWalk(false); // doesn't work, pet is already NOT walking

			//u.SetSpeed(MOVE_RUN, u.GetSpeed(MOVE_RUN), true); // doesn't work, speed is set to 1.0f


			// These have no effect because SetSpeed() gets called from UpdateSpeed() and checks

			//  this: if (m_speed_rate[mtype] == rate) and because it is equal it exits the function

			u.UpdateSpeed(MOVE_RUN,false);

			u.UpdateSpeed(MOVE_WALK,false);

			u.UpdateSpeed(MOVE_SWIM,false);

		}

		else

		{

			// only match owner's speed if pet isn't returning

			u.UpdateSpeed(MOVE_RUN,true);

			u.UpdateSpeed(MOVE_WALK,true);

			u.UpdateSpeed(MOVE_SWIM,true);

		}

	}

but it doesn’t work (see comments in code). The call to SetSpeed() just sets the pet’s speed to 1.0f which is walking anyway…

Any advice where to begin would be appreciated, thanks.

There is no speed change on the run/walk toggle, its not handled serverside

Interesting.

How does the server keep track of where the player is during run vs. walk since you cover more distance when running? Also, what are these for:

MSG_MOVE_SET_RUN_MODE, MSG_MOVE_SET_WALK_MODE

They are used in WorldSession::HandleMovementOpcodes() which is called when you press the hotkey. Does the server just throw them away?

It does not keep track of it, they are just not handled, the client sends the coordinates and the server believes it, its not the best design, but its what we have right now

Ok, then what makes the pet walk when the owner walks? That isn’t a client issue. There must be a way to tell the pet to run.

nvm

I have an idea but was curious about the MotionMaster…

Would it cause a memory leak or other problems if you add a “chase” motion to an entity that already has a “follow” motion without calling Clear() first? I was thinking that after the “chase” motion finalizes it would drop back to the existing “follow”… correct?

Edit:

Well, through trial and error I’ve realized it’s not good to Clear() a Motion type from within that same motion type. It crashes the server very quickly LOL.

Anyway, I think I’ve got a solution for the OP, just need to work out one final thing… setting the pet back to walking if the owner is walking after it catches up.