Advertisement
Guest User

SERVER SIDE: CLIPPED FOLLOWING

a guest
Nov 4th, 2011
13,917
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 13.88 KB | None | 0 0
  1. Tired of seeing people trying to sell this when it was released, just no one ever made a tutorial for it. So, I will make one for you.. This is a spoon-feed tutorial. This will allow server side clipping when following. If this gets removed for whatever reason. Save this pastebin or bookmark it. [Java] SERVER SIDE: CLIPPED FOLLOWING - Pastebin.com - Open source or nothing.
  2.  
  3. Note: I did not program this system. I take no credits for this system. Do not ask me for help with this system. If you want to say leeched, or anything stupid.. Feel free to because in the end, you can go fuck yourself.
  4.  
  5. Edit: The Region class appears to some how been leaked from Palidino, which is a mystery to him, as he never released it and he only had access to it. It appears to be identical to the one he created in early to mid 2010. He will be given full credits for this until someone want's to debate the ownership or steps forward to debate this. 100% credits to Palidino for the Region class. You can contact him through his profile here -Palidino
  6.  
  7. Media - GIF
  8. Spoiler for GIF IMAGE:
  9. http://dl.dropbox.com/u/21484852/capture-21.gif
  10.  
  11.  
  12. FIRST:
  13. Download clip.rar and extract it and place this folder inside your server folder - it should now look like src/server/clip
  14. Now inside the clip folder, go into the region folder and open up both ObjectDef.java and Region.java and replace the paths for the files to be loaded to suit your directories (you may not need to change them).
  15.  
  16. Download: http://dl.dropbox.com/u/21484852/clip.rar
  17.  
  18.  
  19. SECOND:
  20. Download world.rar and extract it, place this folder inside your data directory.
  21. e.g servername/Data/WORLD FOLDER HERE
  22.  
  23. Download: http://dl.dropbox.com/u/21484852/world.rar
  24.  
  25.  
  26. THIRD:
  27. Create a new class, name it Pathfinder.java - paste the following code in it and save it to your server.model.players folder.
  28.  
  29. Code:
  30. package server.model.players;
  31.  
  32. import java.util.LinkedList;
  33.  
  34. import server.clip.region.Region;
  35. import server.model.players.Client;
  36.  
  37. public class PathFinder {
  38.  
  39.     private static final PathFinder pathFinder = new PathFinder();
  40.  
  41.     public static PathFinder getPathFinder() {
  42.         return pathFinder;
  43.     }
  44.  
  45.     public PathFinder() {
  46.     }
  47.  
  48.     public void findRoute(Client c, int destX, int destY, boolean moveNear,
  49.             int xLength, int yLength) {
  50.         if (destX == c.getLocalX() && destY == c.getLocalY() && !moveNear) {
  51.             c.sendMessage("ERROR!");
  52.             return;
  53.         }
  54.         destX = destX - 8 * c.getMapRegionX();
  55.         destY = destY - 8 * c.getMapRegionY();
  56.         int[][] via = new int[104][104];
  57.         int[][] cost = new int[104][104];
  58.         LinkedList<Integer> tileQueueX = new LinkedList<Integer>();
  59.         LinkedList<Integer> tileQueueY = new LinkedList<Integer>();
  60.         for (int xx = 0; xx < 104; xx++) {
  61.             for (int yy = 0; yy < 104; yy++) {
  62.                 cost[xx][yy] = 99999999;
  63.             }
  64.         }
  65.         int curX = c.getLocalX();
  66.         int curY = c.getLocalY();
  67.         via[curX][curY] = 99;
  68.         cost[curX][curY] = 0;
  69.         int tail = 0;
  70.         tileQueueX.add(curX);
  71.         tileQueueY.add(curY);
  72.         boolean foundPath = false;
  73.         int pathLength = 4000;
  74.         while (tail != tileQueueX.size() && tileQueueX.size() < pathLength) {
  75.             curX = tileQueueX.get(tail);
  76.             curY = tileQueueY.get(tail);
  77.             int curAbsX = c.getMapRegionX() * 8 + curX;
  78.             int curAbsY = c.getMapRegionY() * 8 + curY;
  79.             if (curX == destX && curY == destY) {
  80.                 foundPath = true;
  81.                 break;
  82.             }
  83.             tail = (tail + 1) % pathLength;
  84.             int thisCost = cost[curX][curY] + 1;
  85.             if (curY > 0
  86.                     && via[curX][curY - 1] == 0
  87.                     && (Region.getClipping(curAbsX, curAbsY - 1, c.heightLevel) & 0x1280102) == 0) {
  88.                 tileQueueX.add(curX);
  89.                 tileQueueY.add(curY - 1);
  90.                 via[curX][curY - 1] = 1;
  91.                 cost[curX][curY - 1] = thisCost;
  92.             }
  93.             if (curX > 0
  94.                     && via[curX - 1][curY] == 0
  95.                     && (Region.getClipping(curAbsX - 1, curAbsY, c.heightLevel) & 0x1280108) == 0) {
  96.                 tileQueueX.add(curX - 1);
  97.                 tileQueueY.add(curY);
  98.                 via[curX - 1][curY] = 2;
  99.                 cost[curX - 1][curY] = thisCost;
  100.             }
  101.             if (curY < 104 - 1
  102.                     && via[curX][curY + 1] == 0
  103.                     && (Region.getClipping(curAbsX, curAbsY + 1, c.heightLevel) & 0x1280120) == 0) {
  104.                 tileQueueX.add(curX);
  105.                 tileQueueY.add(curY + 1);
  106.                 via[curX][curY + 1] = 4;
  107.                 cost[curX][curY + 1] = thisCost;
  108.             }
  109.             if (curX < 104 - 1
  110.                     && via[curX + 1][curY] == 0
  111.                     && (Region.getClipping(curAbsX + 1, curAbsY, c.heightLevel) & 0x1280180) == 0) {
  112.                 tileQueueX.add(curX + 1);
  113.                 tileQueueY.add(curY);
  114.                 via[curX + 1][curY] = 8;
  115.                 cost[curX + 1][curY] = thisCost;
  116.             }
  117.             if (curX > 0
  118.                     && curY > 0
  119.                     && via[curX - 1][curY - 1] == 0
  120.                     && (Region.getClipping(curAbsX - 1, curAbsY - 1,
  121.                             c.heightLevel) & 0x128010e) == 0
  122.                     && (Region.getClipping(curAbsX - 1, curAbsY, c.heightLevel) & 0x1280108) == 0
  123.                     && (Region.getClipping(curAbsX, curAbsY - 1, c.heightLevel) & 0x1280102) == 0) {
  124.                 tileQueueX.add(curX - 1);
  125.                 tileQueueY.add(curY - 1);
  126.                 via[curX - 1][curY - 1] = 3;
  127.                 cost[curX - 1][curY - 1] = thisCost;
  128.             }
  129.             if (curX > 0
  130.                     && curY < 104 - 1
  131.                     && via[curX - 1][curY + 1] == 0
  132.                     && (Region.getClipping(curAbsX - 1, curAbsY + 1,
  133.                             c.heightLevel) & 0x1280138) == 0
  134.                     && (Region.getClipping(curAbsX - 1, curAbsY, c.heightLevel) & 0x1280108) == 0
  135.                     && (Region.getClipping(curAbsX, curAbsY + 1, c.heightLevel) & 0x1280120) == 0) {
  136.                 tileQueueX.add(curX - 1);
  137.                 tileQueueY.add(curY + 1);
  138.                 via[curX - 1][curY + 1] = 6;
  139.                 cost[curX - 1][curY + 1] = thisCost;
  140.             }
  141.             if (curX < 104 - 1
  142.                     && curY > 0
  143.                     && via[curX + 1][curY - 1] == 0
  144.                     && (Region.getClipping(curAbsX + 1, curAbsY - 1,
  145.                             c.heightLevel) & 0x1280183) == 0
  146.                     && (Region.getClipping(curAbsX + 1, curAbsY, c.heightLevel) & 0x1280180) == 0
  147.                     && (Region.getClipping(curAbsX, curAbsY - 1, c.heightLevel) & 0x1280102) == 0) {
  148.                 tileQueueX.add(curX + 1);
  149.                 tileQueueY.add(curY - 1);
  150.                 via[curX + 1][curY - 1] = 9;
  151.                 cost[curX + 1][curY - 1] = thisCost;
  152.             }
  153.             if (curX < 104 - 1
  154.                     && curY < 104 - 1
  155.                     && via[curX + 1][curY + 1] == 0
  156.                     && (Region.getClipping(curAbsX + 1, curAbsY + 1,
  157.                             c.heightLevel) & 0x12801e0) == 0
  158.                     && (Region.getClipping(curAbsX + 1, curAbsY, c.heightLevel) & 0x1280180) == 0
  159.                     && (Region.getClipping(curAbsX, curAbsY + 1, c.heightLevel) & 0x1280120) == 0) {
  160.                 tileQueueX.add(curX + 1);
  161.                 tileQueueY.add(curY + 1);
  162.                 via[curX + 1][curY + 1] = 12;
  163.                 cost[curX + 1][curY + 1] = thisCost;
  164.             }
  165.         }
  166.         if (!foundPath) {
  167.             if (moveNear) {
  168.                 int i_223_ = 1000;
  169.                 int thisCost = 100;
  170.                 int i_225_ = 10;
  171.                 for (int x = destX - i_225_; x <= destX + i_225_; x++) {
  172.                     for (int y = destY - i_225_; y <= destY + i_225_; y++) {
  173.                         if (x >= 0 && y >= 0 && x < 104 && y < 104
  174.                                 && cost[x][y] < 100) {
  175.                             int i_228_ = 0;
  176.                             if (x < destX) {
  177.                                 i_228_ = destX - x;
  178.                             } else if (x > destX + xLength - 1) {
  179.                                 i_228_ = x - (destX + xLength - 1);
  180.                             }
  181.                             int i_229_ = 0;
  182.                             if (y < destY) {
  183.                                 i_229_ = destY - y;
  184.                             } else if (y > destY + yLength - 1) {
  185.                                 i_229_ = y - (destY + yLength - 1);
  186.                             }
  187.                             int i_230_ = i_228_ * i_228_ + i_229_ * i_229_;
  188.                             if (i_230_ < i_223_
  189.                                     || (i_230_ == i_223_ && (cost[x][y] < thisCost))) {
  190.                                 i_223_ = i_230_;
  191.                                 thisCost = cost[x][y];
  192.                                 curX = x;
  193.                                 curY = y;
  194.                             }
  195.                         }
  196.                     }
  197.                 }
  198.                 if (i_223_ == 1000) {
  199.                     return;
  200.                 }
  201.             } else {
  202.                 return;
  203.             }
  204.         }
  205.         tail = 0;
  206.         tileQueueX.set(tail, curX);
  207.         tileQueueY.set(tail++, curY);
  208.         int l5;
  209.         for (int j5 = l5 = via[curX][curY]; curX != c.getLocalX()
  210.                 || curY != c.getLocalY(); j5 = via[curX][curY]) {
  211.             if (j5 != l5) {
  212.                 l5 = j5;
  213.                 tileQueueX.set(tail, curX);
  214.                 tileQueueY.set(tail++, curY);
  215.             }
  216.             if ((j5 & 2) != 0) {
  217.                 curX++;
  218.             } else if ((j5 & 8) != 0) {
  219.                 curX--;
  220.             }
  221.             if ((j5 & 1) != 0) {
  222.                 curY++;
  223.             } else if ((j5 & 4) != 0) {
  224.                 curY--;
  225.             }
  226.         }
  227.         c.resetWalkingQueue();
  228.         int size = tail--;
  229.         int pathX = c.getMapRegionX() * 8 + tileQueueX.get(tail);
  230.         int pathY = c.getMapRegionY() * 8 + tileQueueY.get(tail);
  231.         c.addToWalkingQueue(localize(pathX, c.getMapRegionX()),
  232.                 localize(pathY, c.getMapRegionY()));
  233.         for (int i = 1; i < size; i++) {
  234.             tail--;
  235.             pathX = c.getMapRegionX() * 8 + tileQueueX.get(tail);
  236.             pathY = c.getMapRegionY() * 8 + tileQueueY.get(tail);
  237.             c.addToWalkingQueue(localize(pathX, c.getMapRegionX()),
  238.                     localize(pathY, c.getMapRegionY()));
  239.         }
  240.     }
  241.  
  242.     public int localize(int x, int mapRegion) {
  243.         return x - 8 * mapRegion;
  244.     }
  245.  
  246. }
  247.  
  248.  
  249. FOURTH:
  250. Open up playerAssistant.java and add this anywhere you like.
  251.  
  252. Code:
  253.     public void playerWalk(int x, int y) {
  254.         PathFinder.getPathFinder().findRoute(c, x, y, true, 1, 1);
  255.     }
  256. Then search for public void followPlayer() and replace it with the one below.
  257.  
  258. Code:
  259.     public void followPlayer() {
  260.         if (PlayerHandler.players[c.followId] == null
  261.                 || PlayerHandler.players[c.followId].isDead) {
  262.             resetFollow();
  263.             return;
  264.         }
  265.         if (c.freezeTimer > 0) {
  266.             return;
  267.         }
  268.         if (c.isDead || c.playerLevel[3] <= 0)
  269.             return;
  270.    
  271.         int otherX = PlayerHandler.players[c.followId].getX();
  272.         int otherY = PlayerHandler.players[c.followId].getY();
  273.  
  274.         boolean sameSpot = (c.absX == otherX && c.absY == otherY);
  275.  
  276.         boolean hallyDistance = c.goodDistance(otherX, otherY, c.getX(),
  277.                 c.getY(), 2);
  278.  
  279.         boolean rangeWeaponDistance = c.goodDistance(otherX, otherY, c.getX(),
  280.                 c.getY(), 4);
  281.         boolean bowDistance = c.goodDistance(otherX, otherY, c.getX(),
  282.                 c.getY(), 6);
  283.         boolean mageDistance = c.goodDistance(otherX, otherY, c.getX(),
  284.                 c.getY(), 7);
  285.  
  286.         boolean castingMagic = (c.usingMagic || c.mageFollow || c.autocasting || c.spellId > 0)
  287.                 && mageDistance;
  288.         boolean playerRanging = (c.usingRangeWeapon)
  289.                 && rangeWeaponDistance;
  290.         boolean playerBowOrCross = (c.usingBow) && bowDistance;
  291.  
  292.         if (!c.goodDistance(otherX, otherY, c.getX(), c.getY(), 25)) {
  293.             c.followId = 0;
  294.             resetFollow();
  295.             return;
  296.         }
  297.         c.faceUpdate(c.followId + 32768);
  298.         if (!sameSpot) {
  299.             if (c.playerIndex > 0 && !c.usingSpecial && c.inWild()) {
  300.                 if (c.usingSpecial && (playerRanging || playerBowOrCross)) {
  301.                     c.stopMovement();
  302.                     return;
  303.                 }
  304.                 if (castingMagic || playerRanging || playerBowOrCross) {
  305.                     c.stopMovement();
  306.                     return;
  307.                 }
  308.                 if (c.getCombat().usingHally() && hallyDistance) {
  309.                     c.stopMovement();
  310.                     return;
  311.                 }
  312.             }
  313.         }
  314.         if (otherX == c.absX && otherY == c.absY) {
  315.             int r = Misc.random(3);
  316.             switch (r) {
  317.             case 0:
  318.                 walkTo(0, -1);
  319.                 break;
  320.             case 1:
  321.                 walkTo(0, 1);
  322.                 break;
  323.             case 2:
  324.                 walkTo(1, 0);
  325.                 break;
  326.             case 3:
  327.                 walkTo(-1, 0);
  328.                 break;
  329.             }
  330.         } else if (c.isRunning2) {
  331.             if (otherY > c.getY() && otherX == c.getX()) {
  332.                 playerWalk(otherX, otherY - 1);
  333.             } else if (otherY < c.getY() && otherX == c.getX()) {
  334.                 playerWalk(otherX, otherY + 1);
  335.             } else if (otherX > c.getX() && otherY == c.getY()) {
  336.                 playerWalk(otherX - 1, otherY);
  337.             } else if (otherX < c.getX() && otherY == c.getY()) {
  338.                 playerWalk(otherX + 1, otherY);
  339.             } else if (otherX < c.getX() && otherY < c.getY()) {
  340.                 playerWalk(otherX + 1, otherY + 1);
  341.             } else if (otherX > c.getX() && otherY > c.getY()) {
  342.                 playerWalk(otherX - 1, otherY - 1);
  343.             } else if (otherX < c.getX() && otherY > c.getY()) {
  344.                 playerWalk(otherX + 1, otherY - 1);
  345.             } else if (otherX > c.getX() && otherY < c.getY()) {
  346.                 playerWalk(otherX + 1, otherY - 1);
  347.             }
  348.         } else {
  349.             if (otherY > c.getY() && otherX == c.getX()) {
  350.                 playerWalk(otherX, otherY - 1);
  351.             } else if (otherY < c.getY() && otherX == c.getX()) {
  352.                 playerWalk(otherX, otherY + 1);
  353.             } else if (otherX > c.getX() && otherY == c.getY()) {
  354.                 playerWalk(otherX - 1, otherY);
  355.             } else if (otherX < c.getX() && otherY == c.getY()) {
  356.                 playerWalk(otherX + 1, otherY);
  357.             } else if (otherX < c.getX() && otherY < c.getY()) {
  358.                 playerWalk(otherX + 1, otherY + 1);
  359.             } else if (otherX > c.getX() && otherY > c.getY()) {
  360.                 playerWalk(otherX - 1, otherY - 1);
  361.             } else if (otherX < c.getX() && otherY > c.getY()) {
  362.                 playerWalk(otherX + 1, otherY - 1);
  363.             } else if (otherX > c.getX() && otherY < c.getY()) {
  364.                 playerWalk(otherX - 1, otherY + 1);
  365.             }
  366.         }
  367.         c.faceUpdate(c.followId+32768);
  368.     }
  369.  
  370. FIFTH:
  371. Open up Player.java and add this in where else you want it.
  372.  
  373. Code:
  374.     public int getLocalX() {
  375.         return getX() - 8 * getMapRegionX();
  376.     }
  377.  
  378.     public int getLocalY() {
  379.         return getY() - 8 * getMapRegionY();
  380.     }
  381.  
  382.  
  383. SIXTH:
  384. Open up FollowPlayer.java which will be in your packets folder and replace it with this.. Probably the same as you have already to be honest.
  385. Code:
  386. package server.model.players.packets;
  387.  
  388. import server.Server;
  389. import server.model.players.Client;
  390. import server.model.players.PacketType;
  391.  
  392. public class FollowPlayer implements PacketType {
  393.    
  394.     @Override
  395.     public void processPacket(Client c, int packetType, int packetSize) {
  396.         int followPlayer = c.getInStream().readUnsignedWordBigEndian();
  397.         if(Server.playerHandler.players[followPlayer] == null) {
  398.             return;
  399.         }
  400.         c.playerIndex = 0;
  401.         c.npcIndex = 0;
  402.         c.mageFollow = false;
  403.         c.usingBow = false;
  404.         c.usingRangeWeapon = false;
  405.         c.followDistance = 1;
  406.         c.followId = followPlayer;
  407.     }  
  408. }
  409.  
  410. SEVENTH:
  411. Open up Server.java and add these imports
  412.  
  413. Code:
  414. import server.clip.region.ObjectDef;
  415. import server.clip.region.Region;
  416. Then add these under the main method. (public static void main)
  417.  
  418. Code:
  419. ObjectDef.loadConfig();
  420.         Region.load();
  421.  
  422.  
  423.  
  424. I am sure I left somethings out because I was in a hurry, just post and I will add anything that I may have left out. Cya around. I will release the NPC clipped follow here shortly. Not that I recommend using it..
  425.  
  426. This was released here: http://www.rune-server.org/runescape...ty-source.html - the user which released it is Wtf Ur Zerk, however he did not develop this source or this clipping system.
  427.  
  428. For those trying to sell this.. Go seek employment..
  429.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement