Thread: Elvarg base, getting ladders to work..

Results 1 to 10 of 10
  1. #1 Elvarg base, getting ladders to work.. 
    Registered Member
    Join Date
    Aug 2014
    Posts
    10
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    Somewhere on the forums I found the following:

    Code:
    				case LADDER:
    					 player.getMovementQueue().reset();
    					 player.performAnimation(new Animation(828)); // Perform animation
    	                    if((Math.abs(player.getPosition().getX() - x) <= 1) ||  //Check if player is close to ladder.
    	                        (Math.abs(player.getPosition().getY() - y) <= 1)){
    	                        TaskManager.submit(new Task(2) { //After 2 ticks, move up the ladder.
    						@Override
    						public void execute() {
    						player.getPacketSender().sendMessage("You climb up the ladder.");
    						player.moveTo(new Position(player.getPosition().getX(), player.getPosition().getY(), 2));
    						player.getMovementQueue().reset();
    						stop(); // Stop task
    						}
    						});
    					}else {
    						player.getPacketSender().sendMessage("I can't reach that!"); //Player is not close to ladder
    																					//And cannot perform the action.
    					}
    				break;
    But this doesn't seem to be working the way I wanted.
    I then made this(which might be shitty code, I am quite new):

    Code:
    				case LADDER:
    					player.performAnimation(new Animation(828));
                        if((Math.abs(player.getPosition().getX() - x) <= 1) ||  //Check if player is close to ladder.
    	                        (Math.abs(player.getPosition().getY() - y) <= 1));
                        player.getClickDelay().reset();
                        TaskManager.submit(new Task(2) {
                        	public void execute() {
            					player.moveTo(new Position(2214, 3802, 1));
            					player.getPacketSender().sendMessage("You climb up a ladder.");
            					stop();
                        	}
                        });
    This works fine, but ofcourse only works for 1 ladder of the same id. (same for the first code I showed btw)
    How can I change this so that it only affects a specific ladder? (so for example by adding the ladders coordinates as a reference)

    The codes are pretty much the same, I just played around with the first one to my liking.. Like I said, I am not the best coder.
    Reply With Quote  
     

  2. #2  
    Registered Member

    Join Date
    Aug 2012
    Posts
    2,399
    Thanks given
    275
    Thanks received
    416
    Rep Power
    253
    Make sure your case LADDER is using correct object id.


    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Aug 2014
    Posts
    10
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    Ye the ladders are working, but when it is set to LADDER_20 for example, this means ALL of the LADDER_20 will take you to the same position.
    Reply With Quote  
     

  4. #4  
    Registered Thanker
    MrClassic's Avatar
    Join Date
    Oct 2008
    Age
    24
    Posts
    1,837
    Thanks given
    10,378
    Thanks received
    200
    Rep Power
    3370
    create an array of the ladder id's. And check if the user is clicking one of those ladders.

    spoonfeed:
    Code:
    int[] ladders = {1111, 2222, 3333, 4444};
    boolean isLadder = IntStream.of(ladders).anyMatch(x -> x == CLICKEDOBJECTID);
    something like that
    Thanks, MrClassic.

    [Only registered and activated users can see links. ]

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

  5. #5  
    Be the change you wanna see!
    Nozemi's Avatar
    Join Date
    Jul 2010
    Posts
    254
    Thanks given
    60
    Thanks received
    57
    Rep Power
    40
    Code:
    			// Stairs Handler
    			if (!Config.STAIRS_IGNORE.contains(id)) {
    				if (def.interactions[0].equalsIgnoreCase("climb-up")
    				|| Config.STAIRS_UP.contains(id)) {
    					performMovement(player, object, Direction.UP);
    					return;
    				}
    
    				if (def.interactions[0].equalsIgnoreCase("climb-down")
    				|| Config.STAIRS_DOWN.contains(id)) {
    					performMovement(player, object, Direction.DOWN);
    					return;
    				}
    			}
    This is what I have going right now. I also removed everything that has to do with that switch statement.
    You obviously need to add in those extra variables I added here, or remove them from my snippet.

    Then put the snippet before or after the switch statement (and probably just remove the LADDER case(s) from the switch).
    Reply With Quote  
     

  6. Thankful user:


  7. #6  
    Donator

    Nightleaf's Avatar
    Join Date
    Apr 2008
    Posts
    442
    Thanks given
    6
    Thanks received
    18
    Rep Power
    83
    Quote Originally Posted by Nozemi View Post
    Code:
    			// Stairs Handler
    			if (!Config.STAIRS_IGNORE.contains(id)) {
    				if (def.interactions[0].equalsIgnoreCase("climb-up")
    				|| Config.STAIRS_UP.contains(id)) {
    					performMovement(player, object, Direction.UP);
    					return;
    				}
    
    				if (def.interactions[0].equalsIgnoreCase("climb-down")
    				|| Config.STAIRS_DOWN.contains(id)) {
    					performMovement(player, object, Direction.DOWN);
    					return;
    				}
    			}
    This is what I have going right now. I also removed everything that has to do with that switch statement.
    You obviously need to add in those extra variables I added here, or remove them from my snippet.

    Then put the snippet before or after the switch statement (and probably just remove the LADDER case(s) from the switch).
    This is a good start but I would say it would be better to look at the action array that is in the cache on objects when you click them and perform an action if it matches/contains the string you want. This way you won't have to know any ids and if you decide to load new data this also covers those potential new objects.
    Reply With Quote  
     

  8. #7  
    Registered Thanker
    MrClassic's Avatar
    Join Date
    Oct 2008
    Age
    24
    Posts
    1,837
    Thanks given
    10,378
    Thanks received
    200
    Rep Power
    3370
    Quote Originally Posted by dannyrisepk View Post
    Ye the ladders are working, but when it is set to LADDER_20 for example, this means ALL of the LADDER_20 will take you to the same position.
    Quote Originally Posted by Nozemi View Post
    Code:
    			// Stairs Handler
    			if (!Config.STAIRS_IGNORE.contains(id)) {
    				if (def.interactions[0].equalsIgnoreCase("climb-up")
    				|| Config.STAIRS_UP.contains(id)) {
    					performMovement(player, object, Direction.UP);
    					return;
    				}
    
    				if (def.interactions[0].equalsIgnoreCase("climb-down")
    				|| Config.STAIRS_DOWN.contains(id)) {
    					performMovement(player, object, Direction.DOWN);
    					return;
    				}
    			}
    This is what I have going right now. I also removed everything that has to do with that switch statement.
    You obviously need to add in those extra variables I added here, or remove them from my snippet.

    Then put the snippet before or after the switch statement (and probably just remove the LADDER case(s) from the switch).
    he wants them to the same position. Not ALL ladders to work. So he would need the ladder id's
    Thanks, MrClassic.

    [Only registered and activated users can see links. ]

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

  9. #8  
    Be the change you wanna see!
    Nozemi's Avatar
    Join Date
    Jul 2010
    Posts
    254
    Thanks given
    60
    Thanks received
    57
    Rep Power
    40
    Quote Originally Posted by Nightleaf View Post
    This is a good start but I would say it would be better to look at the action array that is in the cache on objects when you click them and perform an action if it matches/contains the string you want. This way you won't have to know any ids and if you decide to load new data this also covers those potential new objects.
    That's what I did, isn't it? But I also added the possibility to specify in the config what stair IDs to ignore, or add if they don't have "climb-down" as an option.
    Reply With Quote  
     

  10. Thankful user:


  11. #9  
    Registered Thanker
    MrClassic's Avatar
    Join Date
    Oct 2008
    Age
    24
    Posts
    1,837
    Thanks given
    10,378
    Thanks received
    200
    Rep Power
    3370
    Quote Originally Posted by Nozemi View Post
    That's what I did, isn't it? But I also added the possibility to specify in the config what stair IDs to ignore, or add if they don't have "climb-down" as an option.
    Whoops, it's too early in the morning for me
    Thanks, MrClassic.

    [Only registered and activated users can see links. ]

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

  12. #10  
    Be the change you wanna see!
    Nozemi's Avatar
    Join Date
    Jul 2010
    Posts
    254
    Thanks given
    60
    Thanks received
    57
    Rep Power
    40
    Quote Originally Posted by MrClassic View Post
    he wants them to the same position. Not ALL ladders to work. So he would need the ladder id's
    Ahh my bad. Just check which coord the ladder you're interacting is in then, and have it move you to the new coord. Pretty much the same job.

    Quote Originally Posted by MrClassic View Post
    Whoops, it's too early in the morning for me
    I believe you were right, so it's not too early in the morning for you haha. Either way, it's almost the same job, but instead checking the coords.

    Quote Originally Posted by dannyrisepk View Post
    Somewhere on the forums I found the following:

    Code:
    				case LADDER:
    					 player.getMovementQueue().reset();
    					 player.performAnimation(new Animation(828)); // Perform animation
    	                    if((Math.abs(player.getPosition().getX() - x) <= 1) ||  //Check if player is close to ladder.
    	                        (Math.abs(player.getPosition().getY() - y) <= 1)){
    	                        TaskManager.submit(new Task(2) { //After 2 ticks, move up the ladder.
    						@Override
    						public void execute() {
    						player.getPacketSender().sendMessage("You climb up the ladder.");
    						player.moveTo(new Position(player.getPosition().getX(), player.getPosition().getY(), 2));
    						player.getMovementQueue().reset();
    						stop(); // Stop task
    						}
    						});
    					}else {
    						player.getPacketSender().sendMessage("I can't reach that!"); //Player is not close to ladder
    																					//And cannot perform the action.
    					}
    				break;
    But this doesn't seem to be working the way I wanted.
    I then made this(which might be shitty code, I am quite new):

    Code:
    				case LADDER:
    					player.performAnimation(new Animation(828));
                        if((Math.abs(player.getPosition().getX() - x) <= 1) ||  //Check if player is close to ladder.
    	                        (Math.abs(player.getPosition().getY() - y) <= 1));
                        player.getClickDelay().reset();
                        TaskManager.submit(new Task(2) {
                        	public void execute() {
            					player.moveTo(new Position(2214, 3802, 1));
            					player.getPacketSender().sendMessage("You climb up a ladder.");
            					stop();
                        	}
                        });
    This works fine, but ofcourse only works for 1 ladder of the same id. (same for the first code I showed btw)
    How can I change this so that it only affects a specific ladder? (so for example by adding the ladders coordinates as a reference)

    The codes are pretty much the same, I just played around with the first one to my liking.. Like I said, I am not the best coder.
    Just read the whole OP again.

    You basically need to check which coord the current stair is in. No need to check if player is close, as it triggers a walkToTask upon interacting, which executes when you get close to your object.

    So within the case LADDER:, you need to add if(object.getPosition().getX() == X_CORD && object.getPosition().getY() == Y_CORD) { MOVE PLAYER CODE GOES HERE }
    Reply With Quote  
     

  13. Thankful user:



Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. getting suite to work!
    By i owns u i in forum Help
    Replies: 2
    Last Post: 06-21-2009, 05:07 AM
  2. Getting loading to work
    By Deadly Uzi in forum Help
    Replies: 0
    Last Post: 06-18-2009, 10:53 PM
  3. Replies: 6
    Last Post: 02-14-2009, 06:54 AM
  4. Dodian, how to get glory to work :)
    By Knova in forum Tutorials
    Replies: 9
    Last Post: 08-29-2008, 08:12 PM
  5. Replies: 1
    Last Post: 04-20-2008, 01: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
  •