Dropped item not damging player?

Discussion in 'Spigot Plugin Development' started by Snowmite, May 21, 2016.

  1. I'm trying to make it so that when a player right clicks a pickaxe, it shoots rails. I have no problems with that, I have problems where it damages the player. Here's my code:
    http://hastebin.com/atewiropoz.coffee
     
  2. You have to set it to a double ;)
    Code (Text):
    p.damage (1.0);
     
  3. It damages the shooter...
     
  4. Choco

    Moderator

    Code (Java):
    if (p.equals(pl)) continue;
    ?
     
  5. Okay it doesn't hurt the shooter or the player that got shot, here's my modified code: http://hastebin.com/nipiwelaxa.coffee
     
  6. This makes no sense.. You want to shoot it, but this is simply going to damage each player that is within 1 meter of the user

    You are not letting the drop move at all before you check the location and do damage.. Try a scheduler that holds the drop entity, the person who shot it, and checks if it has reached its target, or check collisions? (it should automatically "pick up" if it hits a player, which can be used to check collision, right).

    Not too important, but good coding practice: use == here instead of equals(object). equals is used to see if two objects have identical data, like two strings being the same. == checks if the objects are the exact same object (same location in memory).

    Code (Java):
    // Makes no sense o _ o
    for(Player p : drop.getWorld ().getPlayers ())
    {
        if(p.equals (pl)) continue;
        if(drop.getLocation ().distance (p.getLocation ()) < 1.0)
        {
            p.damage (1.0);
        }
    }
     
  7. Didn't help me at all..
     
  8. I just told you exactly what was wrong. Read it again?
     
  9. How would I check for a collision? Could you like give me the code to do it? I really don't know how and where to put these methods.
     
  10. You are doing something quite complicated and inefficient that i would not even waste my own time doing, let alone do it to spoonfeed you code, sorry. I told you exactly how to do it, if you do not understand that, you are not ready to do this.

    You should just get more experience with simpler things (since it seems like you do not understand the basics of how code is executed, with regards to order of operations), or alternatively, look up the basic bukkit scheduler tutorials.
     
  11. Why is everyone on Spigot so stubborn?
     
  12. You really expect people to write your plugins for you? Maybe learn enough so you can write them yourself instead of acting surprised.
     
    • Agree Agree x 3
    • Like Like x 1
  13. bump
     
    • Optimistic Optimistic x 1
  14. Double. The damage for example 6 = 3 hearts, 1 = 0.5 hearts
     
  15. As @FlyingLlama said above, a scheduler can accomplish this task fairly easily. I'm certain that there's a Wiki on scheduling tasks, if you don't know how to use them. If you don't understand the Wiki, then you should probably learn/brush up on your Java/OOP.
     
  16. I know how to work with a scheduler, do I just make a repeating task of if it hits a player then cancel it when it does?
     
  17. Yes, but also make sure that it will only run for a short time, say run every 4 ticks (5 times per second), cancels and deletes the item if it hits a player or after a few seconds. You will need to save and re-apply the velocity each tick. The method for detecting collision could either be the item pickup event, unrelated from the scheduler (just stop it if the item entity no longer exists) or based on proximity.
     
  18. How does that make him stubborn? Do you even know what stubborn fucking means? Or are you just throwing around words to try sound more sophisticated? Go back and read some tutorials, you're obviously not suited for accomplishing such a simple task as this, lol
     
    • Creative Creative x 1