Solved How would I check if...

Discussion in 'Plugin Development' started by blok601, Jun 9, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    blok601

    How would I check if a player is inside or touching a cobweb, and then apply damage to the player. I am kind of new to this, but I do understand code. I just have no idea where to start. Thanks in advance!
    -blok601
     
  2. Offline

    Konato_K

  3. Offline

    TheDiamond06

    What if the player doesn't move inside of the cobweb?

    @blok601
    You could have a repeating task every 10 ticks or something that loops through all the players and checks if their location contains a cobweb.
     
  4. @blok601
    When a player is touching a cobweb their movement speed is greatly reduce so you can probably quickly eliminate players with normal walk speed. And then double check if a player with low movement speed is touching a cobweb by scanning all blocks within a 1 block radius of the player to see if it contains a cobweb.
     
  5. Offline

    blok601

    Thanks!I know this is a bad question, but how would you scan the blocks with a 1 block radius? Sorry about that, I am not good at this, but it will be nice to learn.
     
  6. Offline

    CraftBang

    @blok601
    http://bukkit.org/threads/square-creating.307356/#post-2773146
    Code from there:
    Code:
    for(int x = (int) player.getLocation().getX() - 10; x <= (int) player.getLocation().getX() + 10; x++) {
         for(int y = (int) player.getLocation().getY() - 10; y <= (int) player.getLocation().getY() + 10; y++) {
              for(int z = (int) player.getLocation().getZ() - 10; z <= (int) player.getLocation().getZ() + 10; z++) {
                   player.getWorld().getBlockAt(x, y, z).setType(Material.AIR);
              }
         }
    }
    I guess replace all 10's with 1 ?
     
  7. Offline

    blok601

    Well, I went back to that thread, and all this does is make a wall around the player.
     
  8. Offline

    CraftBang

    @blok601

    My bad..
    But just replace
    Code:
    player.getWorld().getBlockAt(x, y, z).setType(Material.AIR);
    with if(player.getWorld().getBlockAt(x, y, z).getType() == Material.COB_WEB /*< NOT SURE ABOUT COBWEB*/){
    //do something here because he is in a cobweb
    }
     
  9. @CraftBang The problem with that method would be that it would damage players if they're near cobweb, not just if they're in cobweb.
     
  10. Offline

    blok601

    Would you just do a repeating task?
     
  11. Offline

    blok601

    Maybe ?
     
  12. Offline

    JBoss925

    Get the block at the location of the player and if it's a cobweb, damage said player. I would personally use a runnable.
     
  13. Offline

    blok601

    Sorry, I am sortve a noob. I know how to use a runnable and all, but how would I check the block at the player's location.
     
  14. player.getLocation().getBlock()
     
  15. Offline

    JBoss925

    player.getLocation().getBlock().getType() == Material.COBWEB
     
  16. Offline

    blok601

    So I am using a syncRepeatingTask in the onEnable. Am I correct?
     
  17. Make a new class:
    Code:
    public class TestCobweb extends BukkitRunnable {
        public static List<Player> inCobweb = new ArrayList<Player>();
       
        @Override
        public void run() {
            for(Player p : Bukkit.getOnlinePlayers()) {
                if(p.getLocation().getBlock().getType()==Material.COBWEB) {
                    if(!inCobweb.contains(p)) inCobweb.add(p);
                }else{
                    if(inCobweb.contains(p)) inCobweb.remove(p);
                }
            }
        }
    }
    And put this in your main class:
    Code:
    @Override
    public void onEnable() {
      new TestCobweb().runTaskTimer(this, 1, 1);
    }
     
  18. Offline

    blok601

    I really didn't think of that, thanks! I want to damage the player, so would I just do player.damage(5) under the p.getLocation?
     
  19. Offline

    SuperSniper

    Yes
     
  20. Well, if you use that, each tick (there are 20 ticks in a second) will the player get 2,5 hearts damage, so then just change
    new TestCobweb().runTaskTimer(this, 1, 1); to new TestCobweb().runTaskTimer(this, 20, 20); to damage it 2,5 hearts every second
     
  21. Offline

    blok601

    Alright, trying it out right now. Thanks for the help everyone!
     
Thread Status:
Not open for further replies.

Share This Page