Thread: Getting player location in a loop

Results 1 to 4 of 4
  1. #1 Getting player location in a loop 
    Donator

    Join Date
    Jan 2014
    Posts
    87
    Thanks given
    22
    Thanks received
    10
    Rep Power
    36
    I'm currently working on zalcano's falling rock attack, and I've got most of it working however. I need to define the coordinates of the players that are being hit:

    Code:
    CycleEvent event = new CycleEvent() {
    				int rockTick = 0;
    				@Override
    				public void execute(CycleEventContainer container) {
    					Misc.shuffle(targets)
    					.stream()
    					.limit(20)
    					.forEach(plr -> {
    						System.err.println(rockTick);
    						
    						final Location locs = plr.getLocation();
    						
    						if (rockTick == 1) {
    							plr.asPlayer().getPA().createPlayersStillGfx(1727, plr.getX(), plr.getY(), 0, 0);
    						}
    						if (rockTick == 6) {
    							if (plr.getLocation().equalsIgnoreHeight(locs)) {
    								plr.appendDamage(Misc.random(1, 2), Hitmark.HIT);
    							}
    						}
    					});
    					if (rockTick >= 8) {
    						container.stop();
    					}
    					//container.setTick(1);
    					rockTick++;
    				}
    			};
    What I colored out should take the players coordinate, however since we're looping their coordinates keep changing and thus players keep getting hit.
    I've tried this:

    Code:
    CycleEvent event = new CycleEvent() {
    				int rockTick = 0;
    				@Override
    				public void execute(CycleEventContainer container) {
    					Misc.shuffle(targets)
    					.stream()
    					.limit(20)
    					.forEach(plr -> {
    						System.err.println(rockTick);
    						
                                                    if (rockTick == 1) {
    						             final Location locs = plr.getLocation();
    						}
    						if (rockTick == 2) {
    							plr.asPlayer().getPA().createPlayersStillGfx(1727, plr.getX(), plr.getY(), 0, 0);
    						}
    						if (rockTick == 6) {
    							if (plr.getLocation().equalsIgnoreHeight(locs)) {
    								plr.appendDamage(Misc.random(1, 2), Hitmark.HIT);
    							}
    						}
    					});
    					if (rockTick >= 8) {
    						container.stop();
    					}
    					//container.setTick(1);
    					rockTick++;
    				}
    			};
    But I cannot open that final on tick 6 and it's now allowing me to make it public

    I've been trial & erroring for over 4 hours now with no luck.

    Also I can grab their location before the cycle event, however that will only grab the location of the NPC's target and not all the players that are gonna get hit resulting in everyone getting hit or no one getting hit (Depending if the actual targets stepping away or not)
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  2. #2  
    Registered Member
    hc747's Avatar
    Join Date
    Dec 2013
    Age
    23
    Posts
    1,448
    Thanks given
    3,133
    Thanks received
    672
    Discord
    View profile
    Rep Power
    1029
    Something along these lines; note that this is somewhat pseudo code. Don't store the players actual location, otherwise it'll point to their current location, as opposed to where they were standing.
    Code:
    CycleEvent event = new CycleEvent() {
     private int tick = 0;
     private List <Location> locations = null;
    
    
     @Override
     public void execute(CycleEventContainer container) {
      if (tick == 1) {
       locations = Misc.shuffle(targets).stream().limit(20).map(target -> target.getLocation().copy());
      } else if (tick == 2) {
       //create graphics for each location
      } else if (tick == 6) {
       //for each player, if they're standing in one of the locations, append damage
      } else if (tick >= 8) {
       container.stop(); //why not stop after tick 6???
      }
      tick++;
     }
    };
    [Only registered and activated users can see links. ]
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  3. Thankful users:


  4. #3  
    Donator

    Join Date
    Jan 2014
    Posts
    87
    Thanks given
    22
    Thanks received
    10
    Rep Power
    36
    Quote Originally Posted by hc747 View Post
    Something along these lines; note that this is somewhat pseudo code. Don't store the players actual location, otherwise it'll point to their current location, as opposed to where they were standing.
    Code:
    CycleEvent event = new CycleEvent() {
     private int tick = 0;
     private List <Location> locations = null;
    
    
     @Override
     public void execute(CycleEventContainer container) {
      if (tick == 1) {
       locations = Misc.shuffle(targets).stream().limit(20).map(target -> target.getLocation().copy());
      } else if (tick == 2) {
       //create graphics for each location
      } else if (tick == 6) {
       //for each player, if they're standing in one of the locations, append damage
      } else if (tick >= 8) {
       container.stop(); //why not stop after tick 6???
      }
      tick++;
     }
    };
    First of all thanks for the reply.

    I'm getting a bit confused on the part where you say don't store players locations as they will change. On the first cycle your returning the targets locations. I'm unsure where it stores this and how I would check the players location individually and the players location at cycle 6 to check wether or not to apply damage.

    Sorry for the nooby questions.
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  5. #4  
    Registered Member
    hc747's Avatar
    Join Date
    Dec 2013
    Age
    23
    Posts
    1,448
    Thanks given
    3,133
    Thanks received
    672
    Discord
    View profile
    Rep Power
    1029
    Quote Originally Posted by toMeisteR View Post
    First of all thanks for the reply.

    I'm getting a bit confused on the part where you say don't store players locations as they will change. On the first cycle your returning the targets locations. I'm unsure where it stores this and how I would check the players location individually and the players location at cycle 6 to check wether or not to apply damage.

    Sorry for the nooby questions.
    If the locations are mutable (I assume they are), you're only storing a reference to the players location, which in 6 ticks might change, so instead of targeting their original location, it'll target their current location - hence why you need to copy (and not modify) the original locations. They're being stored in the List of locations declared below the ticks variable, and being populated in tick 1 as opposed to during initialisation (for whatever reason). Iterate over all of the players within the area and see if any of them are at the same location as any of the locations within the list. GL.
    [Only registered and activated users can see links. ]
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  6. Thankful user:



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. Get player amount in certain Areas?
    By Chaos105 in forum Help
    Replies: 4
    Last Post: 04-03-2015, 02:45 AM
  2. Replies: 12
    Last Post: 06-22-2010, 10:41 PM
  3. Getting player count in a certain area?
    By Underoath in forum Requests
    Replies: 8
    Last Post: 11-20-2009, 08:19 PM
  4. Replies: 1
    Last Post: 01-21-2009, 03:34 PM
  5. Replies: 1
    Last Post: 11-01-2008, 10:19 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
  •