Thread: Elvarg NPC follow fix?

Results 1 to 6 of 6
  1. #1 Elvarg NPC follow fix? 
    Programmer

    Elysian's Avatar
    Join Date
    Dec 2018
    Posts
    157
    Thanks given
    10
    Thanks received
    79
    Rep Power
    694
    So when it comes to Elvarg and it's NPC following I find it pretty decent, the only thing I don't like, which is a huge issue when you think about it.
    Is the fact that when you move horizontally as the NPC is following you, it'll mirror your movement without progressing towards you.

    What would be a good fix to the current solution without rewriting the entire "processFollowing" function.
    Elvarg-Server-Public/MovementQueue.java at main Elvarg-Community/Elvarg-Server-Public GitHub

    I've been looking at OSRS and NPCs are allowed to move diagonally as long as they're following you,
    and then when within attacking distance they will adjust to the closest adjacent tile that is perpendicular to the target that they're following.

    Attached image
    Reply With Quote  
     

  2. #2  
    Chemist

    Advocatus's Avatar
    Join Date
    Dec 2009
    Posts
    2,622
    Thanks given
    201
    Thanks received
    813
    Rep Power
    1462
    Took a quick look at the code, I suspect that this is caused by this code here:
    Elvarg-Server-Public/MovementQueue.java at main Elvarg-Community/Elvarg-Server-Public GitHub

    Since the npc here has a follow target and you are moving it looks like this makes the npc prefer west/east movement over north/south when you are moving.
    Quote Originally Posted by blakeman8192 View Post
    Quitting is the only true failure.
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Dec 2013
    Posts
    282
    Thanks given
    4
    Thanks received
    23
    Rep Power
    57
    You're correct. The code you shared is responsible for determining the movement direction when an NPC is following a target in the MovementQueue.java file. The code prioritizes west/east movement over north/south movement when the target is moving.

    To address the issue you described, you can modify this code block to prioritize diagonal movement when the NPC is following a moving target. This change will allow the NPC to move diagonally instead of mirroring the player's horizontal movement without progressing towards them.

    Here's an updated version of the code that incorporates the changes:
    switch (direction) {
    case NORTH_WEST:
    if (RegionManager.canMove(current, Direction.NORTH_WEST, size, character.getPrivateArea())) {
    direction = Direction.NORTH_WEST;
    } else if (RegionManager.canMove(current, Direction.WEST, size, character.getPrivateArea())) {
    direction = Direction.WEST;
    } else if (RegionManager.canMove(current, Direction.NORTH, size, character.getPrivateArea())) {
    direction = Direction.NORTH;
    } else {
    direction = Direction.NONE;
    }
    break;
    case NORTH_EAST:
    if (RegionManager.canMove(current, Direction.NORTH_EAST, size, character.getPrivateArea())) {
    direction = Direction.NORTH_EAST;
    } else if (RegionManager.canMove(current, Direction.NORTH, size, character.getPrivateArea())) {
    direction = Direction.NORTH;
    } else if (RegionManager.canMove(current, Direction.EAST, size, character.getPrivateArea())) {
    direction = Direction.EAST;
    } else {
    direction = Direction.NONE;
    }
    break;
    case SOUTH_WEST:
    if (RegionManager.canMove(current, Direction.SOUTH_WEST, size, character.getPrivateArea())) {
    direction = Direction.SOUTH_WEST;
    } else if (RegionManager.canMove(current, Direction.WEST, size, character.getPrivateArea())) {
    direction = Direction.WEST;
    } else if (RegionManager.canMove(current, Direction.SOUTH, size, character.getPrivateArea())) {
    direction = Direction.SOUTH;
    } else {
    direction = Direction.NONE;
    }
    break;
    case SOUTH_EAST:
    if (RegionManager.canMove(current, Direction.SOUTH_EAST, size, character.getPrivateArea())) {
    direction = Direction.SOUTH_EAST;
    } else if (RegionManager.canMove(current, Direction.EAST, size, character.getPrivateArea())) {
    direction = Direction.EAST;
    } else if (RegionManager.canMove(current, Direction.SOUTH, size, character.getPrivateArea())) {
    direction = Direction.SOUTH;
    } else {
    direction = Direction.NONE;
    }
    break;
    default:
    break;
    }
    With this modification, the NPC will first attempt to move diagonally towards the target if the diagonal direction is valid. If diagonal movement is not possible, it will fall back to horizontal or vertical movement.

    Please note that this code snippet assumes the presence of the Direction.NORTH_WEST, Direction.NORTH_EAST, Direction.SOUTH_WEST, and Direction.SOUTH_EAST directions in the codebase. If these directions are not available, you may need to define them accordingly or adapt the code to match the existing direction constants in your project.
    You already earned my respect.
    Remember, it will only take a second to destroy the respect.
    Respect me and I will respect you.
    Disrespect me and I'll disrespect you.

    Attached image
    Reply With Quote  
     

  4. #4  
    Programmer

    Elysian's Avatar
    Join Date
    Dec 2018
    Posts
    157
    Thanks given
    10
    Thanks received
    79
    Rep Power
    694
    Quote Originally Posted by Typical Name View Post
    You're correct. The code you shared is responsible for determining the movement direction when an NPC is following a target in the MovementQueue.java file. The code prioritizes west/east movement over north/south movement when the target is moving.

    To address the issue you described, you can modify this code block to prioritize diagonal movement when the NPC is following a moving target. This change will allow the NPC to move diagonally instead of mirroring the player's horizontal movement without progressing towards them.

    Here's an updated version of the code that incorporates the changes:
    switch (direction) {
    case NORTH_WEST:
    if (RegionManager.canMove(current, Direction.NORTH_WEST, size, character.getPrivateArea())) {
    direction = Direction.NORTH_WEST;
    } else if (RegionManager.canMove(current, Direction.WEST, size, character.getPrivateArea())) {
    direction = Direction.WEST;
    } else if (RegionManager.canMove(current, Direction.NORTH, size, character.getPrivateArea())) {
    direction = Direction.NORTH;
    } else {
    direction = Direction.NONE;
    }
    break;
    case NORTH_EAST:
    if (RegionManager.canMove(current, Direction.NORTH_EAST, size, character.getPrivateArea())) {
    direction = Direction.NORTH_EAST;
    } else if (RegionManager.canMove(current, Direction.NORTH, size, character.getPrivateArea())) {
    direction = Direction.NORTH;
    } else if (RegionManager.canMove(current, Direction.EAST, size, character.getPrivateArea())) {
    direction = Direction.EAST;
    } else {
    direction = Direction.NONE;
    }
    break;
    case SOUTH_WEST:
    if (RegionManager.canMove(current, Direction.SOUTH_WEST, size, character.getPrivateArea())) {
    direction = Direction.SOUTH_WEST;
    } else if (RegionManager.canMove(current, Direction.WEST, size, character.getPrivateArea())) {
    direction = Direction.WEST;
    } else if (RegionManager.canMove(current, Direction.SOUTH, size, character.getPrivateArea())) {
    direction = Direction.SOUTH;
    } else {
    direction = Direction.NONE;
    }
    break;
    case SOUTH_EAST:
    if (RegionManager.canMove(current, Direction.SOUTH_EAST, size, character.getPrivateArea())) {
    direction = Direction.SOUTH_EAST;
    } else if (RegionManager.canMove(current, Direction.EAST, size, character.getPrivateArea())) {
    direction = Direction.EAST;
    } else if (RegionManager.canMove(current, Direction.SOUTH, size, character.getPrivateArea())) {
    direction = Direction.SOUTH;
    } else {
    direction = Direction.NONE;
    }
    break;
    default:
    break;
    }
    With this modification, the NPC will first attempt to move diagonally towards the target if the diagonal direction is valid. If diagonal movement is not possible, it will fall back to horizontal or vertical movement.

    Please note that this code snippet assumes the presence of the Direction.NORTH_WEST, Direction.NORTH_EAST, Direction.SOUTH_WEST, and Direction.SOUTH_EAST directions in the codebase. If these directions are not available, you may need to define them accordingly or adapt the code to match the existing direction constants in your project.
    I've never seen a more ChatGPT looking answer lol
    Reply With Quote  
     

  5. Thankful user:


  6. #5  
    Donator


    Join Date
    Aug 2022
    Posts
    79
    Thanks given
    12
    Thanks received
    6
    Rep Power
    111
    Quote Originally Posted by Elysian View Post
    I've never seen a more ChatGPT looking answer lol
    AGXE2AZ.png

    I had to check this out haha, and ChatGPT actually wrote it!
    Reply With Quote  
     

  7. #6  
    Programmer

    Elysian's Avatar
    Join Date
    Dec 2018
    Posts
    157
    Thanks given
    10
    Thanks received
    79
    Rep Power
    694
    Quote Originally Posted by Eustarian View Post
    AGXE2AZ.png

    I had to check this out haha, and ChatGPT actually wrote it!
    Yeah lol
    Reply With Quote  
     


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. [Elvarg] NPC follow distance
    By TomDavies in forum Help
    Replies: 2
    Last Post: 05-04-2017, 10:11 PM
  2. [508] Npc Follow Fix...
    By Alwaysstuck1 in forum Snippets
    Replies: 9
    Last Post: 09-02-2012, 12:14 AM
  3. Fix for Npc Following After death
    By Soulevoker in forum Snippets
    Replies: 5
    Last Post: 01-18-2009, 09:25 PM
  4. second click npc error fix ~MUST READ~
    By fabjan in forum Tutorials
    Replies: 7
    Last Post: 03-30-2008, 08:26 AM
  5. Easy NPC Chat Fix
    By Daniel in forum Tutorials
    Replies: 6
    Last Post: 03-20-2008, 11:37 PM
Tags for this Thread

View Tag Cloud

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •