**CLIENT SIDED**
In Client.java add this method
public int followPlayer = 0;
public int followNPC = 0;
public int followDistance = 1;
Now under "private void resetLogout() {" add
followPlayer = 0;
followNPC = 0;
followDistance = 1;
Now add this void in Client.java
public int canWalkDelay = 0;
public int getDis(int coordX1, int coordY1, int coordX2, int coordY2)
{
int deltaX = coordX2 - coordX1;
int deltaY = coordY2 - coordY1;
return ((int)Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2)));
}
public int random(int range)
{
return (int)(Math.random() * range);
}
public boolean withinDistance(int x1, int y1, int x2, int y2, int dis)
{
for (int i = 0; i <= dis; i++)
{
try{
if ((x1 + i) == x2 && ((y1 + i) == y2 || (y1 - i) == y2 || y1 == y2))
return true;
else
if ((x1 - i) == x2 && ((x1 + i) == y2 || (y1 - i) == y2 || y1 == y2))
return true;
else
if (x1 == x2 && ((x1 + i) == y2 || (y1 - i) == y2 || y1 == y2))
return true;
} catch(Exception ex){
System.out.println("Exception in following, method : WithingDistance");
}
}
return false;
}
Add this under "private void mainGameProcessor() below if(!loggedIn) return;"
try{
canWalkDelay--;
if (followNPC > 0)
{
NPC n = npcArray[followNPC];
if (n != null)
{
if (!withinDistance(myPlayer.smallX[0], myPlayer.smallY[0], n.smallX[0], n.smallY[0], followDistance))
{
doWalkTo(2, 0, 1, 0, myPlayer.smallY[0], 1, 0, n.smallY[0], myPlayer.smallX[0], false, n.smallX[0]);
}
}
}
else if (followPlayer > 0 && canWalkDelay <= 0)
{
Player p = playerArray[followPlayer];
if (p != null)
{
int dis = getDis(myPlayer.smallX[0], myPlayer.smallY[0], p.smallX[0], p.smallY[0]);
if (dis > followDistance)
{
doWalkTo(2, 0, 1, 0, myPlayer.smallY[0], followDistance, 0, p.smallY[0], myPlayer.smallX[0], false, p.smallX[0]);
canWalkDelay = 30;
}
else if (dis == 0)
{
int rnd = random(4);
if (rnd == 0)
{
doWalkTo(2, 0, 1, 0, myPlayer.smallY[0], 1, 0, p.smallY[0], myPlayer.smallX[0], false, p.smallX[0] - 2);
}
else if (rnd == 1)
{
doWalkTo(2, 0, 1, 0, myPlayer.smallY[0], 1, 0, p.smallY[0], myPlayer.smallX[0], false, p.smallX[0] + 2);
}
else if (rnd == 2)
{
doWalkTo(2, 0, 1, 0, myPlayer.smallY[0], 1, 0, p.smallY[0] - 2, myPlayer.smallX[0], false, p.smallX[0]);
}
else if (rnd == 3)
{
doWalkTo(2, 0, 1, 0, myPlayer.smallY[0], 1, 0, p.smallY[0] + 2, myPlayer.smallX[0], false, p.smallX[0]);
}
canWalkDelay = 60;
}
}
}
} catch(Exception ex){
System.out.println("Exception in following, method : in process.)");
}
Now replace "case 174:" with this
case 174:
/*Empty Following Packet*/
followPlayer = 0;
followNPC = 0;
int l11z = inStream.readUnsignedWord();
int iq = inStream.readUnsignedByte();
followDistance = inStream.readUnsignedWord();
if (iq == 0)
{
followNPC = l11z;
}
else if (iq == 1)
{
followPlayer = l11z;
}
pktType = -1;
return true;
**SERVER SIDED**
In Client.java add this
public void applyFollowing()
{
if (follow2 > 0)
{
//Client p = Server.playerHandler.client[followId];
Client p = (Client) Server.playerHandler.players[follow2];
if (p != null)
{
if (isDead)
{
follow(0, 3, 1);
return;
}
if (!goodDistance(p.absX, p.absY, absX, absY, 25))
{
follow(0, 3, 1);
return;
}
}
else if (p == null)
{
follow(0, 3, 1);
}
}
else if (follow2 > 0)
{
//Server.npcHandler.npcs.NPC npc = Server.npcHandler.npcs[followId2];
if (Server.npcHandler.npcs[followId2] != null)
{
if (Server.npcHandler.npcs[followId2].isDead)
{
follow(0, 3, 1);
return;
}
if (!goodDistance(Server.npcHandler.npcs[followId2].absX, Server.npcHandler.npcs[followId2].absY, absX, absY, 25))
{
follow(0, 3, 1);
return;
}
}
else if (Server.npcHandler.npcs[followId2] == null)
{
follow(0, 3, 1);
}
}
}
public int followDistance = 0;
public void follow(int slot, int type, int distance)
{
if (slot > 0 && slot == follow2 && type == 1 && follow2 > 0 && followDistance != distance && (/*usingOtherRangeWeapons || */usingBow || usingMagic))
return;
else if (slot > 0 && slot == followId2 && type == 0 && followId2 > 0 && followDistance >= distance && distance != 1)
return;
//else if (type == 3 && followId2 == 0 && follow2 == 0)
//return;
outStream.createFrame(174);
if (freezeTimer > 0) {
outStream.writeWord(0);
} else {
outStream.writeWord(slot);
if (type == 0) {
follow2 = 0;
followId2 = slot;
faceUpdate(followId2);
} else if (type == 1) {
followId2 = 0;
follow2 = slot;
faceUpdate(32768 + follow2);
} else if (type == 3) {
followId2 = 0;
follow2 = 0;
followDistance = 0;
faceUpdate(65535);
}
followDistance = distance;
}
outStream.writeByte(type);
outStream.writeWord(distance);
}
Now search for
getPA().resetFollow();and delete it!
Now search for "process()" and add these two methods underneath it
applyFollowing();
if(followId > 0) {
getPA().followPlayer();
} else if (followId2 > 0) {
getPA().followNpc();
}Now open up Player.java and add this
public int follow2 = 0;
followId,
followDistance,
followId2,
Now replace your Followplayer.java with this
package server.model.players.packets;
import server.Server;
import server.model.players.Client;
import server.model.players.PacketType;
/**
* Follow Player by Tyluur.
**/
public class FollowPlayer implements PacketType {
@Override
public void processPacket(Client c, int packetType, int packetSize) {
/*int followPlayer = c.getInStream().readUnsignedWordBigEndian();
if(Server.playerHandler.players[followPlayer] == null) {
return;
}
c.playerIndex = 0;
c.npcIndex = 0;
c.mageFollow = false;
c.usingBow = false;
c.usingRangeWeapon = false;
c.followDistance = 1;
c.followId = followPlayer;*/
int toFollow = c.getInStream().readUnsignedWordBigEndian();
c.follow2 = toFollow;
if (Server.playerHandler.players[toFollow] == null)
return;
c.faceUpdate(32768+toFollow);
c.follow(toFollow, 1, 1);
}}and your Walking.java with this!
package server.model.players.packets;
import server.Server;
import server.model.players.Client;
import server.model.players.PacketType;
/**
* Walking packet
**/
public class Walking implements PacketType {
@Override
public void processPacket(Client c, int packetType, int packetSize) {
if (c.isBanking)
c.isBanking = false;
if (packetType == 248 || packetType == 164) {
c.faceUpdate(0);
c.npcIndex = 0;
c.playerIndex = 0;
if (c.followId > 0 || c.followId2 > 0 || c.follow2 > 0)
c.getPA().resetFollow();
}
c.getPA().removeAllWindows();
if(c.duelRule[1] && c.duelStatus == 5) {
if(Server.playerHandler.players[c.duelingWith] != null) {
if(!c.goodDistance(c.getX(), c.getY(), Server.playerHandler.players[c.duelingWith].getX(), Server.playerHandler.players[c.duelingWith].getY(), 1) || c.attackTimer == 0) {
c.sendMessage("Walking has been disabled in this duel!");
}
}
c.playerIndex = 0;
return;
}
if(c.freezeTimer > 0) {
if(Server.playerHandler.players[c.playerIndex] != null) {
if(c.goodDistance(c.getX(), c.getY(), Server.playerHandler.players[c.playerIndex].getX(), Server.playerHandler.players[c.playerIndex].getY(), 1) && packetType != 98) {
c.playerIndex = 0;
return;
}
}
if (packetType != 98) {
c.sendMessage("A magical force stops you from moving.");
c.playerIndex = 0;
}
return;
}
if (System.currentTimeMillis() - c.lastSpear < 4000) {
c.sendMessage("You have been stunned.");
c.playerIndex = 0;
return;
}
if (packetType == 98) {
c.mageAllowed = true;
}
if((c.duelStatus >= 1 && c.duelStatus <= 4) || c.duelStatus == 6) {
if(c.duelStatus == 6) {
c.getTradeAndDuel().claimStakedItems();
}
return;
}
if(c.respawnTimer > 3) {
return;
}
if(c.inTrade) {
return;
}
if(packetType == 248) {
packetSize -= 14;
}
c.newWalkCmdSteps = (packetSize - 5)/2;
if(++c.newWalkCmdSteps > c.walkingQueueSize) {
c.newWalkCmdSteps = 0;
return;
}
c.getNewWalkCmdX()[0] = c.getNewWalkCmdY()[0] = 0;
int firstStepX = c.getInStream().readSignedWordBigEndianA()-c.getMapRegionX()*8;
for(int i = 1; i < c.newWalkCmdSteps; i++) {
c.getNewWalkCmdX()[i] = c.getInStream().readSignedByte();
c.getNewWalkCmdY()[i] = c.getInStream().readSignedByte();
}
int firstStepY = c.getInStream().readSignedWordBigEndian()-c.getMapRegionY()*8;
c.setNewWalkCmdIsRunning(c.getInStream().readSignedByteC() == 1);
for(int i1 = 0; i1 < c.newWalkCmdSteps; i1++) {
c.getNewWalkCmdX()[i1] += firstStepX;
c.getNewWalkCmdY()[i1] += firstStepY;
}
}
}