Thread: [Elvarg] Working ladders?

Results 1 to 10 of 10
  1. #1 [Elvarg] Working ladders? 
    Registered Member immortal pie's Avatar
    Join Date
    Dec 2013
    Age
    27
    Posts
    15
    Thanks given
    3
    Thanks received
    1
    Rep Power
    11
    First off, I am a NOVICE programmer just trying to learn the ropes. But I struggled for hours trying to get a ladder fully working, and couldn't find any tutorials or snippets for this particular base. (Again I know this is simple but as I said I am a beginner.) Anyways I finally came up with this which seems to work just fine. I'm just going to post it in case any other newbies are struggling with this. There are likely flaws, and if you see any please point them out to me so that I can better learn.

    In ObjectPacketActionListener.java
    Code:
    	
    				case LADDER_195:
    					 player.getMovementQueue().reset();
    					 player.performAnimation(climbAnim); // 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(), 1));
    						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;
    Credits:
    Professor Oak for the base, writing the fix for the multiple level bug, and for showing me how to properly use tasks.
    nMilk for contributing to a cleaner version of the location check.
    hc747 for pointing out multiple level bug.
    Last edited by immortal pie; 01-07-2018 at 10:03 PM. Reason: Updated credits, fixed code.
    Reply With Quote  
     

  2. #2  
    Howdy

    nMik's Avatar
    Join Date
    Nov 2010
    Posts
    1,060
    Thanks given
    144
    Thanks received
    147
    Rep Power
    107
    Code:
                    case LADDER_UP:
                        player.getMovementQueue().reset();
                        if((Math.abs(player.getPosition().getX() - x) <= 1) ||
                            (Math.abs(player.getPosition().getY() - y) <= 1)){
                            TaskManager.submit(new Task(2) {
                                @Override
                                public void execute() {
                                    player.performAnimation(CLIMBING_ANIMATION);
                                    player.getPacketSender().sendMessage("You climb up the ladder.");
                                    player.moveTo(new Position(
                                            player.getPosition().getX(),
                                            player.getPosition().getY(),
                                            player.getPosition().getZ() + 1)
                                            );
                                    stop();
                                }
                            });
                        }else {
                            player.getPacketSender().sendMessage("I can't reach that!");
                        
                        }
                    break;

    Reply With Quote  
     

  3. Thankful users:


  4. #3  
    Registered Member immortal pie's Avatar
    Join Date
    Dec 2013
    Age
    27
    Posts
    15
    Thanks given
    3
    Thanks received
    1
    Rep Power
    11
    Quote Originally Posted by nMik View Post
    Code:
                    case LADDER_UP:
                        player.getMovementQueue().reset();
                        if((Math.abs(player.getPosition().getX() - x) <= 1) ||
                            (Math.abs(player.getPosition().getY() - y) <= 1)){
                            TaskManager.submit(new Task(2) {
                                @Override
                                public void execute() {
                                    player.performAnimation(CLIMBING_ANIMATION);
                                    player.getPacketSender().sendMessage("You climb up the ladder.");
                                    player.moveTo(new Position(
                                            player.getPosition().getX(),
                                            player.getPosition().getY(),
                                            player.getPosition().getZ() + 1)
                                            );
                                    stop();
                                }
                            });
                        }else {
                            player.getPacketSender().sendMessage("I can't reach that!");
                        
                        }
                    break;
    Looks much cleaner I didn't realize you could do that. Essentially accomplished the same task with much less code right? Anyways thank you!
    Reply With Quote  
     

  5. #4  
    Rune-Server Affiliate

    Join Date
    Aug 2015
    Posts
    431
    Thanks given
    55
    Thanks received
    114
    Rep Power
    126
    Quote Originally Posted by immortal pie View Post
    Looks much cleaner I didn't realize you could do that. Essentially accomplished the same task with much less code right? Anyways thank you!
    And that's a huge problem around here.
    Reply With Quote  
     

  6. #5  
    Registered Member immortal pie's Avatar
    Join Date
    Dec 2013
    Age
    27
    Posts
    15
    Thanks given
    3
    Thanks received
    1
    Rep Power
    11
    Quote Originally Posted by Famous Dexter View Post
    And that's a huge problem around here.
    Well, now I know!
    Reply With Quote  
     

  7. #6  
    Registered Member
    hc747's Avatar
    Join Date
    Dec 2013
    Age
    26
    Posts
    1,474
    Thanks given
    3,312
    Thanks received
    691
    Rep Power
    1098
    If spam clicked wont this allow users to go up multiple floors from one ladder?
    Reply With Quote  
     

  8. Thankful user:


  9. #7  
    Registered Member immortal pie's Avatar
    Join Date
    Dec 2013
    Age
    27
    Posts
    15
    Thanks given
    3
    Thanks received
    1
    Rep Power
    11
    Quote Originally Posted by hc747 View Post
    If spam clicked wont this allow users to go up multiple floors from one ladder?
    Wow good call. I checked and yes, it does allow you to move up two levels at a time. Anybody have a suggested fix?
    Reply With Quote  
     

  10. #8  
    Extreme Donator


    Join Date
    Oct 2010
    Posts
    2,853
    Thanks given
    1,213
    Thanks received
    1,622
    Rep Power
    5000
    Quote Originally Posted by immortal pie View Post
    Wow good call. I checked and yes, it does allow you to move up two levels at a time. Anybody have a suggested fix?
    Code:
    player.moveTo(new Position(player.getPosition().getX(), player.getPosition().getY(), 1);
    Also, should probably perform the animation before moving the player up.
    Reply With Quote  
     

  11. Thankful user:


  12. #9  
    Registered Member immortal pie's Avatar
    Join Date
    Dec 2013
    Age
    27
    Posts
    15
    Thanks given
    3
    Thanks received
    1
    Rep Power
    11
    I have updated the post, as well as the credits. Thanks for the tips!
    Reply With Quote  
     

  13. #10  
    Howdy

    nMik's Avatar
    Join Date
    Nov 2010
    Posts
    1,060
    Thanks given
    144
    Thanks received
    147
    Rep Power
    107
    Quote Originally Posted by immortal pie View Post
    I have updated the post, as well as the credits. Thanks for the tips!
    Code:
    if (def.getName().contains("Ladder")) {
                        if (LadderActions.climbLadder(player, def, position))
                                return;
                    }
    Code:
    public static boolean climbLadder(Player player, ObjectDefinition def, Position pos) {
            
            String direction = (def.interactions[0].equals("Climb-up")) ? "up" : "down";
            int currHeight = player.getPosition().getZ();
            int newHeight = (direction.equals("up")) ? (currHeight + 1) : (currHeight - 1);
            
            player.getMovementQueue().reset();
            if ((Math.abs(player.getPosition().getX() - pos.getX()) <= 1) ||
                (Math.abs(player.getPosition().getY() - pos.getY()) <= 1)) {
                player.performAnimation(new Animation(CLIMBING));
                TaskManager.submit(new Task(2) {
                    @Override
                    public void execute() {
                        player.getPacketSender().sendMessage("You climb " + direction + " the ladder.");
                        player.moveTo(new Position(
                                player.getPosition().getX(),
                                player.getPosition().getY(),
                                newHeight)
                                );
                        stop();
                    }
                });
                return true;
            }
            player.getPacketSender().sendMessage("I can't reach that!");
            return false;
        }
    You can spam it, but it will only print the message twice rather than moving up twice.

    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. OSRSPK/ELVARG Working skills
    By nochance in forum Help
    Replies: 1
    Last Post: 05-08-2017, 12:12 AM
  2. [Elvarg] Ladder code not working
    By Hyped in forum Help
    Replies: 10
    Last Post: 04-29-2017, 05:46 PM
  3. 82% working ladders
    By Martin in forum Snippets
    Replies: 10
    Last Post: 02-17-2014, 01:14 PM
  4. [PI] Working Ladders
    By ilike to own in forum Tutorials
    Replies: 21
    Last Post: 02-08-2011, 07:28 PM
  5. [delta] fully working ladders in sophanem
    By guppycity in forum Configuration
    Replies: 4
    Last Post: 09-16-2009, 12:37 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
  •