Thread: Please help! Adding walkType for NPCs to the changeRegion packet?

Results 1 to 6 of 6
  1. #1 Please help! Adding walkType for NPCs to the changeRegion packet? 
    Registered Member
    Join Date
    Jun 2014
    Posts
    48
    Thanks given
    1
    Thanks received
    1
    Rep Power
    13
    Hi there,

    I've been trying to work out how to add the walkType if statements to the ChangeRegions.java (that might not be where I should be looking), as I didn't want my NPC direction to be detirmined in process() of NPCHandler.java.

    I tried this:

    [spoiler]
    Code:
    		if (packetType == 210) {
    			
    		for (int i = 0; i < maxNPCs; i++) {
    			if (npcs[i] != null) {
    		if (npcs[i].walkingType >= 2) {
    	        switch(npcs[i].walkingType) {
    
    	        case 5: //west
    	            npcs[i].turnNpc(npcs[i].absX -1, npcs[i].absY);
    	            break;
    
    	        case 4: //east
    	            npcs[i].turnNpc(npcs[i].absX +1, npcs[i].absY);
    	            break;
    
    	        case 3: //south
    	            npcs[i].turnNpc(npcs[i].absX, npcs[i].absY -1);
    	            break;
    	        case 2: //north
    	            npcs[i].turnNpc(npcs[i].absX, npcs[i].absY +1);
    	            break;
    
    	        default: // applies to all npc who are only standing, remove if not needed
    	            if (npcs[i].walkingType >= 0) {
    	                npcs[i].turnNpc(npcs[i].absX, npcs[i].absY); //makes it when npcs move they dont turn back to one direction
    	            }
    	            break;
    	        }
    	    		}
    			}	
    							
    		
    		if(npcs[i].walkingType == 1) {
    			if(Misc.random(3)== 1 && !npcs[i].walkingHome) {
    				int MoveX = 0;
    				int MoveY = 0;			
    				int Rnd = Misc.random(9);
    				if (Rnd == 1) {
    					MoveX = 1;
    					MoveY = 1;
    				} else if (Rnd == 2) {
    					MoveX = -1;
    				} else if (Rnd == 3) {
    					MoveY = -1;
    				} else if (Rnd == 4) {
    					MoveX = 1;
    				} else if (Rnd == 5) {
    					MoveY = 1;
    				} else if (Rnd == 6) {
    					MoveX = -1;
    					MoveY = -1;
    				} else if (Rnd == 7) {
    					MoveX = -1;
    					MoveY = 1;
    				} else if (Rnd == 8) {
    					MoveX = 1;
    					MoveY = -1;
    				}
    				
    				if (MoveX == 1) {
    					if (npcs[i].absX + MoveX < npcs[i].makeX + 1) {
    						npcs[i].moveX = MoveX;
    					} else {
    						npcs[i].moveX = 0;
    					}
    								}
    				
    				if (MoveX == -1) {
    					if (npcs[i].absX - MoveX > npcs[i].makeX - 1)  {
    						npcs[i].moveX = MoveX;
    					} else {
    						npcs[i].moveX = 0;
    					}
    								}
    				
    				if(MoveY == 1) {
    					if(npcs[i].absY + MoveY < npcs[i].makeY + 1) {
    						npcs[i].moveY = MoveY;
    					} else {
    						npcs[i].moveY = 0;
    					}
    								}
    				
    				if(MoveY == -1) {
    					if(npcs[i].absY - MoveY > npcs[i].makeY - 1)  {
    						npcs[i].moveY = MoveY;
    					} else {
    						npcs[i].moveY = 0;
    					}
    									}
    								}
    							}
    						}
    					}
    [/spoiler]

    which went horribly wrong, and didn't help at all! How would I link these if statements so that when packet 210 (the one to change regions) is initiated, it calls them and checks the npc direction?

    Thanks!

    Baylo
    Reply With Quote  
     

  2. #2  
    Banned
    Join Date
    Jan 2014
    Posts
    596
    Thanks given
    91
    Thanks received
    60
    Discord
    View profile
    Rep Power
    0
    Quote Originally Posted by Baylo11 View Post
    Hi there,

    I've been trying to work out how to add the walkType if statements to the ChangeRegions.java (that might not be where I should be looking), as I didn't want my NPC direction to be detirmined in process() of NPCHandler.java.

    I tried this:

    [spoiler]
    Code:
    		if (packetType == 210) {
    			
    		for (int i = 0; i < maxNPCs; i++) {
    			if (npcs[i] != null) {
    		if (npcs[i].walkingType >= 2) {
    	        switch(npcs[i].walkingType) {
    
    	        case 5: //west
    	            npcs[i].turnNpc(npcs[i].absX -1, npcs[i].absY);
    	            break;
    
    	        case 4: //east
    	            npcs[i].turnNpc(npcs[i].absX +1, npcs[i].absY);
    	            break;
    
    	        case 3: //south
    	            npcs[i].turnNpc(npcs[i].absX, npcs[i].absY -1);
    	            break;
    	        case 2: //north
    	            npcs[i].turnNpc(npcs[i].absX, npcs[i].absY +1);
    	            break;
    
    	        default: // applies to all npc who are only standing, remove if not needed
    	            if (npcs[i].walkingType >= 0) {
    	                npcs[i].turnNpc(npcs[i].absX, npcs[i].absY); //makes it when npcs move they dont turn back to one direction
    	            }
    	            break;
    	        }
    	    		}
    			}	
    							
    		
    		if(npcs[i].walkingType == 1) {
    			if(Misc.random(3)== 1 && !npcs[i].walkingHome) {
    				int MoveX = 0;
    				int MoveY = 0;			
    				int Rnd = Misc.random(9);
    				if (Rnd == 1) {
    					MoveX = 1;
    					MoveY = 1;
    				} else if (Rnd == 2) {
    					MoveX = -1;
    				} else if (Rnd == 3) {
    					MoveY = -1;
    				} else if (Rnd == 4) {
    					MoveX = 1;
    				} else if (Rnd == 5) {
    					MoveY = 1;
    				} else if (Rnd == 6) {
    					MoveX = -1;
    					MoveY = -1;
    				} else if (Rnd == 7) {
    					MoveX = -1;
    					MoveY = 1;
    				} else if (Rnd == 8) {
    					MoveX = 1;
    					MoveY = -1;
    				}
    				
    				if (MoveX == 1) {
    					if (npcs[i].absX + MoveX < npcs[i].makeX + 1) {
    						npcs[i].moveX = MoveX;
    					} else {
    						npcs[i].moveX = 0;
    					}
    								}
    				
    				if (MoveX == -1) {
    					if (npcs[i].absX - MoveX > npcs[i].makeX - 1)  {
    						npcs[i].moveX = MoveX;
    					} else {
    						npcs[i].moveX = 0;
    					}
    								}
    				
    				if(MoveY == 1) {
    					if(npcs[i].absY + MoveY < npcs[i].makeY + 1) {
    						npcs[i].moveY = MoveY;
    					} else {
    						npcs[i].moveY = 0;
    					}
    								}
    				
    				if(MoveY == -1) {
    					if(npcs[i].absY - MoveY > npcs[i].makeY - 1)  {
    						npcs[i].moveY = MoveY;
    					} else {
    						npcs[i].moveY = 0;
    					}
    									}
    								}
    							}
    						}
    					}
    [/spoiler]

    which went horribly wrong, and didn't help at all! How would I link these if statements so that when packet 210 (the one to change regions) is initiated, it calls them and checks the npc direction?

    Thanks!

    Baylo

    in npc.java look for these methods

    Code:
    public static int FocusPointX = -1;
    	public int FocusPointY = -1;
    	public int face = 0;
    
    	private void appendSetFocusDestination(Stream str) {
    		if(FocusPointX != -1){
    			str.writeWordBigEndian(FocusPointX);
    			str.writeWordBigEndian(FocusPointY);
    		} else {
    			int x = absX;
    			int y = absY;
    			if(walkingType != 1){
    				//0= north 3= west 2=east 5=east 4=south
    				switch(walkingType){
    				case 0: //north
    					y++; break;
    				case 2: //east
    					x++; break;
    				case 3: //west
    					x--; break;
    				case 4: //south
    					y--; break;
    				}
    			}
    			str.writeWordBigEndian(x * 2 + 1);
    			str.writeWordBigEndian(y * 2 + 1);			
    		}
    		
    	}
    
    	public void turnNpc(int i, int j) {
    		FocusPointX = 2 * i + 1;
    		FocusPointY = 2 * j + 1;
    		updateRequired = true;
    
    	}
    and stuff if you have them replace them if you dont have them add them
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Jun 2014
    Posts
    48
    Thanks given
    1
    Thanks received
    1
    Rep Power
    13
    Thanks for the reply -

    I've added that, and it didn't actually do anything for me :O

    What I'm trying to do is actually add in the code I have, but in somewhere other than process() so that it's not called every 600ms or w/e - I've read that it's best if I use the region loading packet to do this, but I'm not sure how

    Thank you anyway though
    Reply With Quote  
     

  4. #4  
    Registered Member
    Join Date
    Jun 2014
    Posts
    48
    Thanks given
    1
    Thanks received
    1
    Rep Power
    13
    Bump! If anyone knows how to call this information for the changing regions packet, please let me know!
    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Jun 2014
    Posts
    48
    Thanks given
    1
    Thanks received
    1
    Rep Power
    13
    Bump!
    Reply With Quote  
     

  6. #6  
    Registered Member
    Join Date
    Jun 2014
    Posts
    48
    Thanks given
    1
    Thanks received
    1
    Rep Power
    13
    Bump!
    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. Replies: 2
    Last Post: 09-08-2013, 02:23 AM
  2. Replies: 0
    Last Post: 04-16-2013, 01:35 AM
  3. Replies: 8
    Last Post: 08-29-2012, 04:21 AM
  4. Error please help me! REPP++ for help!!
    By Dimitri in forum Help
    Replies: 3
    Last Post: 02-17-2010, 05:58 AM
  5. Replies: 2
    Last Post: 06-06-2009, 06:11 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •