Thread: Calculating interactive tiles for an object

Results 1 to 7 of 7
  1. #1 Calculating interactive tiles for an object 
    Registered Member
    Join Date
    Apr 2020
    Posts
    32
    Thanks given
    1
    Thanks received
    3
    Rep Power
    38
    Basically this will return an array of locations that can be used to verify if you are at the object. This will fix using objects through walls if you check that you are standing in one of the returned locations.
    Put this inside your RSObject class or GameObject class which ever your server uses.


    Code:
    	public final int NORTH = 2;
    	public final int EAST = 8;
    	public final int SOUTH = 32;
    	public final int WEST = 128;
    
    	public Location[] getInteractiveLocations() {
    	
    		ObjectDef def = ObjectDef.getObjectDef(getId());
    		
    		int xSize = def.xLength();
    		int ySize = def.yLength();
    		int type = getType();
    		
    		if (type == 10 || type == 11 || type == 22) {
    			if (getFace() == 1 || getFace() == 3) {
    				xSize = def.yLength();
    				ySize = def.xLength();
    			}
    		}
    		int indexSize = xSize * 2 + ySize * 2; 
    		int index = 0;
    		
    		Location[] perimeter = new Location[indexSize];
    	
    		// west side
    		for (int i = 0; i < ySize; i++) {
    			Location w = new Location(getX() - 1, getY() + i, getZ());
    			if ((Region.getClipping(w) & EAST) == 0) 
    				perimeter[index++] = w;
    		}
    	
    		// north side
    		for (int i = 0; i < xSize; i++) {
    			Location n = new Location(getX() + i, getY() + ySize, getZ());
    			if ((Region.getClipping(n) & SOUTH) == 0)
    				perimeter[index++] = n;
    		}
    	
    		// east side
    		for (int i = 0; i < ySize; i++) {
    			Location e = new Location(getX() + xSize, getY() + i, getZ());
    			if ((Region.getClipping(e) & WEST) == 0)
    				perimeter[index++] = e;
    		}
    	
    		//south side
    		for (int i = 0; i < xSize; i++) {
    			Location s = new Location(getX() + i, getY() - 1, getZ());
    			if ((Region.getClipping(s) & NORTH) == 0)
    				perimeter[index++] = s;
    		}		
    		Location[] validPositions = new Location[indexSize];
    		
    		index = 0;
    		
    		for (Location l : perimeter) {
    			if (l == null)
    				continue;
    			
    			if (Region.getClipping(l) < 256) {
    				validPositions[index++] = l;
    			}
    		}
    		return validPositions;
    	}
    Using this, May need to change RSObject to GameObject depends on your source.

    Code:
    	public boolean withinDistance(Player player, RSObject object) {
    		Location[] interactiveLocations = object.getInteractiveLocations();
    		
    		for(Location location : interactiveLocations) {
    			if (location == null)
    				continue;
    			if (location.equals(player.getLocation())) {
    				return true;
    			}
    		}
    		return false;
    	}

    [Only registered and activated users can see links. ]
    [Only registered and activated users can see links. ]
    [Only registered and activated users can see links. ]
    [Only registered and activated users can see links. ]
    [Only registered and activated users can see links. ]
    [Only registered and activated users can see links. ]
    [Only registered and activated users can see links. ]
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  2. Thankful user:


  3. #2  
    Skotos Founder

    Mantvis's Avatar
    Join Date
    Jan 2017
    Age
    20
    Posts
    817
    Thanks given
    129
    Thanks received
    157
    Rep Power
    116
    Thank you man, legend !
    Reply With Quote  
     

  4. #3  
    Registered Member
    Bartvh's Avatar
    Join Date
    May 2017
    Posts
    331
    Thanks given
    70
    Thanks received
    128
    Rep Power
    222
    You don't take access flags into consideration.
    Reply With Quote  
     

  5. #4  
    Registered Member
    Join Date
    Apr 2020
    Posts
    32
    Thanks given
    1
    Thanks received
    3
    Rep Power
    38
    Quote Originally Posted by Bartvh View Post
    You don't take access flags into consideration.
    Explain an access flag. Do you mean for dynamic objects? Because i handle those in a different way.
    Reply With Quote  
     

  6. #5  
    Extreme Donator


    Join Date
    Oct 2010
    Posts
    2,856
    Thanks given
    1,199
    Thanks received
    1,615
    Rep Power
    5000
    Quote Originally Posted by ggtip2 View Post
    Basically this will return an array of locations that can be used to verify if you are at the object. This will fix using objects through walls if you check that you are standing in one of the returned locations.
    This is a cool little snippet but for verification you should be using the client's methods for checking if a player has reached an object (especially if you don't have server-sided pathfinding). A refactored method was recently released here: [Only registered and activated users can see links. ]

    That way the client and server will match, so the client isn't sending you to a tile where it thinks you can interact meanwhile the server is blocking interaction.
    [Today 01:29 AM] RSTrials: Nice 0.97 Win/Loss Ratio luke. That's pretty bad.
    [Today 01:30 AM] Luke132: Ok u fucking moron i forgot i could influence misc.random
    Reply With Quote  
     

  7. #6  
    Registered Member
    Bartvh's Avatar
    Join Date
    May 2017
    Posts
    331
    Thanks given
    70
    Thanks received
    128
    Rep Power
    222
    Quote Originally Posted by ggtip2 View Post
    Explain an access flag. Do you mean for dynamic objects? Because i handle those in a different way.
    It's a flag in the object configs that indicates from which direction you can interact with the object. A furnace for example can only be interacted with if you stand in the spot where you can put in the bars.
    Reply With Quote  
     

  8. #7  
    Registered Member
    Join Date
    Apr 2020
    Posts
    32
    Thanks given
    1
    Thanks received
    3
    Rep Power
    38
    Quote Originally Posted by Professor Oak View Post
    This is a cool little snippet but for verification you should be using the client's methods for checking if a player has reached an object (especially if you don't have server-sided pathfinding). A refactored method was recently released here: [Only registered and activated users can see links. ]
    The way i use this on my server is by taking the tile the client sends and checking if that tile is one of the tiles that this provides. So it does get the right tile assuming its a static object.
    Code:
    		if (steps > 0) {
    			RS317PathFinder.findRoute(player, path[(steps - 1)][0], path[(steps - 1)][1], true, 16, 16);
    			player.objectActionLocation = new Location(path[(steps - 1)][0], path[(steps - 1)][1], player.getZ());
    		} else {
    			RS317PathFinder.findRoute(player, firstStepX, firstStepY, true, 16, 16);
    			player.objectActionLocation = new Location(firstStepX, firstStepY, player.getZ());
    		}
    Like so ^. taken out of the movement packet.

    Obviously if there's no direct path to the object then "player.objectActionLocation" would be wrong and it can be verified by checking if its any of the tiles that this returns. If not then its unreachable.

    I did try that snippet but it didn't work at all for me. EDITED nevermind it works good.

    Quote Originally Posted by Bartvh View Post
    It's a flag in the object configs that indicates from which direction you can interact with the object. A furnace for example can only be interacted with if you stand in the spot where you can put in the bars.

    Thanks ill look into this
    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: 3
    Last Post: 10-23-2017, 07:30 AM
  2. Code for "Facing an object"?
    By BryceTheCoder in forum Help
    Replies: 2
    Last Post: 09-03-2012, 12:17 AM
  3. Replies: 3
    Last Post: 07-06-2011, 09:44 AM
  4. Anyone have an Object Id list for 317?
    By Hidden in forum Help
    Replies: 1
    Last Post: 12-21-2009, 09:33 PM
  5. getting an object to update for everyone
    By Shamon King in forum Tutorials
    Replies: 3
    Last Post: 01-03-2008, 09:51 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
  •