Thread: NPC not turning

Results 1 to 5 of 5
  1. #1 NPC not turning 
    Donator

    Join Date
    Jan 2014
    Posts
    87
    Thanks given
    22
    Thanks received
    11
    Rep Power
    51
    Im having issues with a NPC not turning to its walking position; This is the only NPC thats having this issue

    https://gyazo.com/6db73d4f2057fb32984fab8d5aad3aeb

    However I don't think it's actually a problem with my npc pathfinding (Possibly a model issue?)

    Code:
    if (npc.walkingType == 1 && (!npc.underAttack) && !npc.walkingHome) {
    						if (System.currentTimeMillis() - npc.getLastRandomWalk() > npc.getRandomWalkDelay()) {
    							int direction = Misc.random3(8);
    							int movingToX = npc.getX() + NPCClipping.DIR[direction][0];
    							int movingToY = npc.getY() + NPCClipping.DIR[direction][1];
    							if (npc.npcType >= 1635 && npc.npcType <= 1643 || npc.npcType == 1654
    									|| npc.npcType == 7302) {
    								NPCDumbPathFinder.walkTowards(npc, npc.getX() - 1 + Misc.random(8),
    										npc.getY() - 1 + Misc.random(8));
    							} else {
    								if (Math.abs(npc.makeX - movingToX) <= 1 && Math.abs(npc.makeY - movingToY) <= 1
    										&& NPCDumbPathFinder.canMoveTo(npc, direction)) {
    									NPCDumbPathFinder.walkTowards(npc, movingToX, movingToY);
    								}
    							}
    							npc.setRandomWalkDelay(TimeUnit.SECONDS.toMillis(1 + Misc.random(2)));
    							npc.setLastRandomWalk(System.currentTimeMillis());
    						}
    					}
    				}
    Code:
    public static void walkTowards(NPC npc, int waypointx, int waypointy) {
    		int x = npc.getX();
    		int y = npc.getY();
    		
    		if (waypointx == x && waypointy == y) {
    			return;
    		}
    		
    		int direction = -1;
    		final int xDifference = waypointx - x;
    		final int yDifference = waypointy - y;
    
    		int toX = 0;
    		int toY = 0;
    
    		if (xDifference > 0) {
    			toX = 1;
    		} else if (xDifference < 0) {
    			toX = -1;
    		}
    
    		if (yDifference > 0) {
    			toY = 1;
    		} else if (yDifference < 0) {
    			toY = -1;
    		}
    
    		int toDir = NPCClipping.getDirection(x, y, x + toX, y + toY);
    			if (canMoveTo(npc, toDir)) {
    				direction = toDir;
    			} else {
    				if (toDir == 0) {
    					if (canMoveTo(npc, 3)) {
    						direction = 3;
    					} else if (canMoveTo(npc, 1)) {
    						direction = 1;
    					}
    				} else if (toDir == 2) {
    					if (canMoveTo(npc, 1)) {
    						direction = 1;
    					} else if (canMoveTo(npc, 4)) {
    						direction = 4;
    					}
    				} else if (toDir == 5) {
    					if (canMoveTo(npc, 3)) {
    						direction = 3;
    					} else if (canMoveTo(npc, 6)) {
    						direction = 6;
    					}
    				} else if (toDir == 7) {
    					if (canMoveTo(npc, 4)) {
    						direction = 4;
    					} else if (canMoveTo(npc, 6)) {
    						direction = 6;
    					}
    				}
    			}
    
    		if (direction == -1) {
    			return;
    		}
    		
    		if (direction == -1) {
    			return;
    		}
    		/*direction >>= 1;	
    			
    		if (direction < 0) {
    			return;
    		}*/
    		//if (npc.moveX != 0 || npc.moveY != 0)
    			//throw new IllegalStateException("walking multiple times.");
    		/*try {
    			throw new Exception();
    		} catch (Exception e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}*/
    		npc.moveX = NPCClipping.DIR[direction][0];
    		npc.moveY = NPCClipping.DIR[direction][1];
    		//npc.moveY = World.getWorld().getNpcHandler().GetMove(npc.getY(), npcLocation[1] + movey);
    		npc.getNextNPCMovement();
    		npc.updateRequired = true;
    	}
    Reply With Quote  
     

  2. #2  
    Administrator

    Kevy's Avatar
    Join Date
    Jul 2006
    Posts
    1,428
    Thanks given
    204
    Thanks received
    1,905
    Rep Power
    5000
    Since this is the only NPC you are having a problem, maybe you are accidentally sending the update mask to face some other entity or coordinates.
    You should try to debug it client side.
    Thanks, Kevin.
    Reply With Quote  
     

  3. #3  
    Donator

    Join Date
    Jan 2014
    Posts
    87
    Thanks given
    22
    Thanks received
    11
    Rep Power
    51
    Quote Originally Posted by Kevy View Post
    Since this is the only NPC you are having a problem, maybe you are accidentally sending the update mask to face some other entity or coordinates.
    You should try to debug it client side.
    I forgot to mention that the jungle demon has different NPC ID's, one being a nightmare zone ID & two others.
    They all have the same issue; So my gut is saying its a model issue but i'm to unexperienced to know if the model can actually cause issues like this.

    Ill play around with different things, thanks for the answer.

    EDIT: it's not the model thats causing a problem.
    Reply With Quote  
     

  4. #4  
    Registered Member

    Join Date
    Nov 2014
    Posts
    337
    Thanks given
    47
    Thanks received
    12
    Rep Power
    187
    Quote Originally Posted by DefusedRSPS View Post
    I forgot to mention that the jungle demon has different NPC ID's, one being a nightmare zone ID & two others.
    They all have the same issue; So my gut is saying its a model issue but i'm to unexperienced to know if the model can actually cause issues like this.

    Ill play around with different things, thanks for the answer.

    EDIT: it's not the model thats causing a problem.
    Sounds like a NPC facing update issue i'd look around NPCHandler if you have one, Also look for that NPC's ID and compare it to others to see if it's out of place.
    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Nov 2019
    Posts
    9
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    Quote Originally Posted by DefusedRSPS View Post
    Im having issues with a NPC not turning to its walking position; This is the only NPC thats having this issue

    https://gyazo.com/6db73d4f2057fb32984fab8d5aad3aeb

    However I don't think it's actually a problem with my npc pathfinding (Possibly a model issue?)

    Code:
    if (npc.walkingType == 1 && (!npc.underAttack) && !npc.walkingHome) {
    						if (System.currentTimeMillis() - npc.getLastRandomWalk() > npc.getRandomWalkDelay()) {
    							int direction = Misc.random3(8);
    							int movingToX = npc.getX() + NPCClipping.DIR[direction][0];
    							int movingToY = npc.getY() + NPCClipping.DIR[direction][1];
    							if (npc.npcType >= 1635 && npc.npcType <= 1643 || npc.npcType == 1654
    									|| npc.npcType == 7302) {
    								NPCDumbPathFinder.walkTowards(npc, npc.getX() - 1 + Misc.random(8),
    										npc.getY() - 1 + Misc.random(8));
    							} else {
    								if (Math.abs(npc.makeX - movingToX) <= 1 && Math.abs(npc.makeY - movingToY) <= 1
    										&& NPCDumbPathFinder.canMoveTo(npc, direction)) {
    									NPCDumbPathFinder.walkTowards(npc, movingToX, movingToY);
    								}
    							}
    							npc.setRandomWalkDelay(TimeUnit.SECONDS.toMillis(1 + Misc.random(2)));
    							npc.setLastRandomWalk(System.currentTimeMillis());
    						}
    					}
    				}
    Code:
    public static void walkTowards(NPC npc, int waypointx, int waypointy) {
    		int x = npc.getX();
    		int y = npc.getY();
    		
    		if (waypointx == x && waypointy == y) {
    			return;
    		}
    		
    		int direction = -1;
    		final int xDifference = waypointx - x;
    		final int yDifference = waypointy - y;
    
    		int toX = 0;
    		int toY = 0;
    
    		if (xDifference > 0) {
    			toX = 1;
    		} else if (xDifference < 0) {
    			toX = -1;
    		}
    
    		if (yDifference > 0) {
    			toY = 1;
    		} else if (yDifference < 0) {
    			toY = -1;
    		}
    
    		int toDir = NPCClipping.getDirection(x, y, x + toX, y + toY);
    			if (canMoveTo(npc, toDir)) {
    				direction = toDir;
    			} else {
    				if (toDir == 0) {
    					if (canMoveTo(npc, 3)) {
    						direction = 3;
    					} else if (canMoveTo(npc, 1)) {
    						direction = 1;
    					}
    				} else if (toDir == 2) {
    					if (canMoveTo(npc, 1)) {
    						direction = 1;
    					} else if (canMoveTo(npc, 4)) {
    						direction = 4;
    					}
    				} else if (toDir == 5) {
    					if (canMoveTo(npc, 3)) {
    						direction = 3;
    					} else if (canMoveTo(npc, 6)) {
    						direction = 6;
    					}
    				} else if (toDir == 7) {
    					if (canMoveTo(npc, 4)) {
    						direction = 4;
    					} else if (canMoveTo(npc, 6)) {
    						direction = 6;
    					}
    				}
    			}
    
    		if (direction == -1) {
    			return;
    		}
    		
    		if (direction == -1) {
    			return;
    		}
    		/*direction >>= 1;	
    			
    		if (direction < 0) {
    			return;
    		}*/
    		//if (npc.moveX != 0 || npc.moveY != 0)
    			//throw new IllegalStateException("walking multiple times.");
    		/*try {
    			throw new Exception();
    		} catch (Exception e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}*/
    		npc.moveX = NPCClipping.DIR[direction][0];
    		npc.moveY = NPCClipping.DIR[direction][1];
    		//npc.moveY = World.getWorld().getNpcHandler().GetMove(npc.getY(), npcLocation[1] + movey);
    		npc.getNextNPCMovement();
    		npc.updateRequired = true;
    	}
    Try Checking the NPC Defs and check if you miss any comma's in the list of npc's , becuase you might have added something and forgot to close it at the end, If thats not the problem i would suggest debugging like Kevy said
    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. NPC Not Walking?
    By Trytohaxme in forum Help
    Replies: 4
    Last Post: 10-06-2009, 07:31 AM
  2. Making Npc's turn in autospawn
    By Shamon King in forum Help
    Replies: 0
    Last Post: 07-09-2009, 02:44 AM
  3. Replies: 1
    Last Post: 03-24-2009, 10:47 AM
  4. Making NPCs not walk throught Players & NPCs
    By Nemmyz in forum Configuration
    Replies: 10
    Last Post: 03-11-2009, 12:20 PM
  5. NPCs not working.
    By FateJiki in forum Configuration
    Replies: 2
    Last Post: 02-17-2008, 02: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
  •