Thread: Trapdoor Handling

Results 1 to 10 of 10
  1. #1 Trapdoor Handling 
    Erethium Developer
    Code Kiwi's Avatar
    Join Date
    Jan 2015
    Posts
    432
    Thanks given
    179
    Thanks received
    23
    Rep Power
    72
    Probably not the best way, but quickly wrote this up someone else might find this of use.
    Then again not much difference then handling it via actionhandler.java

    Updated thanks to @Mige5

    Code:
    public class Dungeons {
    
    /*Erethium RSPS*/
    private static void useDoor(final Client c, final int index) {
    		c.teleX = data[index][1];
    		c.teleY = data[index][2];
    		c.teleZ = data[index][3];
    		c.startAnimation(4597);
    		c.sendMessage("You open the trap door...");
    		EventManager.getSingleton().addEvent(new Event() {
    			@Override
    			public void execute(EventContainer container) {
    				c.getPA().movePlayer(c.teleX,c.teleY,c.teleZ);
    				c.startAnimation(9730);
    				c.sendMessage("You climb down the trap door...");
    				container.stop();
    			}
    
    		}, 5);
    	}
    
    private static int[][] data = { //ObjectID, Xcoords, Ycoords, Zcoords
    		{26933, 3097, 9868, 0}, //Edgevile Dungeon
    		{1755, 3096, 3468, 0}}; //Cockroach Dungeon
    
    public static boolean Trapdoor(Client c, int object) {
    		for(int i = 0; i < data.length; i++) {
    			if(object == data[i][0]) {
    				useDoor(c, i);
    				return true;
    			}
    		}
    		return false;
    	}
    }
    Code:
    		if (Dungeons.Trapdoor(c, objectType)) {
    		return;
    		}
    Last edited by Code Kiwi; 05-14-2018 at 04:32 AM.
    Reply With Quote  
     

  2. #2  
    Respected Member


    Kris's Avatar
    Join Date
    Jun 2016
    Age
    26
    Posts
    3,638
    Thanks given
    820
    Thanks received
    2,642
    Rep Power
    5000
    No. Just no.
    Think about your code logically - if two people use *any* trapdoor simultaneously, both will be teleported to the same location.
    Attached image
    Reply With Quote  
     

  3. Thankful users:


  4. #3  
    Erethium Developer
    Code Kiwi's Avatar
    Join Date
    Jan 2015
    Posts
    432
    Thanks given
    179
    Thanks received
    23
    Rep Power
    72
    Quote Originally Posted by Kris View Post
    No. Just no.
    Think about your code logically - if two people use *any* trapdoor simultaneously, both will be teleported to the same location.
    Ahh, i see now hehe. Just tested it.
    http://prntscr.com/jh9fc1

    Curious, would this be more rightful?

    c.getPA().movePlayer(data[I][1] ,data[I][2] ,data[I][3]);
    Reply With Quote  
     

  5. #4  
    Respected Member


    Kris's Avatar
    Join Date
    Jun 2016
    Age
    26
    Posts
    3,638
    Thanks given
    820
    Thanks received
    2,642
    Rep Power
    5000
    Quote Originally Posted by Erethium View Post
    private static int[][] data = { //ObjectID, Xcoords, Ycoords, Zcoords
    {26933, 12, 1, 0}};

    Object ID, Moverplay X, Moveplay Y, Moveplay Z?

    Not all trapdoors use same object ids?
    No. You used static variables that all players access alike within a scheduled task.
    Attached image
    Reply With Quote  
     

  6. Thankful user:


  7. #5  
    Community Veteran

    mige5's Avatar
    Join Date
    Aug 2008
    Posts
    5,528
    Thanks given
    573
    Thanks received
    1,410
    Rep Power
    2114
    Quote Originally Posted by Erethium View Post
    private static int[][] data = { //ObjectID, Xcoords, Ycoords, Zcoords
    {26933, 12, 1, 0}};

    Object ID, Moverplay X, Moveplay Y, Moveplay Z?

    Not all trapdoors use same object ids?
    doesnt matter...

    u are setting these values when ever some1 clicks any trap door:
    Code:
    		teleX = data[i][1];
    		teleY = data[i][2];
    		teleZ = data[i][3];
    then u use those values for teleporting... and it will use the values that they were last set to.
    Number of page #1 releases with most views & posts: (Updated: 2023)
    RS2 server section: 1
    RS2 client section: 2
    Reply With Quote  
     

  8. Thankful users:


  9. #6  
    Erethium Developer
    Code Kiwi's Avatar
    Join Date
    Jan 2015
    Posts
    432
    Thanks given
    179
    Thanks received
    23
    Rep Power
    72
    Quote Originally Posted by mige5 View Post
    doesnt matter...

    u are setting these values when ever some1 clicks any trap door:
    Code:
    		teleX = data[i][1];
    		teleY = data[i][2];
    		teleZ = data[i][3];
    then u use those values for teleporting... and it will use the values that they were last set to.
    Ah, i see.
    Thank's for that clearing that up.

    In my head it was thinking differently.
    What would be the best placement for something as such.

    Code:
    c.getPA().movePlayer(data[i][1] ,data[i][1] ,data[i][1]);
    from the same class without it being final?
    Reply With Quote  
     

  10. #7  
    Community Veteran

    mige5's Avatar
    Join Date
    Aug 2008
    Posts
    5,528
    Thanks given
    573
    Thanks received
    1,410
    Rep Power
    2114
    Quote Originally Posted by Erethium View Post
    Ah, i see.
    Thank's for that clearing that up.
    also u can reduce unnecessary looping:
    Code:
    if (Dungeons.Trapdoor(c, objectType)) {
    	return;
    }
    Code:
    public static boolean Trapdoor(Client c, int object) {
    		for(int i = 0; i < data.length; i++) {
    			if(object == data[i][0]) {
    				useDoor(c, i);
    				return true;
    			}
    		}
    		return false;
    	}
    }
    Code:
    public static void useDoor(final Client c, final int index) {
    		teleX = data[index][1];
    		teleY = data[index][2];
    		teleZ = data[index][3];
    		c.startAnimation(4597);
    		c.sendMessage("You open the trap door...");
    ....
    Number of page #1 releases with most views & posts: (Updated: 2023)
    RS2 server section: 1
    RS2 client section: 2
    Reply With Quote  
     

  11. Thankful user:


  12. #8  
    Erethium Developer
    Code Kiwi's Avatar
    Join Date
    Jan 2015
    Posts
    432
    Thanks given
    179
    Thanks received
    23
    Rep Power
    72
    Quote Originally Posted by mige5 View Post
    also u can reduce unnecessary looping:
    Code:
    if (Dungeons.Trapdoor(c, objectType)) {
    	return;
    }
    Code:
    public static boolean Trapdoor(Client c, int object) {
    		for(int i = 0; i < data.length; i++) {
    			if(object == data[i][0]) {
    				useDoor(c, i)
    				return true;
    			}
    		}
    		return false;
    	}
    }
    Code:
    public static void useDoor(final Client c, final int index) {
    		teleX = data[index][1];
    		teleY = data[index][2];
    		teleZ = data[index][3];
    		c.startAnimation(4597);
    		c.sendMessage("You open the trap door...");
    ....
    *Magic before my eyes*
    Much appreciated, didn't even think to reference the usedoor method in the class.
    Reply With Quote  
     

  13. #9  
    Registered MrClassic
    MrClassic's Avatar
    Join Date
    Oct 2008
    Age
    15
    Posts
    2,063
    Thanks given
    24,154
    Thanks received
    551
    Rep Power
    5000
    Most 317 undergrounds are located at the trapdoors coordinates + 6400 on the Y coordination. This will save you alot of time
    Reply With Quote  
     

  14. Thankful users:


  15. #10  
    Banned
    Join Date
    Sep 2017
    Posts
    339
    Thanks given
    24
    Thanks received
    30
    Rep Power
    0
    Thanks for the snippet not going to use this code i made it way better
    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] Trapdoor handling methods
    By Chelsea Grin in forum Snippets
    Replies: 9
    Last Post: 12-02-2012, 12:32 PM
  2. Complete Mining! Handled! All rocks working!
    By James in forum Tutorials
    Replies: 22
    Last Post: 09-26-2007, 05:49 AM
  3. Glassblowing [HANDLED!]
    By Laxika in forum Tutorials
    Replies: 10
    Last Post: 09-23-2007, 06:38 PM
  4. Smemelting whit interface! [HANDLED]
    By Laxika in forum Tutorials
    Replies: 13
    Last Post: 09-23-2007, 06:26 PM
  5. region handling
    By Pandora in forum Tutorials
    Replies: 10
    Last Post: 08-17-2007, 01: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
  •