Thread: Some Logic help

Results 1 to 4 of 4
  1. #1 Some Logic help 
    Registered Member
    Join Date
    Jun 2020
    Posts
    21
    Thanks given
    4
    Thanks received
    0
    Discord
    View profile
    Rep Power
    11
    Hello Community,
    I will probably be flamed pretty quickly, but I am hoping someone could at least be kind enough to explain this rather than shut me down with some type of negative comments.

    I understand the basic concepts of if statements.
    If it rains{
    the game is cancelled.
    }
    It rained. Therefore, the game was cancelled.
    or the error would be
    The game was cancelled; therefore it rained.
    There could be multiple reasons for why the game could've been cancelled.

    I am just stating this before you tell me to go on a java site and look up my issue.

    I am looking at the ObjectHandler class at door ids.

    While the door is open, I noticed that while opened the console printed this:
    [ObjectHandler] examined object id : 1239, 3088, 3259, 0, 0, 1, Door
    and while closed.
    [ObjectHandler] examined object id : 1239, 3088, 3259, 0, 0, 0, Door

    The 1 & 0 at the end being a true and false statement I guess? The door is either opened or closed.

    Anywho, If I were to write an if statement, how would I go about creating a way to open and close the door using the ObjectHandler class.
    I've seen other tutorials but they never explain anything to me. It's not the fact that I don't undertstand what if statements do it's just how to word them.

    ( This server is for learning purposes to improve my code ) and one day I truly believe Runescape will die and I'll still be able to play the game through my own person local server.
    Reply With Quote  
     

  2. #2  
    Contributor

    clem585's Avatar
    Join Date
    Sep 2013
    Posts
    3,556
    Thanks given
    652
    Thanks received
    640
    Rep Power
    358
    From Matrix's ObjectHandler:

    Code:
    				Logger.log(
    						"ObjectHandler",
    						"examined object id : " + object.getId() + ", "
    								+ object.getX() + ", " + object.getY()
    								+ ", " + object.getPlane() + ", "
    								+ object.getType() + ", "
    								+ object.getRotation() + ", "
    								+ object.getDefinitions().name);
    That 0/1 is rotation.

    The easiest way to handle doors would be to spawn a temporary door object (World.spawnTemporaryObject I think ?) on top of the existing door with a rotation of (rot + 1). Very simple solution, but it has drawbacks. For example, if you decide to apply that code to all the objects that have "Door" in their name and "Open" in their option, you will run into special cases where this does not apply. For example, the option could be "unlock" instead of "open", or the id of the opened door could be different from the closed one. This is probably the best solution if you're new to this.

    The proper way to do this would probably be to have a data structure where you add door ids as you implement them (door by door), along with some config. For example:

    Code:
    [
      {
        doorId: 1,
        x: 2500, // could store x/y/z in one int, using them for demonstration purposes
        y: 2500,
        z: 0,
        toDoorId: 2,
        closedAfter: true, // for doors that close after the player goes throught like gnome stronghold.
        etc...
      }
    ]
    So anyway, for the 1st solution it would be something like this in ObjectHandler:

    Code:
    if (object.getDefinitions().getName.toLowerCase().contains("door") && object.getDefinitions().containsOption("Open")) {
        World.spawnTemporaryObject(new WorldObject(object.getId(), object.getType(), object.getRotation() + 1));
    }
    Project thread
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Jun 2020
    Posts
    21
    Thanks given
    4
    Thanks received
    0
    Discord
    View profile
    Rep Power
    11
    I found this in the ObjectHandler class:

    Code:
    public static boolean handleDoor(Player player, WorldObject object,
    			long timer) {
    		if (World.isSpawnedObject(object)) {
    			World.removeObject(object);
    			return false;
    		}
    		WorldObject openedDoor = new WorldObject(object.getId(),
    				object.getType(), (object.getRotation() + 1) & 0x3,
    				object.getX(), object.getY(), object.getPlane());
    		World.spawnObjectTemporary(openedDoor, timer);
    		return false;
    	}
    so I used this :

    Code:
     private static boolean handleDoor1(Player player, WorldObject object) {
    		return handleDoor(player, object, 1239); 
    	}
    somehow it worked.

    Is there a flaw using this system vs say the data structure?
    Reply With Quote  
     

  4. #4  
    Contributor

    clem585's Avatar
    Join Date
    Sep 2013
    Posts
    3,556
    Thanks given
    652
    Thanks received
    640
    Rep Power
    358
    Quote Originally Posted by Summer L View Post
    I found this in the ObjectHandler class:

    Code:
    public static boolean handleDoor(Player player, WorldObject object,
    			long timer) {
    		if (World.isSpawnedObject(object)) {
    			World.removeObject(object);
    			return false;
    		}
    		WorldObject openedDoor = new WorldObject(object.getId(),
    				object.getType(), (object.getRotation() + 1) & 0x3,
    				object.getX(), object.getY(), object.getPlane());
    		World.spawnObjectTemporary(openedDoor, timer);
    		return false;
    	}
    so I used this :

    Code:
     private static boolean handleDoor1(Player player, WorldObject object) {
    		return handleDoor(player, object, 1239); 
    	}
    somehow it worked.

    Is there a flaw using this system vs say the data structure?
    Nothing major, probably the quickest solution. The only downsides I can think of on top of my head are:

    - Some doors won't work if they don't have the "open" option. Something like "unlock" won't work.
    - Some doors that you don't want to be opened will be handled. Think of the strength door in warrior's guild.
    - Some doors are meant to close behind you. Again, like the warrior's guild strength door.
    Project thread
    [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. Some small help for the new coders :)
    By Engarde in forum Tutorials
    Replies: 0
    Last Post: 02-09-2008, 01:56 PM
  2. Some simple help, I'm confused [CS3]
    By xWarEagle in forum General
    Replies: 0
    Last Post: 01-02-2008, 01:15 AM
  3. Need some client help plz
    By woofdawg23 in forum Requests
    Replies: 2
    Last Post: 10-01-2007, 05:41 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
  •