[Urgent] Hiding a player within a radius

Discussion in 'Plugin Development' started by kreashenz, Feb 15, 2013.

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

    molenzwiebel

    Oh, and use negative durability for the armor, it will go down but you dont see the bar
     
  2. Offline

    kreashenz

    -_Husky_- and now, it just completely screwed the kit, I get nothing now. :/
     
  3. Offline

    -_Husky_-

    Post code.
     
  4. Offline

    molenzwiebel

    Kreashenz, note that my mehod doesn't use craftbukkit so it is compatible with other versions, if you go with his, you'll need to update after each update of mc.
     
    -_Husky_- likes this.
  5. Offline

    kreashenz

    molenzwiebel -_Husky_- , damn that is true.. That's not good, is there a safer way to do it, like, incorporate your code and Husky's into one code ?
    Code:java
    1. else if (args[0].equalsIgnoreCase("ninja")) {
    2. if (sender instanceof Player) {
    3. if (sender.hasPermission("kkit.ninja")) {
    4. Player player = (Player)sender;
    5. PlayerInventory pi = player.getInventory();
    6. pi.clear();
    7. pi.setArmorContents(null);
    8. Bukkit.getServer().getScheduler().cancelAllTasks();
    9. for (PotionEffect effect : player.getActivePotionEffects()) {
    10. player.removePotionEffect(effect.getType());
    11. }
    12. List<Entity> around = player.getNearbyEntities(30,30,30);
    13. List<Entity> sight = player.getNearbyEntities(50,50,50);
    14. Player s = null;
    15. for(Entity ent : around) {
    16. if(ent instanceof CraftPlayer) {
    17. s = (Player) ent;
    18. s.showPlayer(player);
    19. } else {
    20. for(Entity entt : sight) {
    21. s = (Player) entt;
    22. s.hidePlayer(player);
    23. }
    24. }
    25. ItemStack gethelmet = new ItemStack(Material.GOLD_HELMET, 64);
    26. gethelmet.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
    27. ItemStack getchestplate = new ItemStack(Material.GOLD_CHESTPLATE, 64);
    28. getchestplate.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
    29. ItemStack getleggings = new ItemStack(Material.GOLD_LEGGINGS, 64);
    30. getleggings.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
    31. ItemStack getboots = new ItemStack(Material.GOLD_BOOTS, 64);
    32. getboots.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
    33. getboots.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, 9);
    34. ItemStack getsword = new ItemStack(Material.IRON_SWORD);
    35. getsword.addEnchantment(Enchantment.DAMAGE_ALL, 1);
    36. ItemMeta iSword = (ItemMeta)getsword.getItemMeta();
    37. iSword.setDisplayName("Sharpened Knife");
    38. getsword.setItemMeta(iSword);
    39. pi.setHelmet(gethelmet);
    40. pi.setChestplate(getchestplate);
    41. pi.setLeggings(getleggings);
    42. pi.setBoots(getboots);
    43. pi.addItem(getsword);
    44. ItemStack getSoup = new ItemStack(Material.MUSHROOM_SOUP, 1);
    45. player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 18000, 0));
    46. player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 2400000, 4));
    47. for(int i=1; i <=34; i++)
    48. pi.addItem(getSoup);
    49. sender.sendMessage(prefix + Ninja);
    50. }
    51. } else sender.sendMessage(prefix + MustBePlayer);
    52. } else sender.sendMessage(prefix + NoPerm);
    53. }
     
  6. Offline

    -_Husky_-

    I am 90% certain I left out a }

    I am coding on an iPad, forgive me.
    Go with his version, I wont have access to a computer for awhile, now I sleep, goodnight.
     
  7. Offline

    molenzwiebel

    Boh of our versions aren't that good as they both loop through all entities/players. I think there is no way to get getNearbyEntities() to return players, so try fooling around with both Husky's and mine

    And, i'm coding on a iPhone :p

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

    kreashenz

    Arggh, you's and your stupid iOS devices xD

    Bump, help with the second page now :) I don't know where to put the code in my kit.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
    -_Husky_- likes this.
  9. Offline

    molenzwiebel

    Put it in a scheduler and change the code a bit:
    Code:java
    1.  
    2. for (Player p1 : Bukkit.getOnlinePlayers()) {
    3. if(!p1.isninja) continue;
    4. for (Player p2 : Bukkit.getOnlinePlayers()) {
    5. if (p1.getLocation().distance(p2.getLocation()) > radius) {
    6. p2.hidePlayer(p1);
    7. } else {
    8. p2.showPlayer(p1);
    9. }
    10. }
    11. }
    12.  


    Something like that
     
    -_Husky_- likes this.
  10. Offline

    kreashenz

    molenzwiebel What do I put in the Ninja Class for if(!p1.isninja) continue; ? Do I need to set a isNinja boolean?
     
  11. Offline

    -_Husky_-

    Hold on 10-20 mins, I will get on the computer and send some code.

    Code:java
    1. else if (args[0].equalsIgnoreCase("ninja")) {
    2. if (sender instanceof Player) {
    3. if (sender.hasPermission("kkit.ninja")) {
    4. Player player = (Player)sender;
    5. PlayerInventory pi = player.getInventory();
    6. pi.clear();
    7. pi.setArmorContents(null);
    8. Bukkit.getServer().getScheduler().cancelAllTasks();
    9. for (PotionEffect effect : player.getActivePotionEffects()) {
    10. player.removePotionEffect(effect.getType());
    11. }
    12. List<Entity> around = player.getNearbyEntities(30,30,30);
    13. List<Entity> sight = player.getNearbyEntities(50,50,50);
    14. Player s = null;
    15. for(Entity ent : around) {
    16. if(ent instanceof CraftPlayer) {
    17. s = (Player) ent;
    18. s.showPlayer(player);
    19. } else {
    20. for(Entity entt : sight) {
    21. s = (Player) entt;
    22. s.hidePlayer(player);
    23. }
    24. }
    25. }
    26. ItemStack gethelmet = new ItemStack(Material.GOLD_HELMET, 64);
    27. gethelmet.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
    28. ItemStack getchestplate = new ItemStack(Material.GOLD_CHESTPLATE, 64);
    29. getchestplate.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
    30. ItemStack getleggings = new ItemStack(Material.GOLD_LEGGINGS, 64);
    31. getleggings.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
    32. ItemStack getboots = new ItemStack(Material.GOLD_BOOTS, 64);
    33. getboots.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
    34. getboots.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, 9);
    35. ItemStack getsword = new ItemStack(Material.IRON_SWORD);
    36. getsword.addEnchantment(Enchantment.DAMAGE_ALL, 1);
    37. ItemMeta iSword = (ItemMeta)getsword.getItemMeta();
    38. iSword.setDisplayName("Sharpened Knife");
    39. getsword.setItemMeta(iSword);
    40. pi.setHelmet(gethelmet);
    41. pi.setChestplate(getchestplate);
    42. pi.setLeggings(getleggings);
    43. pi.setBoots(getboots);
    44. pi.addItem(getsword);
    45. ItemStack getSoup = new ItemStack(Material.MUSHROOM_SOUP, 1);
    46. player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 18000, 0));
    47. player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 2400000, 4));
    48. for(int i=1; i <=34; i++)
    49. pi.addItem(getSoup);
    50. sender.sendMessage(prefix + Ninja);
    51. }
    52. } else sender.sendMessage(prefix + MustBePlayer);
    53. } else sender.sendMessage(prefix + NoPerm);


    Sorted.

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

    kreashenz

    -_Husky_- This is still not working.. I actually got no idea.
     
  13. Offline

    -_Husky_-

    Not working, Let me test. :)
     
  14. Looks like you're overcomplicating things a lot.
    What are you trying to do?
     
  15. Offline

    kreashenz

    AlexLeporiday Just trying to hide the player, if they get out of the radius.. ( In this case its 50 blocks )..
     
  16. Offline

    -_Husky_-

    Code:
    List<Entity> around = player.getNearbyEntities(30,30,30);
    List<Entity> sight = player.getNearbyEntities(50,50,50);
    Player s = null;
    for(Entity ent : around) {
    if(ent instanceof CraftPlayer) {
    s = (Player) ent;
    s.showPlayer(player);
    } else {
    for(Entity entt : sight) {
    if(entt instanceof CraftPlayer) {
    s = (Player) entt;
    s.hidePlayer(player);
    }
    }
    }
    }
    Is all that needs to be added. I tested and it works. :eek:
     
  17. Offline

    kreashenz

    -_Husky_- What about changing the sight around to 1, would that change anything?
     
  18. Code:
    public static void playerVisablity(Player player, int visability) {
        List<Entity> entitiesNear = player.getNearbyEntities(visability,visability,visability);
        for(Player onlinePlayer : Bukkit.getServer().getOnlinePlayers()) {
            if(entitiesNear.contains(onlinePlayer)) onlinePlayer.showPlayer(player);
            else if(onlinePlayer.canSee(player)) onlinePlayer.hidePlayer(player);
        }
    }
    This method takes a player and a range in blocks that they should be visible. Any player inside the visibility range will be able to see the player, any player outside this range will not be able to see the player.

    For this to work smoothly you'd want to call this method every time the player moves. If you call it whenever a player moves then there could be an issue when you don't move and a player walks towards you. You'll be able to see them but they won't be able to see you. So, think carefully how you might want to adapt this method to fit your purpose.
     
    molenzwiebel likes this.
  19. Offline

    molenzwiebel

    AlexLeporiday Put it in a scheduler, it works better for this and the player move event is called far too many times per tick. I repeat, don't put it in the player move event! getNearbyEntities() is not the fastest funtion and the move event get's called A LOT of times per tick, this causes a lot of lag on big servers
     
    AlexLeporiday likes this.
  20. This is a much better idea but it depends how often you run the task.
     
  21. Offline

    molenzwiebel

    Even a scheduler that is called once per tick is called less than the PlayerMoveEvent. I recommend something like 5 or 10 ticks delay.

    It was just a placeholder, put something there to determine if the player needs to be invisible.

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

    kreashenz

    molenzwiebel so, I'm just lost, how do I assign a schedule to PlayerMoveEvent..?
     
  23. Offline

    molenzwiebel

    Code:java
    1.  
    2. public int startInvisiTimer() {
    3. return Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this.plugin, new Runnable() {
    4. public void run() {
    5. for (Player player : Bukkit.getServer().getOnlinePlayers()) {
    6. List<Entity> entitiesNear = player.getNearbyEntities(visability,visability,visability);
    7. for(Player onlinePlayer : Bukkit.getServer().getOnlinePlayers()) {
    8. if(entitiesNear.contains(onlinePlayer)) onlinePlayer.showPlayer(player);
    9. else if(onlinePlayer.canSee(player)) onlinePlayer.hidePlayer(player);
    10. }
    11. }
    12. }
    13. }, 0L, 5L);
    14. }
    15. public void stopInvisiTimer(int id) {
    16. Bukkit.getServer().getScheduler().cancelTask(id);
    17. }
    18.  


    Something like that, dont expect it to work
    Start timer returns a id that you can use to stop it. I'll be home in 1.5 hours and help you furher then.
     
Thread Status:
Not open for further replies.

Share This Page