Thread: Pi Global Drops double drops each time

Results 1 to 4 of 4
  1. #1 Pi Global Drops double drops each time 
    Owner of Ghreborn new and old.


    Join Date
    Nov 2009
    Posts
    916
    Thanks given
    47
    Thanks received
    155
    Rep Power
    273
    so i used this https://www.rune-server.org/runescap...s-handler.html and edited the eventhandler for the one i use and now its double each one ones is able to picked up and the other is not heres my class file
    Code:
    package server.model.content;
    
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.util.ArrayList;
    import java.util.List;
    
    import server.Config;
    import server.Server;
    import server.core.PlayerHandler;
    import server.event.CycleEvent;
    import server.event.CycleEventContainer;
    import server.event.Event;
    import server.event.EventContainer;
    import server.event.EventManager;
    import server.model.players.Client;
    import server.util.Misc;
    
    /**
     * Handles global drops which respawn after set amount of time when taken
     * @author Stuart <RogueX>
     *
     */
    public class GlobalDropsHandler {
    	
    	/**
    	 * time in seconds it takes for the item to respawn
    	 */
    	private static final int TIME_TO_RESPAWN = 60;
    	
    	/**
    	 * holds all the objects
    	 */
    	private static List<GlobalDrop> globalDrops = new ArrayList<GlobalDrop>();
    	
    	/**
    	 * loads the items
    	 */
    	public static void initialize() {
    		String Data;
    		BufferedReader Checker = null;
    		try {
    			Checker = new BufferedReader(new FileReader("./Data/cfg/globaldrops.txt"));
    			while ((Data = Checker.readLine()) != null) {
    				if (Data.startsWith("#"))
    					continue;
    				String[] args = Data.split(":");
    				globalDrops.add(new GlobalDrop(Integer.parseInt(args[0]), Integer.parseInt(args[1]), Integer.parseInt(args[2]), Integer.parseInt(args[3])));
    			}
    			Checker.close();
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    		Misc.println("Loaded " + globalDrops.size() + " global drops.");
    		EventManager.getSingleton().addEvent(new Event() {
    
    			@Override
    			public void execute(EventContainer container) {
    				for(GlobalDrop drop : globalDrops) {
    					if(drop.isTaken()) {
    						if((System.currentTimeMillis() - drop.getTakenAt()) >= (TIME_TO_RESPAWN * 1000)) {
    							drop.setTaken(false);
    							for(int i = 0; i < Config.MAX_PLAYERS; i++) {
    								Client client = (Client)PlayerHandler.players[i];
    								if(client != null) {
    									if(client.distanceToPoint(drop.getX(), drop.getY()) <= 60) {
    										client.getItems().createGroundItem(drop.getId(), drop.getX(), drop.getY(), drop.getAmount());
    									}
    								}
    							}
    						}
    					}
    				}
    			}
    			
    		}, 1);
    	}
    	
    	/**
    	 * See if a drop exists at the given place
    	 * @param a item id
    	 * @param b x cord
    	 * @param c y cord
    	 * @return
    	 */
    	private static GlobalDrop itemExists(int a, int b, int c) {
    		for(GlobalDrop drop : globalDrops) {
    			if(drop.getId() == a && drop.getX() == b && drop.getY() == c) {
    				return drop;
    			}
    		}
    		return null;
    	}
    	
    	/**
    	 * Pick up an item at the given location
    	 * @param a item id
    	 * @param b cord x
    	 * @param c cord y
    	 */
    	public static void pickup(Client client, int a, int b, int c) {
    		GlobalDrop drop = itemExists(a, b, c);
    		if(drop == null) {
    			return;
    		}
    		if(drop.isTaken()) {
    			return;
    		}
    		drop.setTakenAt(System.currentTimeMillis());
    		drop.setTaken(true);
    		if(client.getItems().freeSlots() > 0) {
    			client.getItems().addItem(drop.getId(), drop.getAmount());
    		}
    		//TODO use the region manager for this... 
    		for(int i = 0; i < Config.MAX_PLAYERS; i++) {
    			Client cl = (Client)PlayerHandler.players[i];
    			if(cl != null) {
    				if(cl.distanceToPoint(drop.getX(), drop.getY()) <= 60) {
    					cl.getItems().removeGroundItem(drop.getId(), drop.getX(), drop.getY(), drop.getAmount());
    				}
    			}
    		}
    	}
    	
    	/**
    	 * Loads all the items when a player changes region
    	 */
    	public static void load(Client client) {
    		for(GlobalDrop drop : globalDrops) {
    			if(!drop.isTaken()) {
    				if(client.distanceToPoint(drop.getX(), drop.getY()) <= 60) {
    					client.getItems().createGroundItem(drop.getId(), drop.getX(), drop.getY(), drop.getAmount());
    				}
    			}
    		}
    	}
    	
    	/**
    	 * Holds each drops data
    	 * @author Stuart
    	 *
    	 */
    	static class GlobalDrop {
    		/**
    		 * cord x
    		 */
    		int x;
    		/** 
    		 * cord y
    		 */
    		int y;
    		/**
    		 * item id
    		 */
    		int id;
    		/**
    		 * item amount
    		 */
    		int amount;
    		/**
    		 * has the item been taken
    		 */
    		boolean taken = false;
    		/**
    		 * Time it was taken at
    		 */
    		long takenAt;
    		
    		/**
    		 * Sets the drop arguments
    		 * @param a item id
    		 * @param b item amount
    		 * @param c cord x
    		 * @param d cord y
    		 */
    		public GlobalDrop(int a, int b, int c, int d) {
    			this.id = a;
    			this.amount = b;
    			this.x = c;
    			this.y = d;
    		}
    		
    		/**
    		 * get cord x
    		 * @return
    		 */
    		public int getX() {
    			return this.x;
    		}
    		
    		/**
    		 * get cord x
    		 * @return
    		 */
    		public int getY() {
    			return this.y;
    		}
    		
    		/**
    		 * get the item id
    		 * @return
    		 */
    		public int getId() {
    			return this.id;
    		}
    		
    		/**
    		 * get the item amount
    		 * @return
    		 */
    		public int getAmount() {
    			return this.amount;
    		}
    		
    		/**
    		 * has the drop already been taken?
    		 * @return
    		 */
    		public boolean isTaken() {
    			return this.taken;
    		}
    		
    		/**
    		 * set if or not the drop has been taken
    		 * @param a true yes false no
    		 */
    		public void setTaken(boolean a) {
    			this.taken = a;
    		}
    		
    		/**
    		 * set the time it was picked up
    		 * @param a
    		 */
    		public void setTakenAt(long a) {
    			this.takenAt = a;
    		}
    		
    		/**
    		 * get the time it was taken at
    		 * @return
    		 */
    		public long getTakenAt() {
    			return this.takenAt;
    		}
    		
    	}
    	
    }

    any idea how the double of items each time?
    Im back and working on reborn,
    Reply With Quote  
     

  2. #2  
    Officially Retired


    Join Date
    Oct 2007
    Age
    30
    Posts
    5,454
    Thanks given
    558
    Thanks received
    122
    Rep Power
    1364
    Do you check your globaldrops.txt is it double drop inside?
    Reply With Quote  
     

  3. #3  
    Owner of Dawntained

    Mgt Madness's Avatar
    Join Date
    Oct 2011
    Age
    28
    Posts
    3,380
    Thanks given
    1,429
    Thanks received
    958
    Rep Power
    2168
    You gotta add debug prints, when the item is added on the floor, add a debug print under it such as System.out.println(itemId + ", " + itemAmount); etc..
    Attached image
    Reply With Quote  
     

  4. #4  
    Registered Member
    Join Date
    Jul 2015
    Posts
    150
    Thanks given
    0
    Thanks received
    7
    Rep Power
    0
    Some servers offer a double drop event sort of like double exp I doubt it but it's worth a quick glance at the server configs
    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. Replies: 103
    Last Post: 02-26-2019, 10:29 PM
  2. Replies: 14
    Last Post: 06-08-2016, 09:08 PM
  3. Replies: 39
    Last Post: 10-04-2014, 05:42 PM
  4. Replies: 6
    Last Post: 08-10-2012, 12:47 AM
  5. PI double drop
    By Ashley in forum Help
    Replies: 9
    Last Post: 07-24-2012, 11:23 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
  •