Thread: [PI] NPC clipping / Tile clipping [PI]

Results 1 to 5 of 5
  1. #1 [PI] NPC clipping / Tile clipping [PI] 
    Registered Member
    Join Date
    Jul 2011
    Posts
    90
    Thanks given
    3
    Thanks received
    7
    Rep Power
    11
    I haven't even looked at an RSPS since about 2013, but I see things have really moved on

    Unlike most of you I am still going to be using the original PI. After starting up a server again one of the things that always frustrated me was NPC clipping.

    Now I am not a great or experienced programmer, so I'm going to be producing tutorials that are simple and solve the problem for newbies NPC clipping will always be better client sided as there is no strain on the server. But it's too advanced for me to make from scratch at the moment so I've made a bit of code that fixes the problem temporarily.

    Any suggestions for improvements would be appreciated - I will be updating this thread as I develop the system.



    Open up your NPCHandler.java
    Search for "if (npcs[i].walkingType == 1) {"
    Replace the whole section with the following:

    Code:
    				// Auto Talker's tile clipping 0.03	
    					if (npcs[i].walkingType == 1) {
    					
    						if (Misc.random(3) == 1 && !npcs[i].walkingHome) {
    							int MoveX = 0;
    							int MoveY = 0;
    							int Rnd = Misc.random(3);
    						
    							if (Rnd == 0) {
    								MoveX = 1;
    							} if (Rnd == 1) {
    								MoveX = -1;
    							} if (Rnd == 2) {
    								MoveY = 1;
    							} if (Rnd == 3) {
    								MoveY = -1;
    							} 
    							
    											
    					
    							if(
    							// Add or change your tile blocks here - A cleaner way will be added in future
    							// ---------------------------------------------------------------------------
    							// Edgeville Bank
    							MoveX + npcs[i].absX == 3099 && MoveY + npcs[i].absY == 3497 || // East wall
    							MoveX + npcs[i].absX == 3099 && MoveY + npcs[i].absY == 3498 || // East wall
    							MoveX + npcs[i].absX == 3099 && MoveY + npcs[i].absY == 3499 || // East wall
    							MoveX + npcs[i].absX == 3096 && MoveY + npcs[i].absY == 3500 || // North wall
    							MoveX + npcs[i].absX == 3097 && MoveY + npcs[i].absY == 3500 || // North wall
    							MoveX + npcs[i].absX == 3098 && MoveY + npcs[i].absY == 3500 || // North wall
    							MoveX + npcs[i].absX == 3096 && npcs[i].absY + MoveY == 3498 || // Desk
    							
    							// General Store
    							MoveX + npcs[i].absX == 3078 && npcs[i].absY + MoveY == 3510 || // Desk
    							MoveX + npcs[i].absX == 3079 && npcs[i].absY + MoveY == 3510 || // Desk
    							MoveX + npcs[i].absX == 3080 && npcs[i].absY + MoveY == 3510 || // Box
    							MoveX + npcs[i].absX == 3081 && npcs[i].absY + MoveY == 3510 || // Desk
    							MoveX + npcs[i].absX == 3082 && npcs[i].absY + MoveY == 3510 || // Desk
    							MoveX + npcs[i].absX == 3078 && npcs[i].absY + MoveY == 3513 || // Bookcase
    							MoveX + npcs[i].absX == 3079 && npcs[i].absY + MoveY == 3513 || // Bookcase
    							MoveX + npcs[i].absX == 3080 && npcs[i].absY + MoveY == 3513    // Bookcase
    							)
    								{
    									npcs[i].moveX = 0;
    									npcs[i].moveY = 0;
    									return;
    								}
    						
    							
    							if (MoveX == 1) {
    								if (npcs[i].absX + MoveX < npcs[i].makeX + 3) {
    									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 + 3) {
    									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;
    								}
    							} 
    
    							int x = (npcs[i].absX + npcs[i].moveX);
    							int y = (npcs[i].absY + npcs[i].moveY);
    							
    							if (VirtualWorld.I(npcs[i].heightLevel,
    									npcs[i].absX, npcs[i].absY, x, y, 0))
    							{
    								npcs[i].getNextNPCMovement(i);
    								npcs[i].updateRequired = true;
    								int XX = npcs[i].absX + npcs[i].moveX;
    								int YY = npcs[i].absY + npcs[i].moveY;
    							}
    							else {
    								npcs[i].moveX = 0;
    								npcs[i].moveY = 0;
    							}
    							npcs[i].updateRequired = true;
    						}
    					}










    Now the system should be working let's make it a bit easier to manage.
    This section isn't required but might just make it easier to use



    Spoiler for Click here to see my management system:


    Create a new text file called "tile_block_list.txt" inside Data/cfg/



    Open up your PlayerAssistant.java
    Make sure you add the following imports at the top of the file:

    Code:
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;

    Now add the following public void:

    Code:
    // Auto Talker's tile clipping
    	public void saveCoords() {
            String filePath = "./Data/cfg/tile_block_list.txt";
            BufferedWriter bw = null;
    
            try {
                bw = new BufferedWriter(new FileWriter(filePath, true));
                bw.write("MoveX + npcs[i].absX == " + c.absX + " && MoveY + npcs[i].absY == " + c.absY + " ||");
                bw.newLine();
                bw.flush();
            } catch (IOException ioe) {
                ioe.printStackTrace();
            } finally {
                if (bw != null) {
                    try {
                        bw.close();
                    } catch (IOException ioe2) {
                    }
                }
            }
        }


    Open up your ClickItem.java
    Now add the following function above "if (itemId >= 5509 && itemId <= 5514) {":
    Code:
    // Auto Talker's tile clipping
    	if (itemId == 292) {
    		if(c.playerRights == 3) {	
    			c.getDH().sendDialogues(512, -1);
    		}
    		return;
    		}


    Open up your DialogueHandler.java
    Now search for: "Case 19:" and add the following above it:
    Code:
                            case 512:
    			sendOption5("North", "East", "South", "West", "Record");
    			c.dialogueAction = 512;
    			break;

    Open up your ClickingButtons.java
    Now search for: "9190" and add the following to the end of this case.
    Code:
                               else if (c.dialogueAction == 512) {
    				c.getPA().movePlayer(c.absX, c.absY + 1, 0);
    			}
    Now search for: "9191" and add the following to the end of this case.
    Code:
                               else if (c.dialogueAction == 512) {
    				c.getPA().movePlayer(c.absX + 1, c.absY, 0);
    			}
    Now search for: "9192" and add the following to the end of this case.
    Code:
                               else if (c.dialogueAction == 512) {
    				c.getPA().movePlayer(c.absX, c.absY - 1, 0);
    			}
    Now search for: "9193" and add the following to the end of this case.
    Code:
                               else if (c.dialogueAction == 512) {
    				c.getPA().movePlayer(c.absX - 1, c.absY, 0);
    			}
    Now search for: "9194" and add the following to the end of this case.
    Code:
                             else if (c.dialogueAction == 512) {
    				c.getPA().saveCoords();
    				c.sendMessage("Record updated " + c.absX + ", " + c.absY + ".");
    				c.forcedText = "Record updated.";
    				c.forcedChatUpdateRequired = true;
    				c.updateRequired = true;
    			}



    Now in-game you need to be holding item 292 and have Owner status. If you click on the book it will let you jump on top of objects and print code to your Data/cfg/tile_block_list.txt - Then all you have to do is copy and paste those codes into your NPChandler.java



    Watch it working:


    Reply With Quote  
     

  2. #2  
    The One And Only

    01053's Avatar
    Join Date
    Apr 2011
    Age
    28
    Posts
    2,887
    Thanks given
    417
    Thanks received
    885
    Rep Power
    856
    Hi auto talker,

    Instead of doing this you could actually just check if the tile is walkable – I actually believe this is how most servers do it these days so yeah,

    Just download another server and look at how they're doing things.


    Reply With Quote  
     

  3. Thankful user:


  4. #3  
    Registered Member
    Join Date
    Jul 2011
    Posts
    90
    Thanks given
    3
    Thanks received
    7
    Rep Power
    11
    Quote Originally Posted by 01053 View Post
    Hi auto talker,

    Instead of doing this you could actually just check if the tile is walkable – I actually believe this is how most servers do it these days so yeah,

    Just download another server and look at how they're doing things.
    Thanks for the feedback I'm going to have a look at this.
    Reply With Quote  
     

  5. #4  
    ¦¦¦ RuneTimes ¦¦¦

    RainDropzZ's Avatar
    Join Date
    Oct 2010
    Posts
    389
    Thanks given
    31
    Thanks received
    108
    Rep Power
    556
    No Clipping is always server sided. Normaly you use the map files from the cache to make clipping work. Also your code would get reaaaaaaaally slow when you implement whole map chunks, just from the mass of tiles that you need to check for.
    Reply With Quote  
     

  6. #5  
    Registered Member
    Join Date
    Jul 2011
    Posts
    90
    Thanks given
    3
    Thanks received
    7
    Rep Power
    11
    Quote Originally Posted by RainDropzZ View Post
    No Clipping is always server sided. Normaly you use the map files from the cache to make clipping work. Also your code would get reaaaaaaaally slow when you implement whole map chunks, just from the mass of tiles that you need to check for.
    Ah. Now I think about it, it makes sense as people can always edit the client.

    And yeah I didn't really design it for the use of mass tiles, it's more for NPCs based in houses to avoid having to remove objects.
    But thanks again for the feedback - I'll have a look at messing with the map files
    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. [PI] Clipping Checks, Clipped projectiles, Clipped npcs
    By Project Diversion in forum Buying
    Replies: 3
    Last Post: 02-11-2013, 06:07 AM
  2. [PI] NPC and Player Clipping 10M RSGP
    By Coke zero in forum Buying
    Replies: 1
    Last Post: 07-01-2012, 07:18 PM
  3. [PI]Npc Sizes for clipped npcs
    By Organic in forum Help
    Replies: 4
    Last Post: 03-09-2012, 09:58 PM
  4. [pi]$ Npc & Player combat clipping$ [pi]
    By Usaclub in forum Requests
    Replies: 2
    Last Post: 04-29-2011, 01:54 PM
  5. [PI] Npc/Player following clipping
    By johny cash in forum Requests
    Replies: 0
    Last Post: 01-10-2011, 07:14 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
  •