Thread: NPC facing

Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1 NPC facing 
    Super Donator

    Join Date
    Oct 2008
    Posts
    328
    Thanks given
    34
    Thanks received
    20
    Rep Power
    66
    Client side:

    Find
    Code:
    void updateNPCMovement
    Above
    Code:
    npc.desc = NpcDefinition.forID
    /
    Code:
    npc.definition = NPCDefinition.forId
    add

    Code:
    int faceDirection = stream.readBits(3);
    under

    Code:
    npc.standAnimation =
    add

    Code:
    npc.turnDirection = npc.anInt1552 = Constants.FACE_DIRECTIONS[faceDirection];
    Constants.FACE_DIRECTIONS
    Code:
    public static final int[] FACE_DIRECTIONS = new int[]{768, 1024, 1280, 512, 1536, 256, 0, 1792};
    Server side:

    In your NPC updating class, find something along the lines of:
    Code:
    packet.putBits(5, yPos);
    packet.putBits(5, xPos);
    packet.putBits(1, 0);
    After
    Code:
    packet.putBits(1, 0);
    Put:
    Code:
    packet.putBits(3, npc.getDirection().ordinal());
    Where npc.getDirection.ordinal() is the direction/rotation of the npc.

    More or less how newer protocols handle it

    Naming may be different, basically within the method of updating the NPC's movement.
    menth
    Reply With Quote  
     

  2. #2  
    Banned
    Join Date
    Dec 2015
    Posts
    55
    Thanks given
    0
    Thanks received
    5
    Rep Power
    0
    Reply With Quote  
     

  3. #3  
    Super Donator

    Join Date
    Oct 2008
    Posts
    328
    Thanks given
    34
    Thanks received
    20
    Rep Power
    66
    read what I posted
    menth
    Reply With Quote  
     

  4. #4  
    Banned
    Join Date
    Dec 2015
    Posts
    55
    Thanks given
    0
    Thanks received
    5
    Rep Power
    0
    Quote Originally Posted by M,i,K,e_ View Post
    read what I posted
    I did?
    Reply With Quote  
     

  5. #5  
    Super Donator

    Join Date
    Oct 2008
    Posts
    328
    Thanks given
    34
    Thanks received
    20
    Rep Power
    66
    Quote Originally Posted by Damnit Mom View Post
    I did?
    then why do all of that instead of just using the way runescape does it?

    npc doesn't change direction after moving in case that's what you mean, static remains the same direction, otherwise client handles the direction upon moving
    menth
    Reply With Quote  
     

  6. #6  
    Banned
    Join Date
    Dec 2015
    Posts
    55
    Thanks given
    0
    Thanks received
    5
    Rep Power
    0
    Quote Originally Posted by M,i,K,e_ View Post
    then why do all of that instead of just using the way runescape does it?

    npc doesn't change direction after moving in case that's what you mean, static remains the same direction, otherwise client handles the direction upon moving
    Yea true, you got a point there.
    Reply With Quote  
     

  7. Thankful user:


  8. #7  
    Super Donator

    Join Date
    Oct 2008
    Posts
    328
    Thanks given
    34
    Thanks received
    20
    Rep Power
    66
    Quote Originally Posted by Damnit Mom View Post
    Yea true, you got a point there.
    gives the server a lot less to do in the process, only reason I posted it, otherwise I wouldn't of lol
    menth
    Reply With Quote  
     

  9. #8  
    Donator

    Arithium's Avatar
    Join Date
    May 2010
    Age
    31
    Posts
    4,721
    Thanks given
    199
    Thanks received
    1,256
    Rep Power
    1114
    You need post the direction enum so we know the order of the directions.
    Reply With Quote  
     

  10. #9  
    Super Donator

    Join Date
    Oct 2008
    Posts
    328
    Thanks given
    34
    Thanks received
    20
    Rep Power
    66
    Quote Originally Posted by Arithium View Post
    You need post the direction enum so we know the order of the directions.
    Edit, nvm, and the directions are the same in any, used from Arios
    Code:
    /**
     * Represents a direction.
     *
     * @author Emperor
     */
    public enum Direction {
    
        /**
         * The north-west direction.
         */
        NORTH_WEST(-1, 1, 7, 0x12c0108, 0x12c0120, 0x12c0138),
    
        /**
         * The north direction.
         */
        NORTH(0, 1, 0, 0x12c0120),
    
        /**
         * The north-east direction.
         */
        NORTH_EAST(1, 1, 4, 0x12c0180, 0x12c0120, 0x12c01e0),
    
        /**
         * The west direction.
         */
        WEST(-1, 0, 3, 0x12c0108),
    
        /**
         * The east direction.
         */
        EAST(1, 0, 1, 0x12c0180),
    
        /**
         * The south-west direction.
         */
        SOUTH_WEST(-1, -1, 6, 0x12c0108, 0x12c0102, 0x12c010e),
    
        /**
         * The south direction.
         */
        SOUTH(0, -1, 2, 0x12c0102),
    
        /**
         * The south-east direction.
         */
        SOUTH_EAST(1, -1, 5, 0x12c0180, 0x12c0102, 0x12c0183);
    
        /**
         * The amounts of steps on the x-axis.
         */
        private final int stepX;
    
        /**
         * The amounts of steps on the y-axis.
         */
        private final int stepY;
    
        /**
         * The integer value.
         */
        private final int value;
    
        /**
         * The traversal flags.
         */
        private int[] traversal;
    
        /**
         * Constructs a new {@code Direction} {@code Object}.
         *
         * @param stepX     The x-offset to move a step.
         * @param stepY     The y-offset to move a step.
         * @param value     The direction value.
         * @param traversal The traversal flags.
         */
        private Direction(int stepX, int stepY, int value, int... traversal) {
            this.stepX = stepX;
            this.stepY = stepY;
            this.value = value;
            this.setTraversal(traversal);
        }
    
        /**
         * Gets the direction.
         *
         * @param rotation The int value.
         * @return The direction.
         */
        public static Direction get(int rotation) {
            for (Direction dir : Direction.values()) {
                if (dir.value == rotation) {
                    return dir;
                }
            }
            throw new IllegalArgumentException("Invalid direction value - " + rotation);
        }
    
        /**
         * Gets the walk point for a direction.
         * <br>The point will be the offset to the location the node is facing.
         *
         * @param direction The direction.
         * @return The point.
         */
        public static Point getWalkPoint(Direction direction) {
            return new Point(direction.stepX, direction.stepY);
        }
    
        /**
         * Gets the direction.
         *
         * @param location The start location.
         * @param l        The end location.
         * @return The direction.
         */
        public static Direction getDirection(Location location, Location l) {
            return getDirection(l.getX() - location.getX(), l.getY() - location.getY());
        }
    
        /**
         * Gets the direction for movement.
         *
         * @param diffX The difference between 2 x-coordinates.
         * @param diffY The difference between 2 y-coordinates.
         * @return The direction.
         */
        public static Direction getDirection(int diffX, int diffY) {
            if (diffX < 0) {
                if (diffY < 0) {
                    return SOUTH_WEST;
                } else if (diffY > 0) {
                    return NORTH_WEST;
                }
                return WEST;
            } else if (diffX > 0) {
                if (diffY < 0) {
                    return SOUTH_EAST;
                } else if (diffY > 0) {
                    return NORTH_EAST;
                }
                return EAST;
            }
            if (diffY < 0) {
                return SOUTH;
            }
            return NORTH;
        }
    
        /**
         * Gets the direction for the given walking flag.
         *
         * @param walkingFlag The walking flag.
         * @param rotation    The rotation.
         * @return The direction, or null if the walk flag was 0.
         */
        public static Direction forWalkFlag(int walkingFlag, int rotation) {
            if (rotation != 0) {
                walkingFlag = (walkingFlag << rotation & 0xf) + (walkingFlag >> 4 - rotation);
            }
            if (walkingFlag > 0) {
                if ((walkingFlag & 0x8) == 0) {
                    return Direction.WEST;
                }
                if ((walkingFlag & 0x2) == 0) {
                    return Direction.EAST;
                }
                if ((walkingFlag & 0x4) == 0) {
                    return Direction.SOUTH;
                }
                if ((walkingFlag & 0x1) == 0) {
                    return Direction.NORTH;
                }
            }
            return null;
        }
    
        /**
         * Gets the opposite dir.
         *
         * @return the direction.
         */
        public Direction getOpposite() {
            return Direction.get(toInteger() + 2 & 3);
        }
    
        /**
         * Rotates the direction to the left.
         *
         * @return The direction.
         */
        public Direction rotateLeft() {
            if ((ordinal() - 1) < 0) {
                return values()[(values().length - 1)];
            }
            for (Direction dir : values()) {
                if (ordinal() == dir.ordinal()) {
                    return values()[ordinal() - 1];
                }
            }
            return this;
        }
    
        /**
         * Rotates the direction to the right.
         *
         * @return The direction.
         */
        public Direction rotateRight() {
            if ((ordinal() + 1) == (values().length + 1)) {
                return values()[0];
            }
            for (Direction dir : values()) {
                if (ordinal() == dir.ordinal()) {
                    return values()[ordinal() + 1];
                }
            }
            return this;
        }
    
        /**
         * Gets the most logical direction.
         *
         * @param location The start location.
         * @param l        The end location.
         * @return The most logical direction.
         */
        public static Direction getLogicalDirection(Location location, Location l) {
            int offsetX = Math.abs(l.getX() - location.getX());
            int offsetY = Math.abs(l.getY() - location.getY());
            if (offsetX > offsetY) {
                if (l.getX() > location.getX()) {
                    return Direction.EAST;
                } else {
                    return Direction.WEST;
                }
            } else if (l.getY() < location.getY()) {
                return Direction.SOUTH;
            }
            return Direction.NORTH;
        }
    
        /**
         * Method used to go to clue the anme.
         *
         * @param direction the direction.
         * @return the name.
         */
        public String toName(Direction direction) {
            return direction.name().toLowerCase();
        }
    
        /**
         * Method used to get the direction to an integer.
         *
         * @return the integer.
         */
        public int toInteger() {
            return value;
        }
    
        /**
         * Gets the stepX.
         *
         * @return The stepX.
         */
        public int getStepX() {
            return stepX;
        }
    
        /**
         * Gets the stepY.
         *
         * @return The stepY.
         */
        public int getStepY() {
            return stepY;
        }
    
        /**
         * Checks if traversal is permitted for this direction.
         *
         * @param l The location.
         * @return <code>True</code> if so.
         */
        public boolean canMove(Location l) {
            int flag = RegionManager.getClippingFlag(l.getZ(), l.getX(), l.getY());
            for (int f : traversal) {
                if ((flag & f) != 0) {
                    return false;
                }
            }
            return true;
        }
    
        /**
         * Gets the traversal.
         *
         * @return The traversal.
         */
        public int[] getTraversal() {
            return traversal;
        }
    
        /**
         * Sets the traversal.
         *
         * @param traversal The traversal to set.
         */
        public void setTraversal(int[] traversal) {
            this.traversal = traversal;
        }
    }
    menth
    Reply With Quote  
     

  11. #10  
    Owner of Dawntained

    Mgt Madness's Avatar
    Join Date
    Oct 2011
    Age
    28
    Posts
    3,380
    Thanks given
    1,429
    Thanks received
    958
    Rep Power
    2168
    thanks
    Attached image
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Change standing npc face direction
    By hayzie in forum Tutorials
    Replies: 52
    Last Post: 08-01-2010, 11:10 AM
  2. [508] NPC Facing
    By iZAjz in forum Requests
    Replies: 1
    Last Post: 03-12-2009, 12:29 PM
  3. npc face :/
    By Darkie in forum Help
    Replies: 0
    Last Post: 02-09-2009, 07:11 PM
  4. Replies: 13
    Last Post: 01-16-2009, 06:11 PM
  5. Replies: 0
    Last Post: 10-21-2008, 09:40 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •