Thread: [PI] Object Manager - Object Height

Results 1 to 10 of 10
  1. #1 [PI] Object Manager - Object Height 
    Registered Member Aleksandr's Avatar
    Join Date
    Sep 2006
    Age
    30
    Posts
    1,027
    Thanks given
    450
    Thanks received
    131
    Discord
    View profile
    Rep Power
    53
    my objectmanager does not spawn an object whenever i reach the proper height! it will spawn the new object only if i'm on the same height and i get near it(

    Code:
    package server.world;
    
    import java.util.ArrayList;
    
    import server.model.objects.Object;
    import server.util.Misc;
    import server.model.players.Client;
    import server.Server;
    
    /**
     * @author Sanity
     */
    
    public class ObjectManager {
    
    	public ArrayList<Object> objects = new ArrayList<Object>();
    	private ArrayList<Object> toRemove = new ArrayList<Object>();
    	public void process() {
    		for (Object o : objects) {
    			if (o.tick > 0)
    				o.tick--;
    			//if (o
    			else {
    				updateObject(o);
    				toRemove.add(o);
    			}		
    		}
    		for (Object o : toRemove) {
    			if (isObelisk(o.newId)) {
    				int index = getObeliskIndex(o.newId);
    				if (activated[index]) {
    					activated[index] = false;
    					teleportObelisk(index);
    				}
    			}
    			objects.remove(o);	
    		}
    		toRemove.clear();
    	}
    	
    	public void removeObject(int x, int y) {
    		for (int j = 0; j < Server.playerHandler.players.length; j++) {
    			if (Server.playerHandler.players[j] != null) {
    				Client c = (Client)Server.playerHandler.players[j];
    				c.getPA().object(-1, x, y, 0, 10);
    				c.sendMessage("Removed Object - ObjectManager");
    			}	
    		}	
    	}
    	
    	public void updateObject(Object o) {
    		for (int j = 0; j < Server.playerHandler.players.length; j++) {
    			if (Server.playerHandler.players[j] != null) {
    				Client c = (Client)Server.playerHandler.players[j];
    				//if (c.heightLevel == o.height) {  //note: i added this to not spawn an object on every single floor, but when i reach the correct floor, it won't spawn the object.
    				c.getPA().object(o.newId, o.objectX, o.objectY, o.face, o.type);
    				c.sendMessage("Update Object - ObjectManager");
    				//}
    			}	
    		}	
    	}
    	
    	public static void placeObject(Object o) {
    		for (int j = 0; j < Server.playerHandler.players.length; j++) {
    			if (Server.playerHandler.players[j] != null) {
    				Client c = (Client)Server.playerHandler.players[j];
    				if (c.distanceToPoint(o.objectX, o.objectY) <= 60 && c.heightLevel == o.height)
    				c.getPA().object(o.objectId, o.objectX, o.objectY, o.face, o.type);
    				c.sendMessage("place Object - ObjectManager");
    			}
    		}
    	}
    	
    	public Object getObject(int x, int y, int height) {
    		for (Object o : objects) {
    			if (o.objectX == x && o.objectY == y && o.height == height)
    				System.out.println("get Object - ObjectManager" + o.height);
    				return o;
    		}	
    		return null;
    	}
    	
    	public void loadObjects(Client c) {
    		if (c == null)
    			return;
    		for (Object o : objects) {
    			if (loadForPlayer(o,c))
    				c.getPA().object(o.objectId, o.objectX, o.objectY, o.face, o.type);
    				c.sendMessage("load Object - ObjectManager");
    		}
    		loadCustomSpawns(c);
    		if (c.distanceToPoint(2813, 3463) <= 60) {
    			c.getFarming().updateHerbPatch();
    		}
    	}
    	
    	private int[][] customObjects = {{}};
    	public void loadCustomSpawns(Client c) {
    	
    c.getPA().checkObjectSpawn(-1, 3090, 3503, 1, 10);	// new funpk
    c.getPA().checkObjectSpawn(-1, 3304, 3111, 1, 10); // funpk cactus
    
    	 if (c.heightLevel == 0) {
    			c.getPA().checkObjectSpawn(2492, 2911, 3614, 1, 10);
    		 }else{
    			c.getPA().checkObjectSpawn(-1, 2911, 3614, 1, 10);
    	}
    	}
    	
    	public final int IN_USE_ID = 14825;
    	public boolean isObelisk(int id) {
    		for (int j = 0; j < obeliskIds.length; j++) {
    			if (obeliskIds[j] == id)
    				return true;
    		}
    		return false;
    	}
    	public int[] obeliskIds = {14829,14830,14827,14828,14826,14831};
    	public int[][] obeliskCoords = {{3154,3618},{3225,3665},{3033,3730},{3104,3792},{2978,3864},{3305,3914}};
    	public boolean[] activated = {false,false,false,false,false,false};
    	
    	public void startObelisk(int obeliskId) {
    		int index = getObeliskIndex(obeliskId);
    		if (index >= 0) {
    			if (!activated[index]) {
    				activated[index] = true;
    				addObject(new Object(14825, obeliskCoords[index][0], obeliskCoords[index][1], 0, -1, 10, obeliskId,16));
    				addObject(new Object(14825, obeliskCoords[index][0] + 4, obeliskCoords[index][1], 0, -1, 10, obeliskId,16));
    				addObject(new Object(14825, obeliskCoords[index][0], obeliskCoords[index][1] + 4, 0, -1, 10, obeliskId,16));
    				addObject(new Object(14825, obeliskCoords[index][0] + 4, obeliskCoords[index][1] + 4, 0, -1, 10, obeliskId,16));
    			}
    		}	
    	}
    	
    	public int getObeliskIndex(int id) {
    		for (int j = 0; j < obeliskIds.length; j++) {
    			if (obeliskIds[j] == id)
    				return j;
    		}
    		return -1;
    	}
    	
    	public void teleportObelisk(int port) {
    		int random = Misc.random(5);
    		while (random == port) {
    			random = Misc.random(5);
    		}
    		for (int j = 0; j < Server.playerHandler.players.length; j++) {
    			if (Server.playerHandler.players[j] != null) {
    				Client c = (Client)Server.playerHandler.players[j];
    				int xOffset = c.absX - obeliskCoords[port][0];
    				int yOffset = c.absY - obeliskCoords[port][1];
    				if (c.goodDistance(c.getX(), c.getY(), obeliskCoords[port][0] + 2, obeliskCoords[port][1] + 2, 1)) {
    					c.getPA().startTeleport2(obeliskCoords[random][0] + xOffset, obeliskCoords[random][1] + yOffset, 0);
    				}
    			}		
    		}
    	}
    	
    	public boolean loadForPlayer(Object o, Client c) {
    		if (o == null || c == null)
    			return false;
    		return c.distanceToPoint(o.objectX, o.objectY) <= 60 && c.heightLevel == o.height;
    	}
    	
    	public void addObject(Object o) {
    		if (getObject(o.objectX, o.objectY, o.height) == null) {
    			objects.add(o);
    			placeObject(o);
    		}	
    	}
    
    
    
    
    }
    as you can see, i've been playing around with it a bit.
    to spawn new objects i use
    Code:
    new Object(objectId, x, y, z, orientation, newobjectId, objecttype, ticks);
    and i put 0 for ticks
    Reply With Quote  
     

  2. #2  
    Registered Member Aleksandr's Avatar
    Join Date
    Sep 2006
    Age
    30
    Posts
    1,027
    Thanks given
    450
    Thanks received
    131
    Discord
    View profile
    Rep Power
    53
    I found out that this piece of code isn't working the way i want it to
    public boolean loadForPlayer(Object o, Client c) {
    if (o == null || c == null)
    return false;
    return c.distanceToPoint(o.objectX, o.objectY) <= 60 && c.heightLevel == o.height;
    }
    so I changed it up like this:
    public boolean loadForPlayer(Object o, Client c) {
    if (o == null || c == null)
    return false;
    if (c.heightLevel != o.height)
    return false;
    return c.distanceToPoint(o.objectX, o.objectY) <= 60 && c.heightLevel == o.height;
    }
    but it's still not helping much, there are still ways to dupe the flag o.O
    Reply With Quote  
     

  3. #3  
    Respected Member

    Join Date
    Jan 2009
    Posts
    5,682
    Thanks given
    1,093
    Thanks received
    3,494
    Discord
    View profile
    Rep Power
    5000
    if you spawn the item at top floor and go down a floor is it there?
    Reply With Quote  
     

  4. #4  
    Registered Member Aleksandr's Avatar
    Join Date
    Sep 2006
    Age
    30
    Posts
    1,027
    Thanks given
    450
    Thanks received
    131
    Discord
    View profile
    Rep Power
    53
    EDIT: no. with my latest ObjectManager it doesn't spawn the objects on other floors anymore, it doesn't spawn the object at all actually(if you are on the wrong floor), unless the loadForPlayer method works right.

    right now my only problem is, making the loadObjects(c); work when the player reaches the correct height. loadForPlayer(o,c) isn't really working right, i'm not understanding this part here: return c.distanceToPoint(o.objectX, o.objectY) <= 60 && c.heightLevel == o.height;

    it's a bit difficult to talk here, if only we can chat.

    Also, i would like to show you what i mean.
    Reply With Quote  
     

  5. #5  
    Respected Member

    Join Date
    Jan 2009
    Posts
    5,682
    Thanks given
    1,093
    Thanks received
    3,494
    Discord
    View profile
    Rep Power
    5000
    that just means

    player in range of object and height is the same display....
    Reply With Quote  
     

  6. #6  
    Registered Member Aleksandr's Avatar
    Join Date
    Sep 2006
    Age
    30
    Posts
    1,027
    Thanks given
    450
    Thanks received
    131
    Discord
    View profile
    Rep Power
    53
    Quote Originally Posted by thispixel View Post
    that just means

    player in range of object and height is the same display....
    um, not really understanding you there...

    EDIT: even if i get to the correct height this code if (loadForPlayer(o,c)) will return false, (if i'm already near the object but on diff height)
    Reply With Quote  
     

  7. #7  
    Respected Member

    Join Date
    Jan 2009
    Posts
    5,682
    Thanks given
    1,093
    Thanks received
    3,494
    Discord
    View profile
    Rep Power
    5000
    [Only registered and activated users can see links. ] ill try help you out
    Reply With Quote  
     

  8. Thankful user:


  9. #8  
    Registered Member Aleksandr's Avatar
    Join Date
    Sep 2006
    Age
    30
    Posts
    1,027
    Thanks given
    450
    Thanks received
    131
    Discord
    View profile
    Rep Power
    53
    I added you, but your not online
    Reply With Quote  
     

  10. #9  
    Registered Member Aleksandr's Avatar
    Join Date
    Sep 2006
    Age
    30
    Posts
    1,027
    Thanks given
    450
    Thanks received
    131
    Discord
    View profile
    Rep Power
    53
    Bump
    Reply With Quote  
     

  11. #10  
    Registered Member
    Join Date
    Nov 2010
    Posts
    52
    Thanks given
    5
    Thanks received
    2
    Rep Power
    26
    I didn't read it all, but I am assuming that it checks distance on walk packet? If so, that's not the greatest way to do it, as 99% of the time, there will be no object to load, so the checking will just be payload.
    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. Object Height on object() void
    By Aleksandr in forum Help
    Replies: 33
    Last Post: 12-02-2013, 05:00 AM
  2. [PI] Removing object from height 1[$10]
    By Ninja assassin in forum Help
    Replies: 8
    Last Post: 11-04-2010, 12:33 AM
  3. Object coords/height
    By jp09 in forum Help
    Replies: 3
    Last Post: 07-04-2010, 02:18 AM
  4. [Devo 2.7]object height
    By rmb7 in forum Help
    Replies: 2
    Last Post: 10-05-2009, 02:18 PM
  5. Castle Wars object height help for DS
    By Techengage in forum Help
    Replies: 5
    Last Post: 03-22-2009, 07:18 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
  •