Welcome, guest! Please login or register.

    * Shoutbox

    RefreshHistory
    • stCky: Palidinho is your OpenGL (was it OpenGL?) stuff open source anywhere?
      August 16, 2017, 09:07:22 PM
    • Travas:BUILD THE WALL
      August 15, 2017, 09:28:49 PM
    • Travas: i have ass cancer
      August 15, 2017, 09:23:29 PM
    • stCky: what are the fudge are you tryna ask?
      August 15, 2017, 08:21:35 PM
    • bader: what are the rsps community alive ?
      August 15, 2017, 05:46:16 PM
    • bader: yo guys
      August 15, 2017, 05:46:08 PM
    • Spacehost:[link] Updated our thread :)
      August 15, 2017, 09:40:34 AM
    • Adaro: The client is in Download section at Homepage
      August 15, 2017, 01:09:20 AM
    • FaTe_Of_GoDs: where do i get the client?????????????
      August 14, 2017, 05:23:14 PM
    • stCky: can anyone help me? I cant login to the shoutbox
      August 13, 2017, 05:45:15 PM
    • drubrkletern: appeal denied
      August 13, 2017, 02:35:27 PM
    • King_Trout:[link]
      August 13, 2017, 11:17:12 AM
    • Cole1497: no sorry
      August 13, 2017, 10:27:14 AM
    • ayz: yo can anyone explain something to me
      August 13, 2017, 08:08:51 AM
    • coolking12: Hi
      August 13, 2017, 04:16:06 AM
    • stCky: n+1
      August 11, 2017, 06:09:24 PM
    • PalidinoDH: How many more pages are going to show errors before this dude gets on and fixes shit
      August 11, 2017, 04:57:00 PM
    • stCky: it is made by the wonderful people at jetbrains
      August 10, 2017, 10:00:06 PM
    • Zoravon: what's the difference between that and eclipse?
      August 10, 2017, 05:59:52 PM
    • stCky: use an IDE like IntelliJ or shitclipse
      August 10, 2017, 05:33:01 PM

    Author Topic: PI All single doors 100% working  (Read 18881 times)

    0 Members and 1 Guest are viewing this topic.

    Offlinekillamess

    • Member
    • ***
    • Posts: 217
    • Thanks: +0/-0
      • View Profile
    PI All single doors 100% working
    « on: November 27, 2011, 12:04:29 AM »
    Allows the server to have over 1000 perfectly working doors.
    I have now converted the code into what most people use (PI)

    This will make all single doors on your server work to get DoubleDoors working
    do this snippet afterwards - DoubleDoors

    Video of this:
    https://www.youtube.com/watch?v=O4CjQRLIlKE

    First you need the door file (5kb) contains all single doors
    doors.rar

    This goes into your Data folder make sure you the doors.txt file in this and not the doors.rar

    More doors can also be added into this if you follow the format correctly (some doors never are opened like rfd and so on, so this leaves an option to add more in a super easy format)
    -id-x-y-f-z-t

    Key:
    - = space
    id = the door Id
    x = the doors x co ordinate
    y = the doors y co ordinate
    f = the doors current facing direction 0 = westside, 1 = northside, 2 = east side, 3 = southside
    z = the doors height level
    t = the doors type (normal doors are type 0 and some diagonal doors are type 9)


    Spaces must be in front of every number, It will work out how to handle the door
     if you added it correctly.


    Then you'll need the door class, it should be placed so its like src/server/model/players/objects/Doors.java

    Code: [Select]
    package server.model.players.objects;

    import java.util.ArrayList;
    import java.util.List;
    import java.io.*;
    import java.util.Scanner;

    import server.Server;
    import server.world.ObjectHandler;

    /**
     *
     * @author Killamess
     * Basic door manipulation
     *
     */
    public class Doors {

    private static Doors singleton = null;

    private List<Doors> doors = new ArrayList<Doors>();

    private File doorFile;

    public static Doors getSingleton() {
    if (singleton == null) {
    singleton = new Doors("./Data/doors.txt");
    }
    return singleton;
    }

    private Doors(String file){
    doorFile = new File(file); 
    }

    private Doors(int door, int x, int y, int z, int face, int type, int open) {
    this.doorId = door;
    this.originalId = door;
    this.doorX = x;
    this.doorY = y;
    this.originalX = x;
    this.originalY = y;
    this.doorZ = z;
    this.originalFace = face;
    this.currentFace = face;
    this.type = type;
    this.open = open;
    }

    private Doors getDoor(int id, int x, int y, int z) {
    for (Doors d : doors) {
    if (d.doorId == id) {
    if (d.doorX == x && d.doorY == y && d.doorZ == z) {
    return d;
    }
    }
    }
    return null;
    }

    public boolean handleDoor(int id, int x, int y, int z) {

    Doors d = getDoor(id, x, y, z);

    if (d == null) {
    return false;
    }
    int xAdjustment = 0, yAdjustment = 0;
    if (d.type == 0) {
    if (d.open == 0) {
    if (d.originalFace == 0 && d.currentFace == 0) {
    xAdjustment = -1;
    } else if (d.originalFace == 1 && d.currentFace == 1) {
    yAdjustment = 1;
    } else if (d.originalFace == 2 && d.currentFace == 2) {
    xAdjustment = 1;
    } else if (d.originalFace == 3 && d.currentFace == 3) {
    yAdjustment = -1;
    }
    } else if (d.open == 1) {
    if (d.originalFace == 0 && d.currentFace == 0) {
    yAdjustment = 1;
    } else if (d.originalFace == 1 && d.currentFace == 1) {
    xAdjustment = 1;
    } else if (d.originalFace == 2 && d.currentFace == 2) {
    yAdjustment = -1;
    } else if (d.originalFace == 3 && d.currentFace == 3) {
    xAdjustment = -1;
    }
    }
    } else if (d.type == 9) {
    if (d.open == 0) {
    if (d.originalFace == 0 && d.currentFace == 0) {
    xAdjustment = 1;
    } else if (d.originalFace == 1 && d.currentFace == 1) {
    xAdjustment = 1;
    } else if (d.originalFace == 2 && d.currentFace == 2) {
    xAdjustment = -1;
    } else if (d.originalFace == 3 && d.currentFace == 3) {
    xAdjustment = -1;
    }
    } else if (d.open == 1) {
    if (d.originalFace == 0 && d.currentFace == 0) {
    xAdjustment = 1;
    } else if (d.originalFace == 1 && d.currentFace == 1) {
    xAdjustment = 1;
    } else if (d.originalFace == 2 && d.currentFace == 2) {
    xAdjustment = -1;
    } else if (d.originalFace == 3 && d.currentFace == 3) {
    xAdjustment = -1;
    }
    }
    }
    if (xAdjustment != 0 || yAdjustment != 0) {
    Objects o = new Objects(-1, d.doorX, d.doorY, d.doorZ, 0, d.type, 0);
    Server.objectHandler.placeObject(o);
    }
    if (d.doorX == d.originalX && d.doorY == d.originalY) {
    d.doorX += xAdjustment;
    d.doorY += yAdjustment;
    } else {
    Objects o = new Objects(-1, d.doorX, d.doorY, d.doorZ, 0, d.type, 0);
    Server.objectHandler.placeObject(o);
    d.doorX = d.originalX;
    d.doorY = d.originalY;
    }
    if (d.doorId == d.originalId) {
    if (d.open == 0) {
    d.doorId += 1;
    } else if (d.open == 1) {
    d.doorId -= 1;
    }
    } else if (d.doorId != d.originalId) {
    if (d.open == 0) {
    d.doorId -= 1;
    } else if (d.open == 1) {
    d.doorId += 1;
    }
    }
    Server.objectHandler.placeObject(new Objects(d.doorId, d.doorX, d.doorY, d.doorZ, getNextFace(d), d.type, 0));
    return true;
    }

    private int getNextFace(Doors d) {
    int f = d.originalFace;
    if (d.type == 0) {
    if (d.open == 0) {
    if (d.originalFace == 0 && d.currentFace == 0) {
    f = 1;
    } else if (d.originalFace == 1 && d.currentFace == 1) {
    f = 2;
    } else if (d.originalFace == 2 && d.currentFace == 2) {
    f = 3;
    } else if (d.originalFace == 3 && d.currentFace == 3) {
    f = 0;
    } else if (d.originalFace != d.currentFace){
    f = d.originalFace;
    }
    } else if (d.open == 1) {
    if (d.originalFace == 0 && d.currentFace == 0) {
    f = 3;
    } else if (d.originalFace == 1 && d.currentFace == 1) {
    f = 0;
    } else if (d.originalFace == 2 && d.currentFace == 2) {
    f = 1;
    } else if (d.originalFace == 3 && d.currentFace == 3) {
    f = 2;
    } else if (d.originalFace != d.currentFace){
    f = d.originalFace;
    }
    }
    } else if (d.type == 9) {
    if (d.open == 0) {
    if (d.originalFace == 0 && d.currentFace == 0) {
    f = 3;
    } else if (d.originalFace == 1 && d.currentFace == 1) {
    f = 2;
    } else if (d.originalFace == 2 && d.currentFace == 2) {
    f = 1;
    } else if (d.originalFace == 3 && d.currentFace == 3) {
    f = 0;
    } else if (d.originalFace != d.currentFace){
    f = d.originalFace;
    }
    } else if (d.open == 1) {
    if (d.originalFace == 0 && d.currentFace == 0) {
    f = 3;
    } else if (d.originalFace == 1 && d.currentFace == 1) {
    f = 0;
    } else if (d.originalFace == 2 && d.currentFace == 2) {
    f = 1;
    } else if (d.originalFace == 3 && d.currentFace == 3) {
    f = 2;
    } else if (d.originalFace != d.currentFace){
    f = d.originalFace;
    }
    }
    }
    d.currentFace = f;
    return f;
    }

    public void load() {
    long start = System.currentTimeMillis();
    try {
    singleton.processLineByLine();
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    }
    System.out.println("Loaded "+ doors.size() +" doors in "+ (System.currentTimeMillis() - start) +"ms.");
    }

    private final void processLineByLine() throws FileNotFoundException {
    Scanner scanner = new Scanner(new FileReader(doorFile));
        try {
        while(scanner.hasNextLine()) {
        processLine(scanner.nextLine());
        }
      } finally {
        scanner.close();
        }
    }

    protected void processLine(String line){
    Scanner scanner = new Scanner(line);
    scanner.useDelimiter(" ");
    try {
    while(scanner.hasNextLine()) {
    int id = Integer.parseInt(scanner.next());
    int x = Integer.parseInt(scanner.next());
        int y = Integer.parseInt(scanner.next());
        int f = Integer.parseInt(scanner.next());
        int z = Integer.parseInt(scanner.next());
        int t = Integer.parseInt(scanner.next());
        doors.add(new Doors(id,x,y,z,f,t,alreadyOpen(id)?1:0));
    }
    } finally {
    scanner.close();
    }
    }

    private boolean alreadyOpen(int id) {
    for (int i = 0; i < openDoors.length; i++) {
    if (openDoors[i] == id) {
    return true;
    }
    }
    return false;
    }

    private int doorId;
    private int originalId;
    private int doorX;
    private int doorY;
    private int originalX;
    private int originalY;
    private int doorZ;
    private int originalFace;
    private int currentFace;
    private int type;
    private int open;

    private static int[] openDoors = {
    1504, 1514, 1517, 1520, 1531,
    1534, 2033, 2035, 2037, 2998,
    3271, 4468, 4697, 6101,6103,
    6105, 6107, 6109, 6111, 6113,
    6115, 6976, 6978, 8696, 8819,
    10261, 10263,10265,11708,11710,
    11712,11715,11994,12445, 13002,
    };

    }

    Then in your ClickObject packet you will see something like this
    Code: [Select]

    case FIRST_CLICK:
    c.objectX = c.getInStream().readSignedWordBigEndianA();
    c.objectId = c.getInStream().readUnsignedWord();
    c.objectY = c.getInStream().readUnsignedWordA();

    under that add this
    Code: [Select]
    if(c.goodDistance(c.getX(), c.getY(), c.objectX, c.objectY, 1)) {
    if (Doors.getSingleton().handleDoor(c.objectId, c.objectX, c.objectY, c.heightLevel)) {
    return;
    }
    }
    import Doors, this goes with the rest of the imports in ClickObject.
    Code: [Select]
    import server.model.players.objects.Doors;


    Also in your objectHandler at the placeObject method you'll need to add this above the other code (inside the placeObject method).
    Code: [Select]
    ArrayList<Objects> toremove = new ArrayList<Objects>();

    for (Objects s : globalObjects) {
    if (s.getObjectX() == o.getObjectX() && s.getObjectY() == o.getObjectY()) {
    toremove.add(s);
    }
    }
    for (Objects s : toremove) {
    if (globalObjects.contains(s)) {
    globalObjects.remove(s);
    }
    }
    globalObjects.add(o);

    This will stop the server making lots of objects and instead it will search for already existing objects, delete them then add your object.


    Also you need to add this to your Server.java file find the main method and in it, it will have something like this
    Code: [Select]
    EventManager.initialize();
    under ^^^ that add this
    Code: [Select]
    Doors.getSingleton().load();
    Also you will need to import Doors, this goes at the top of your Server.java file with the other imports.
    Code: [Select]
    import server.model.players.objects.Doors;

    If its loaded right it should say this when you start up the server
    Code: [Select]
    Loaded 1023 doors in 152ms.
    Gates will not work with this.
    « Last Edit: November 29, 2011, 10:09:58 PM by killamess »
    wtf there is no autospawn theres only a autospawn.cfg

    Offlinelostmyphat

    • Member
    • ****
    • Posts: 1,746
    • Thanks: +0/-0
      • View Profile
    Re: Door system
    « Reply #1 on: November 27, 2011, 12:27:01 AM »
    Very nice!
    Visit my RSREMAKE thread here: http://www.moparscape.org/smf/index.php/topic,513804.0
    If you are going to pm me about helping your rsps I won't give one pony poop


    OfflineRyley

    • Member
    • ****
    • *
    • Posts: 7,315
    • Thanks: +0/-0
      • View Profile
    Re: Door system
    « Reply #2 on: November 27, 2011, 12:53:23 AM »
    Mind posting your object manager constructor?


    Offlinekillamess

    • Member
    • ***
    • Posts: 217
    • Thanks: +0/-0
      • View Profile
    Re: Door system
    « Reply #3 on: November 27, 2011, 01:00:31 AM »
    Mind posting your object manager constructor?
    Code: [Select]
    private static ObjectManager singleton = null;

    public static ObjectManager getSingleton() {
    if (singleton == null) {
    singleton = new ObjectManager();
    }
    return singleton;
    }
    wtf there is no autospawn theres only a autospawn.cfg

    OfflineRyley

    • Member
    • ****
    • *
    • Posts: 7,315
    • Thanks: +0/-0
      • View Profile
    Re: Door system
    « Reply #4 on: November 27, 2011, 01:01:01 AM »
    Thank you.

    OfflineZymus

    • Member
    • ****
    • *
    • Posts: 7,267
    • Thanks: +0/-0
      • View Profile
    Re: Door system
    « Reply #5 on: November 27, 2011, 01:30:04 AM »
    Code: Java
    1. privatestaticfinal Singleton INSTANCE =new Singleton();
    2.  
    3. private Singleton(){
    4.     // load
    5. }
    6.  
    7. publicstatic Singleton getSIngleton(){
    8.     return INSTANCE;
    9. }
    10.  

    OfflineRyley

    • Member
    • ****
    • *
    • Posts: 7,315
    • Thanks: +0/-0
      • View Profile
    Re: Door system
    « Reply #6 on: November 27, 2011, 01:54:59 AM »
    Yeah, when he posted it I understood how it worked.

    OfflineThe Outsider

    • Member
    • ****
    • Posts: 1,185
    • Thanks: +0/-0
      • View Profile
    Re: Door system
    « Reply #7 on: November 27, 2011, 01:55:44 AM »
    The only piece of information I truly needed was the diagonal door type = 9. Thanks! Also, Project No-Doze is under rated, shame you stopped developing it.

    Offlinejohnl17

    • Member
    • ****
    • Posts: 324
    • Thanks: +0/-0
      • View Profile
    Re: Door system
    « Reply #8 on: November 27, 2011, 09:52:25 AM »
    This looks like it was made for PI? or hyperion?


    OfflineThe Outsider

    • Member
    • ****
    • Posts: 1,185
    • Thanks: +0/-0
      • View Profile
    Re: Door system
    « Reply #10 on: November 27, 2011, 11:06:55 AM »
    This looks like it was made for PI? or hyperion?

    He created it for shard I believe. Wouldn't be to hard to convert.
    Shard/No-Doze yes.

    Offlinekillamess

    • Member
    • ***
    • Posts: 217
    • Thanks: +0/-0
      • View Profile
    Re: Door system
    « Reply #11 on: November 27, 2011, 07:37:53 PM »
    Ok I have converted it into PI, however i have not tested this.
    wtf there is no autospawn theres only a autospawn.cfg

    Offlinepk2play

    • Member
    • ****
    • Posts: 1,676
    • Thanks: +0/-0
      • View Profile
    Re: Door system (Converted to PI)
    « Reply #12 on: November 27, 2011, 07:44:50 PM »
    Few errors
    Code: [Select]
    src\server\model\players\ActionHandler.java:36: handleDoor(int,int,int,int) in s
    erver.model.players.Doors cannot be applied to (int,int,int)
                if (Doors.getSingleton().handleDoor(obX, obY, c.heightLevel)) {
                                        ^
    src\server\model\players\Doors.java:117: placeObject(server.model.objects.Object
    ) in server.world.ObjectManager cannot be applied to (server.model.objects.Objec
    ts)
                            Server.objectManager.placeObject(o);
                                                ^
    src\server\model\players\Doors.java:124: placeObject(server.model.objects.Object
    ) in server.world.ObjectManager cannot be applied to (server.model.objects.Objec
    ts)
                            Server.objectManager.placeObject(o);
                                                ^
    src\server\model\players\Doors.java:141: placeObject(server.model.objects.Object
    ) in server.world.ObjectManager cannot be applied to (server.model.objects.Objec
    ts)
                    Server.objectManager.placeObject(new Objects(d.doorId, d.doorX,
    d.doorY, d.doorZ, getNextFace(d), d.type, 0));
    No dwarf Cannon U could try convert it from a [pi]

    OfflineRyley

    • Member
    • ****
    • *
    • Posts: 7,315
    • Thanks: +0/-0
      • View Profile
    Re: Door system (Converted to PI)
    « Reply #13 on: November 27, 2011, 07:53:46 PM »
    Doors.getSingleton().handleDoor(obX, obY, c.heightLevel)

    To

    Doors.getSingleton().handleDoor(objectType, obX, obY, c.heightLevel)

    Offlinekillamess

    • Member
    • ***
    • Posts: 217
    • Thanks: +0/-0
      • View Profile
    Re: Door system (Converted to PI)
    « Reply #14 on: November 27, 2011, 08:06:19 PM »
    Few errors
    Code: [Select]
    src\server\model\players\ActionHandler.java:36: handleDoor(int,int,int,int) in s
    erver.model.players.Doors cannot be applied to (int,int,int)
                if (Doors.getSingleton().handleDoor(obX, obY, c.heightLevel)) {
                                        ^
    src\server\model\players\Doors.java:117: placeObject(server.model.objects.Object
    ) in server.world.ObjectManager cannot be applied to (server.model.objects.Objec
    ts)
                            Server.objectManager.placeObject(o);
                                                ^
    src\server\model\players\Doors.java:124: placeObject(server.model.objects.Object
    ) in server.world.ObjectManager cannot be applied to (server.model.objects.Objec
    ts)
                            Server.objectManager.placeObject(o);
                                                ^
    src\server\model\players\Doors.java:141: placeObject(server.model.objects.Object
    ) in server.world.ObjectManager cannot be applied to (server.model.objects.Objec
    ts)
                    Server.objectManager.placeObject(new Objects(d.doorId, d.doorX,
    d.doorY, d.doorZ, getNextFace(d), d.type, 0));

    Should be fixed now
    wtf there is no autospawn theres only a autospawn.cfg

    OfflineRyley

    • Member
    • ****
    • *
    • Posts: 7,315
    • Thanks: +0/-0
      • View Profile
    Re: Door system (Converted to PI)
    « Reply #15 on: November 27, 2011, 08:20:30 PM »
    That works.

    Offlineiz3 legend

    • Member
    • ****
    • Posts: 1,024
    • Thanks: +0/-0
      • View Profile
    Re: PI All single doors 100% working
    « Reply #16 on: November 27, 2011, 08:23:18 PM »
    Nice one man, good luck with the server.

    Offlinepk2play

    • Member
    • ****
    • Posts: 1,676
    • Thanks: +0/-0
      • View Profile
    Re: Door system (Converted to PI)
    « Reply #17 on: November 27, 2011, 08:25:01 PM »
    Few errors
    Code: [Select]
    src\server\model\players\ActionHandler.java:36: handleDoor(int,int,int,int) in s
    erver.model.players.Doors cannot be applied to (int,int,int)
                if (Doors.getSingleton().handleDoor(obX, obY, c.heightLevel)) {
                                        ^
    src\server\model\players\Doors.java:117: placeObject(server.model.objects.Object
    ) in server.world.ObjectManager cannot be applied to (server.model.objects.Objec
    ts)
                            Server.objectManager.placeObject(o);
                                                ^
    src\server\model\players\Doors.java:124: placeObject(server.model.objects.Object
    ) in server.world.ObjectManager cannot be applied to (server.model.objects.Objec
    ts)
                            Server.objectManager.placeObject(o);
                                                ^
    src\server\model\players\Doors.java:141: placeObject(server.model.objects.Object
    ) in server.world.ObjectManager cannot be applied to (server.model.objects.Objec
    ts)
                    Server.objectManager.placeObject(new Objects(d.doorId, d.doorX,
    d.doorY, d.doorZ, getNextFace(d), d.type, 0));

    Should be fixed now
    <3<3<3<3
    No dwarf Cannon U could try convert it from a [pi]

    OfflineRyley

    • Member
    • ****
    • *
    • Posts: 7,315
    • Thanks: +0/-0
      • View Profile
    Re: PI All single doors 100% working
    « Reply #18 on: November 27, 2011, 08:26:29 PM »
    Some of the double doors work, only one side of the door does though.

    Offlinekillamess

    • Member
    • ***
    • Posts: 217
    • Thanks: +0/-0
      • View Profile
    Re: PI All single doors 100% working
    « Reply #19 on: November 27, 2011, 08:43:57 PM »
    Some of the double doors work, only one side of the door does though.

    You will need my doubleDoor class but I have not released it.
    wtf there is no autospawn theres only a autospawn.cfg

     

    Copyright © 2017 MoparScape. All rights reserved.
    Powered by SMFPacks SEO Pro Mod |
    SimplePortal 2.3.5 © 2008-2012, SimplePortal