Get cause of death

Discussion in 'Plugin Development' started by slater96, Jul 25, 2012.

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

    slater96

    I'm trying to get the cause of deaths for thing's like if players get killed by tnt, zombies, cactus, lava, fire etc...
    I've tried using the getEntityId, but it didn't seem to work. Anyone know how I can do this?
     
  2. Offline

    slater96

  3. That doesn't matter. The important part is this:
     
  4. Offline

    slater96

    Ok thanks, i've put it in player death now and it works fine. Does anyone know how to get the block for suffocation so I can see whether it's sand or gravel?
     
  5. Maybe something like player.getEyeLocation().getBlock();
     
  6. Offline

    slater96

    Yeah that sorta worked, I did
    p.getEyeLocation().getBlock().getType().toString().toUpperCase()
    But it's not always accurate :(

    Anyone know any other way to see if the suffocation block is sand or gravel?

    Also I am also trying to stop people suffocating when they spawn randomly within a radius, do you know any way I can make it so that when a player teleports to that location and damage cause is suffocation, that it teleports them again or up. Thanks

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  7. Offline

    WarmakerT

    You can do that on the server.properties file
     
  8. Offline

    Firefly

    world.getHighestBlockYAt(location) Should avoid suffocation.. no?
     
  9. Offline

    slater96

    I couldn't seem to get that to work with my code :(
    Here it is:
    Code:
    plugin.getConfig().getString("Spawn_FreeForAll");
                            String[] spawnfreeforall = plugin.getConfig().getString("Spawn_FreeForAll.Loc").split(",");
                            double x = Double.parseDouble(spawnfreeforall[0]);
                            double y = Double.parseDouble(spawnfreeforall[1]);
                            double z = Double.parseDouble(spawnfreeforall[2]);
                            String newWorld = plugin.getConfig().getString("Spawn_FreeForAll.World");
                            String yaw = plugin.getConfig().getString("Spawn_FreeForAll.Yaw");
                            float yaw2 = Float.parseFloat(yaw);
                            String pitch = plugin.getConfig().getString("Spawn_FreeForAll.Pitch");
                            float pitch2 = Float.parseFloat(pitch);
                            Location freeforall = new Location(p.getServer().getWorld(newWorld), x, y, z, yaw2, pitch2);
                            double radius = plugin.getConfig().getInt("FreeForAllRadius");
                            freeforall.add((2*Math.random() - 1)*radius, 0.0, (2*Math.random() - 1)*radius);
                            p.teleport(freeforall);
                            plugin.FreeForAll.add(p);
    I think i tried newWorld.getHighestBlockAt(freeforall) but can't remember.
     
  10. Offline

    Firefly

    String pitch = plugin.getConfig().getString("Spawn_FreeForAll.Pitch");

    Why not just:

    Float pitch = plugin.getConfig().getFloat("Spawn_FreeForAll.Pitch");
     
  11. Offline

    slater96

    Yeah lol, I don't know why I did that either :p
     
  12. Code:java
    1. Material mat = p.getEyeLocation().getBlock().getType();
    2. if(mat == Material.SAND)
    3. {
    4. //Sand!
    5. p.sendMessage("You died building a sand castle");
    6. }
    7. else if(mat == Material.GRAVEL)
    8. {
    9. //Gravel!
    10. p.sendMessage("Gravel killed you!");
    11. }
    12. else
    13. {
    14. //Something other...
    15. String m = mat.toString().toLowerCase().replaceAll("_", " ");
    16. p.sendMessage(m+" killed you!");
    17. }

    I don't know if you could suffocate if only your lower bods parts stuck in a block, but if so maybe do the same with p.getLocation();
     
    slater96 likes this.
  13. I did that, you won't suffocate.
     
  14. Offline

    slater96

    I'm trying to change all my code like you said but it appears there's no getFloat()?
    There is float list however so is that what I use?
     
  15. Offline

    bartboy8

    p.getLocation.getY()+1;
    that should get the block at their head then do if that block equals sand or gravel print what you like!
     
  16. I don't know why there's a getFloatList() but not a getFloat()... but I guess you can use getDouble() instead.

    Or just use player.getEyeLocation().
     
    V10lator likes this.
Thread Status:
Not open for further replies.

Share This Page