Solved Instasoup don't works....

Discussion in 'Plugin Development' started by nickpowns, Jul 18, 2014.

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

    nickpowns

  2. Offline

    Traks

    It should only fully heal you when your health is 10 or above, since your second if-statement isn't an else if-statement. You should also compare objects (which aren't constants) with the equals method, unless you, of course, want to compare their references
     
  3. Offline

    nickpowns

    so i did changed it to else if, but it didn't work.
    ik that ive not set @Eventhandler etc. but in eclipse i have.

    Code:java
    1. if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    2. if(p.getItemInHand().getType() == Material.MUSHROOM_SOUP) {
    3. if(p.getHealthScale() < 15) {
    4. p.setHealth(p.getHealthScale() + 5);
    5. p.getItemInHand().setType(Material.BOWL);
    6. }
    7. else if(p.getHealthScale() >= 15) {
    8. p.setHealth(20);
    9. p.getItemInHand().setType(Material.BOWL);
    10. }
    11. }
    12. return;
    13. }
    14. }
     
  4. Offline

    Regablith

    Check if the health is less then 20, and if so add 5 hearts to their health and remove the soup. If not, don't do anything. You're checking the scale of the health, which is checking if the player has less than 7.5 hearts (If I'm not mistaken). When you are adding health, do the player's health + 5
     
    GlacialCreeper likes this.
  5. Offline

    nickpowns

    my new code:
    Code:java
    1. if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    2. if(p.getItemInHand().getType() == Material.MUSHROOM_SOUP) {
    3. if(p.getHealthScale() < 20) {
    4. p.setHealth(p.getHealth() + 5);
    5. p.getItemInHand().setType(Material.BOWL);
    6. }
    7. }
    8. return;
    9. }

    doesn't work either, it dont heals me or give me a bowl...
     
  6. Offline

    Paradrakor

    Code:java
    1. if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    2. double health = player.getHealth();
    3. if (mat == Material.MUSHROOM_SOUP) {
    4. ItemStack bowl = new ItemStack(Material.BOWL);
    5. if (health == 20) {
    6. int food = player.getFoodLevel();
    7. if (food == 20){
    8. return;
    9. }
    10. int nfood = food + 7;
    11. if (nfood > 20) {
    12. player.setFoodLevel(20);
    13. }
    14. else {
    15. player.setFoodLevel(nfood);
    16. }
    17. player.getInventory().setItem(player.getInventory().getHeldItemSlot(), bowl);
    18. event.setCancelled(true);
    19. return;
    20. } else {
    21. double nhealth = health + 7;
    22. if (nhealth > 20) {
    23. player.setHealth(20);
    24. } else {
    25. player.setHealth(nhealth);
    26. }
    27. event.setCancelled(true);
    28. player.getInventory().setItem(player.getInventory().getHeldItemSlot(), bowl);
    29. return;
    30. }
    31.  
    32. }
    33. }



    my code for instasoup - it works perfectly, but it's for 3.5 hearts of healing not 2.5.
     
  7. Offline

    nickpowns

    thanks, ill try to use it tomorrow (im from the netherlands, thats why)
     
  8. Offline

    22vortex22

    This code is overcomplicated and unneeded. I show mine when I get home.
     
  9. Offline

    Scullyking

    Always use .equals() rather than == when comparing objects. Don't forget strings are objects.
     
  10. Offline

    Paradrakor

    no need to be rude. i'm a beginner. if it works perfectly, it doesn't really matter if it's unneeded.
     
  11. Offline

    nickpowns

    omg thank you guys so much!
    i've finally got it! :)
     
  12. Offline

    22vortex22

    I'm not trying to be rude. I was trying to help out. (It might have sounded rude and I'm sorry) You need to learn how to make code simplier.



    Code:java
    1. @EventHandler
    2. public void OnPlayerSoup(PlayerInteractEvent event){
    3. Player player = event.getPlayer();
    4. if(player.getHealth() == 20){}
    5. else
    6. {
    7. int soup = +7;
    8. if((event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) && player.getItemInHand().getType().equals(Material.MUSHROOM_SOUP))
    9. {
    10. player.setHealth(player.getHealth() + soup > player.getMaxHealth() ? player.getMaxHealth() : player.getHealth() + soup);
    11. event.getPlayer().getItemInHand().setType(Material.BOWL);
    12. }
    13. }
    14. }
     
Thread Status:
Not open for further replies.

Share This Page