Two Questions

Discussion in 'Plugin Development' started by MCraftGamer35, Sep 4, 2014.

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

    MCraftGamer35

    I am developing a oitc plugin for my network, how would I make it so if you get hit by a arrow it kills you instantly, also, I want it to spawn in 4 spawnpoints, how would I do that also, please leave feedback, thanks!
    Here is my arrow code, please edit and correct it.
    Code:
    @EventHandler
        public void onEntityDamage(EntityDamageByEntityEvent e1){
            if (e1.getEntity() instanceof Arrow) {
                Player damaged = (Player) e1.getEntity();
                    damaged.setHealth(0);
     
  2. Offline

    teej107

  3. Offline

    MCraftGamer35

    That didn't really help me. Considering it's showing how to set spawns, but not really able to have a 25% chance of spawning in each one. For the arrow thing, that dosen't really help either.

    teej107
     
  4. Offline

    techboy291

    Most of the people here aren't going to code feed you (I hope). And yeah, just check to see if the event's getDamager() is an instanceof Arrow (getEntity() is the one getting damaged, which of course can't happen to an arrow); then setDamage(0) to kill them.

    I'm going to sound really stupid and kind of code feed you now, but I don't really want to explain it in words. ;c
    Say you had
    Code:
    List<Location> spawns;
    
    equal to all of the spawn-points. You could do:
    Code:
    Location spawn = spawns.get(new Random().nextInt(spawns.size())) // nextInt(int) gives you a random number between 0 and up to but not including the int specified.
    
     
  5. Offline

    Gater12

  6. Offline

    MCraftGamer35

  7. Offline

    teej107

    MCraftGamer35 I was pointing out the flaw and would hope you realize what you did wrong. Since you didn't seem to notice.... Instead of casting an Arrow (Entity but you did an instance check) to a Player (because Arrows aren't Players and therefore you'll get a ClassCastException), look at this http://jd.bukkit.org/rb/apidocs/org/bukkit/entity/Projectile.html. As for spawning, since you want to deal with random spawning, Use a Random!!!!!

    EDIT: You'll have to perform more than 1 instanceof check for your EntityDamageByEntityEvent.
     
  8. Offline

    techboy291

    MCraftGamer35 Update the code in the OP to what everyone suggested.
     
  9. Offline

    MCraftGamer35

    Heres my new code, still not working.@teej107
    Code:
    @EventHandler
        public void onEntityDamage(EntityDamageByEntityEvent e1){
            if (e1.getDamager() instanceof Arrow) {
                Player damager = (Player) e1.getDamager();
                Player damaged = (Player) e1.getEntity();
                    damaged.setHealth(0);
            }
        }
     
  10. Offline

    Deleted user

    -
     
    Last edited by a moderator: Jan 23, 2015
  11. Offline

    teej107

Thread Status:
Not open for further replies.

Share This Page