Thread: Nice way of handling objects

Results 1 to 9 of 9
  1. #1 Nice way of handling objects 
    Extreme Donator


    Join Date
    Oct 2010
    Posts
    1,666
    Thanks given
    253
    Thanks received
    405
    Discord
    View profile
    Rep Power
    296
    I don't think I have ever contributed a snippet or tutorial on Rune-Server before, so why not start giving back to the community.
    I am sharing a way of how I handle objects, and I am pretty sure that other people use something similar to this. I like this because of the organization, plus this frees up a lot of space in the ObjectHandler class, because having too many things in that one handleOption1 method can overload it and I have seen a lot of people complaining they ran out of space, I guess they have a lot of object actions or are just a bit sloppy o.o

    Anyways, first we are going to create a new package: com.rs.game.player.actions.objects

    Now in that, you can create different files to handle objects in different regions. I sort these classes by region/city such as Desert, Wilderness, Lumbridge, Varrock, etc. We can make one for Lumbridge as an example.

    Code:
    package com.rs.game.player.actions.objects;
    
    import com.rs.game.WorldObject;
    import com.rs.game.player.Player;
    
    /*
     * @Author Danny
     * Handles Lumbridge Objects
     */
    
    public class Lumbridge {
    
    	public static void decorateCoffin(Player player,
    			final WorldObject object) {
    		player.getPackets().sendGameMessage("You come to decorate the coffin....");
    		World.spawnNPC(4387, new WorldTile(3242, 3178, 0), -1, true);
    		player.setNextForceTalk(new ForceTalk("WHAT THE **** IT'S A GHOST?!?!!"));
                    return;
    	}
    	
    	public static boolean isObject(final WorldObject object) {
    		switch (object.getId()) {
    		case 76824:
    		return true;
    		default:
    		return false;
    		}
    	}
    
    	
    	
    	public static void HandleObject(Player player, final WorldObject object) {
    		final int id = object.getId();
    		if (id == 76824) { 
    			decorateCoffin(player, object); 
    		}
    		
    	}
    
    }
    Here you place the object ID.
    Here you edit the object action.

    Now lastly, go to ObjectHandler and add this

    Code:
    if (Lumbridge.isObject(object))
                    Lumbridge.HandleObject(player, object);
    For a quick explanation for this, the if statement checks to see if the object id belongs to the Lumbridge class, that is why we add the object id to the isObject method as true. Now if it sees that the object is a Lumbridge object, it will carry out the action using the HandleObject method. As you can see in the Lumbridge class, if the object has the id of the coffin, it will carry out the decorateCoffin method which is found above.

    Hope this makes things a bit easier for people, I prefer to see this done in seperate organized classes rather than a jumbled mess all over the place in ObjectHandler, but hey, everyone is different.
    Reply With Quote  
     

  2. #2  
    Success is the worst teacher

    Santa Hat's Avatar
    Join Date
    Oct 2012
    Age
    24
    Posts
    3,337
    Thanks given
    801
    Thanks received
    1,185
    Rep Power
    189
    It's nice for doing what your doing and re-creating rs but other than that I'm not sure why you would really create a new class to handle some objects

    But good contribution

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

  3. #3  
    Extreme Donator


    Join Date
    Oct 2010
    Posts
    1,666
    Thanks given
    253
    Thanks received
    405
    Discord
    View profile
    Rep Power
    296
    Quote Originally Posted by Santa Hat View Post
    It's nice for doing what your doing and re-creating rs but other than that I'm not sure why you would really create a new class to handle some objects

    But good contribution
    My reason is because I hate how ObjectHandler is getting so full and having different classes for each region makes it a lot easier to spot and handle objects. I mean, I've reached the point where I have made over 500 objects have actions, and they aren't just simple 1-3 line actions, so eventually my ObjectHandler is absolutely gigantic. Just think about how many objects are interactable in each city, it's alot.
    Reply With Quote  
     

  4. #4  
    Extreme Donator


    Join Date
    Oct 2010
    Posts
    1,666
    Thanks given
    253
    Thanks received
    405
    Discord
    View profile
    Rep Power
    296
    Quote Originally Posted by Savions sw View Post
    Code:
    	
    	public static boolean isObject(final WorldObject object) {
    		switch (object.getId()) {
    		case 76824:
    		return true;
    		default:
    		return false;
    		}
    Are you ****ing serious
    What did you say Mr. Scammer? Come back to troll on one of my threads when you have given me what I paid for 2 months ago.
    Reply With Quote  
     

  5. #5  
    Registered Member
    maffia-rpg's Avatar
    Join Date
    Jul 2011
    Posts
    2,776
    Thanks given
    587
    Thanks received
    759
    Rep Power
    120
    You should make an interface if your going to handle objects this way.

    Code:
    Lumbridge.decorateCoffin(player, object);
    Your already in that class, why do you re-call that class?
    Reply With Quote  
     

  6. #6  
    KNOWLEDGE IS POWER

    OG KingFox's Avatar
    Join Date
    Dec 2006
    Age
    30
    Posts
    1,683
    Thanks given
    628
    Thanks received
    1,055
    Discord
    View profile
    Rep Power
    709
    Quote Originally Posted by maffia-rpg View Post
    You should make an interface if your going to handle objects this way.

    Code:
    Lumbridge.decorateCoffin(player, object);
    Your already in that class, why do you re-call that class?
    was kinda wondering the same thing :L

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

  7. #7  
    Owner of Dawntained

    Mgt Madness's Avatar
    Join Date
    Oct 2011
    Age
    25
    Posts
    3,377
    Thanks given
    1,410
    Thanks received
    943
    Rep Power
    2027
    This is exactly what i do, for taverly dungeon objects, brimhaven, etc..
    The only problem is if an object id is present in both places lol, then you have to add an exception for the object in a certain area L

    EDIT:
    You forgot return;
    After it handles the objects, i use this to save the server effort to go through useless stuff.
    Reply With Quote  
     

  8. #8  
    Extreme Donator


    Join Date
    Oct 2010
    Posts
    1,666
    Thanks given
    253
    Thanks received
    405
    Discord
    View profile
    Rep Power
    296
    Quote Originally Posted by King Fox View Post
    was kinda wondering the same thing :L
    Idk, I was writing this up pretty quickly as my phone was dying and didn't take the time to look at what I had typed up already. I was doing this off the top of my head so it just passed through my head but your right, I don't need to call Lumbridge in that method since its already the class Lumbridge. Changed that, thanks!

    Quote Originally Posted by Mgt Madness View Post
    This is exactly what i do, for taverly dungeon objects, brimhaven, etc..
    The only problem is if an object id is present in both places lol, then you have to add an exception for the object in a certain area L

    EDIT:
    You forgot return;
    After it handles the objects, i use this to save the server effort to go through useless stuff.
    Glad I'm not the only person who thinks this is usefull and somewhat organized, and thanks for pointing it out, again I was writing this on my phone so it was a bit sloppy here and there.
    Reply With Quote  
     

  9. #9  
    Registered Member
    Join Date
    Oct 2012
    Posts
    1,280
    Thanks given
    331
    Thanks received
    257
    Rep Power
    69
    Can't read the blue colour. Maybe you want to change that. I wanna read it to decide whether I will use it or not. Not the other way around.
    I'm working on: [Only registered and activated users can see links. ]
    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. SkillHandler - New way of handling skills
    By Jamili in forum Tutorials
    Replies: 30
    Last Post: 04-23-2012, 05:14 PM
  2. [PI or others] Better way of handling commands
    By wakadoodle in forum Snippets
    Replies: 2
    Last Post: 07-26-2011, 09:41 PM
  3. Proper way of global objects?
    By Zahhak in forum Help
    Replies: 2
    Last Post: 01-29-2010, 10:04 PM
  4. Better ways of handling item equiping?
    By Underoath in forum Help
    Replies: 2
    Last Post: 12-24-2009, 10:55 AM
  5. Adding a nice way to handle objects (emulous)
    By Livinglife in forum Tutorials
    Replies: 15
    Last Post: 03-23-2009, 10:15 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
  •