Solved Adding more hearts to players?

Discussion in 'Plugin Development' started by Dave_, Jul 10, 2013.

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

    Dave_

    I'm trying to add more hearts to my players but it seems when I do setMaxHealth(); it doesnt do it. Am I missing out on something?

    Code:
            if (players.get(p)){
                System.out.println(p.getInventory().getArmorContents()[0].getTypeId());
                if (p.getInventory().getArmorContents()[0].getTypeId() == 301){
                    p.setMaxHealth(30D);
                    return "Ranger";
                }
                if (p.getInventory().getArmorContents()[0].getTypeId() == 317){
                    return "Medic";
                }
                if (p.getInventory().getArmorContents()[0].getTypeId() == 309){
                    return "Warrior";
                }
            }
            return "Normal Player";
     
  2. Offline

    Jamesthatguy

    Instead of ints use doubles.
     
  3. Offline

    Dave_

    Why would that make any difference? Just incase It does I just tried it and the extra hearts do not show.
     
  4. Offline

    xTrollxDudex

    Dave_
    Read the sticky on ambiguous getHealth(). But you can put in say 10.5D as the argument to make sure it is a double I think
     
  5. Offline

    Dave_

    I did the suggested and still no luck. I still have 10 hearts :/

    Code:
    p.setMaxHealth(12.0D);
     
  6. Offline

    LinearLogic

    A player's default max health is 20.0, so I'd suggest trying something more than that...
     
  7. Offline

    Dave_

    Code:
                if (p.getInventory().getArmorContents()[0].getTypeId() == 301){
                    p.setMaxHealth(22.0D);
                    return "Ranger";
                }
    Still only 10 hearts.
     
  8. Offline

    LinearLogic

    Add a printout line to make sure you're event reaching the p.setMaxHealth(22.oD); line. And if you include a decimal point, there's no need to append the "D", just to make life a bit easier.
     
  9. I haven't read much about how the hearts stuff works but I think it is like this. You can change a players health to anything like 500. But the only way new hearts will show up is by using the new item system that allows items to give a player more health.
     
  10. Offline

    Dave_


    I knew that and yes the event is making it or else it would return "Normal Player", and about the D I just didnt remove it from the 30D its like 2 am haha
     
  11. Offline

    LinearLogic

    Well make sure "Ranger" is being returned. And paste your whole class? How is the Player object retrieved?
     
  12. Offline

    Dave_


    Oh, I thought for sure the bukkit team would add some kind of implementation without the use of items.
     
  13. Offline

    LinearLogic

    Not sure what this talk about the need for items to be involved is... something like this works just fine:
    Code:java
    1. @EventHandler
    2. public void onJoin(PlayerJoinEvent event) {
    3. event.getPlayer().setMaxHealth(40.0);
    4. }
     
  14. Offline

    Dave_


    Code:
        private void updateList(){
            for (Player p : Bukkit.getOnlinePlayers()){
                ItemStack[] armor = p.getInventory().getArmorContents();
                int i = 0;
                for (int num = 0; num < 4; num++){
                    if (armor[num].getTypeId() != 0){
                        if (armor[0].getTypeId() - i == armor[num].getTypeId()){
                            i++;
                        }
                    }
                }
                boolean isClass = checkClassSafely(p);
             
                if (i == 4){
                    players.put(p, true);
                }else{
                    players.put(p, false);
                }
                String name = getType(p);
                if (players.get(p) && !isClass){
                    p.sendMessage(ChatColor.GREEN + "You are a " + ChatColor.WHITE + name);
                }else if (!players.get(p) && isClass){
                    p.sendMessage(ChatColor.RED + "You are now a " + ChatColor.WHITE + name);
                }
            }
        }
     
        public String getType(Player p){
            if (players.get(p)){
                System.out.println(p.getInventory().getArmorContents()[0].getTypeId());
                if (p.getInventory().getArmorContents()[0].getTypeId() == 301){
                    p.setMaxHealth(22.0D);
                    return "Ranger";
                }
                if (p.getInventory().getArmorContents()[0].getTypeId() == 317){
                    return "Medic";
                }
                if (p.getInventory().getArmorContents()[0].getTypeId() == 309){
                    return "Warrior";
                }
            }
            return "Normal Player";
        }
    Proof it calls

    Show Spoiler

    2013-07-11_01.57.31.png
     
  15. LinearLogic Does that actualy show that you have more hearts?

    Dave_ Try printing out the amount of health the player has.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  16. Offline

    Dave_


    Code:
    02:07:11 [INFO] CONSOLE: Reload complete.
    02:07:12 [INFO] Current Health: 20.0
    02:07:12 [INFO] Max Health: 22.0
    But the 2 hearts do not show
     
  17. Offline

    LinearLogic

    BorisTheTerrible: yup. And Dave_, I'm guessing the player you're retrieving is the wrong one, since I compiled your code with "p" retrieved by getServer().getPlayer("LinearLogic") and I got the extra heart.

    EDIT: now that you're printing out the health and max health, trying printing the player's name as well.
     
  18. Offline

    Dave_


    That is strange.

    Code:
    p.sendMessage(ChatColor.GREEN + "You are a " + ChatColor.WHITE + name);
    sends to the correct player.
     
  19. Dave_ This only works as of 1.6 I believe so make sure your trying this on an up to date server.
     
  20. Offline

    LinearLogic

    You're not running a 1.6.2 MC client, are you? 1.6.1 servers support modified max health, but the client won't display the extra hearts.
     
  21. Offline

    Dave_


    oh ,im using the first Bukkit 1.6.1 dev build, maybe i should update it, ill post back if it isn't working yet.
     
  22. Offline

    NoLiver92

    You can not 'add more hearts' to the gui from the server it would require a modified client. you can change the health but it will be adjusted to 10 visible hearts.
     
  23. Offline

    Dave_

    LinearLogic BorisTheTerrible Thanks guys, outdated bukkit build ;)


    yes you can as of MC 1.6

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  24. Offline

    LinearLogic

    Thanks to the awesomeness of the Mojang team, that is no longer true. Try it out for yourself!
     
  25. Offline

    NoLiver92

    how did you do it?
     
  26. Offline

    LinearLogic

    NoLiver92, just alter the player's max health with player.setMaxHealth(someDouble) and your client does the rest!
     
  27. Offline

    NoLiver92

Thread Status:
Not open for further replies.

Share This Page