Sending multiple messages on deathevent

Discussion in 'Plugin Development' started by RuthlessRage, Apr 5, 2015.

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

    RuthlessRage

    if 10 players are killed from a tnt explosion then i wan there to be 10 messages each containing the players who died names. ti sis on entity event and its checking the last cause and if its blasteplosion then its suppost to send the message. but if 10 ppl die to the same tnt it will only show the first to die message how can i make it show messages for each player that died
     
  2. Show your code
     
  3. Offline

    Gater12

  4. Offline

    Xerox262

    Make the players that die an array instead of just a single player

    Do something like this

    Player[] died = e.getPlayer //This is an array, can store more than one player

    int i = 0; //Makes it so that the plugin will know what player it's on
    while (i <= died.length){
    Bukkit.BroadcastMessage(Bukkit.GetOfflinePlayers(died.getPlayer().getName()) + " was blown sky high"); //Will broadcast a message for every person that dies
    i ++; //Makes sure the plugin doesn't get stuck in a loop forever
    }

    If this worked set the post to filled please :3

    Edit D: I just noticed that it doesn't space it correctly ;-; if you paste that into eclipse press CTRL + Shift + F and it should format it for you

    Or... If you wanted to cut down the spam you could make it all appear in one message but with multiple players you could do

    while (i <= died.length){
    String broadcastMessage = "";
    while (i != died.length){
    broadcastMessage += Bukkit.getOnlinePlayer(died.getPlayer().getName()) + ", "
    i ++;
    }
    if(broadcastMessage.equals("")){
    broadcastMessage = Bukkit.getOnlinePlayer(died.getPlayer().getName()) + " was blown away")
    } else {
    broadcastMessage += "and " + Bukkit.getOnlinePlayer(died.getPlayer().getName()) + " was blown away"
    }
    Bukkit.broadcastMessage(broadcastMessage);
    }
     
    Last edited: Apr 5, 2015
  5. Offline

    RuthlessRage

    @Xerox262 @FisheyLP @Gater12

    if 10 players die to one tnt i want it to broadcast all the players who died
    Code:
    public void onEntityDeath(PlayerDeathEvent e) {
        Entity ent = e.getEntity().getPlayer(); 
        EntityDamageEvent ede = ent.getLastDamageCause();
        DamageCause dc = ede.getCause();
        Player p = (Player)ent;
        if (dc == DamageCause.BLOCK_EXPLOSION) {
           
            Bukkit.BroadcastMessage(ChatColor.RED + p.getName() + "died by tnt!");
           
            }
    }
     
  6. Offline

    Xerox262

    It's cus you didn't use an array :p it's only seeing the first player, try this
    Code:
    public void onEntityDeath(PlayerDeathEvent e) {
        Entity ent = e.getEntity().getPlayer();
        EntityDamageEvent ede = ent.getLastDamageCause();
        DamageCause dc = ede.getCause();
        Player[] p = (Player)ent;
        if (dc == DamageCause.BLOCK_EXPLOSION) {
            int i = 0;
            String broadcastMessage = "";
            if (p.length > 1){
                while(i != p.length - 1){
                    broadcastMessage += Bukkit.getOnlinePlayer(p[i].getPlayer().getName() + ", ");
                    i ++;
                }
            }
            if (i + 2 == p.length) {
                 broadcastMessage += Bukkit.getOnlinePlayer(p[i].getPlayer().getName() + " and "
                 i ++;
                 broadcastMessage += Bukkit.getOnlinePlayer(p[i].getPlayer().getName() + " died by tnt!"
            }
            if (broadcastMessage.equals("")){
                broadcastMessage = Bukkit.getOnlinePlayer(p[i].getPlayer().getName() + " died by tnt";
            }
         }
    }
     
  7. Offline

    Gater12

    @Xerox262
    getPlayer() returns a single Player object. I don't know how you turned it into an array. Can you explain that?
     
  8. Offline

    Xerox262

    :I You're right, ignore my last message

    Edit:

    Wait, there's nothing wrong with your code, I just tested it and it works like it should look apart from the missing space :p
     
    Last edited: Apr 5, 2015
  9. Offline

    RuthlessRage

  10. Offline

    Booshayy

  11. Offline

    RuthlessRage

    @Booshayy yes the problem is that this code will only show the first player to die. being that say 5 people all died from the same explosion.
    Code:
    public void onEntityDeath(PlayerDeathEvent e) {
        Entity ent = e.getEntity().getPlayer();
        EntityDamageEvent ede = ent.getLastDamageCause();
        DamageCause dc = ede.getCause();
        Player p = (Player)ent;
        if (dc == DamageCause.BLOCK_EXPLOSION) {
          
            Bukkit.BroadcastMessage(ChatColor.RED + p.getName() + "died by tnt!");
          
            }
    }
     
  12. @RuthlessRage Just want to say, set the death message don't broadcast otherwise it will do both. Also that message will print "bwfcwalshydied by tnt!"
     
    dlange likes this.
  13. Offline

    RuthlessRage

    @bwfcwalshy @Gater12 @Booshayy IS everyone here blind or am I not explaining this right.

    Jack,jill,jhon and Jamie go into the wilderness. they build a house. they start decorating their house. jack goes out to get more resources. jack comes back with tnt and redstone. he attempts to add a tnt trap when someone tries to enter their house. while he was adding this trap he set it off! jack,jill,jhon and Jamie all die. yet the chat only shows that jill has died! let me clarify again... all the players died but it will only show one player who died.

    the way I want my plugin to turn out I can't use setdeathmessage. I only want the players within a 15 block radius to get not a deathmessage but for the plugin to send them a message with player.sendmessage(). ounce again this will not show all the players who died to the same explosion only one...
     
  14. Offline

    nverdier

    @RuthlessRage You really need to make yourself more clear in the OP and all of the other posts. And don't call us blind.
     
  15. Offline

    RuthlessRage

    @nverdier this is clear as the tiguana river

    Jack,jill,jhon and Jamie go into the wilderness. they build a house. they start decorating their house. jack goes out to get more resources. jack comes back with tnt and redstone. he attempts to add a tnt trap when someone tries to enter their house. while he was adding this trap he set it off! jack,jill,jhon and Jamie all die. yet the chat only shows that jill has died! let me clarify again... all the players died but it will only show one player who died.
    the way I want my plugin to turn out I can't use setdeathmessage. I only want the players within a 15 block radius to get not a deathmessage but for the plugin to send them a message with player.sendmessage(). which i already have set up. ounce again this will not show all the players who died to the same explosion only one player!...
     
  16. Offline

    nverdier

    Msrules123 likes this.
  17. Offline

    RuthlessRage

    @nverdier i'm still without an awnser here someone help me please!
    and that's not the river. the river is in mexico and its a river not ocean...
     
  18. Offline

    nverdier

    @RuthlessRage
    1) On player death event, add the user to a Set if they were killed by tnt.
    2) Get the players that were killed by it, and use a StringBuilder to compose a message with all of their names.
    3) Broadcast the message.
     
  19. Offline

    RuthlessRage

    Why would I add a thing to get the playes that died if the listener already detects who died by tnt. And could you show me an example what your talking about
     
  20. Offline

    nverdier

    @RuthlessRage Because the listener is called every time a player dies, not the same listener for everybody who died then. And no, I will not spoonfeed. That's not something we do.
     
  21. Offline

    RuthlessRage

    @nverdier so if player dies to tnt put them in a hashmap and then In a separate listener make it broadcast it. But how will I know when a player is put in that hashmap and when to send the message what event will I use
     
  22. Offline

    nverdier

    @RuthlessRage You don't broadcast it in a separate listener... You only have one death listener, right?
     
  23. Offline

    Zombie_Striker

    • Create an array or map to hold the String
    • On the death event, put their names into the map/array
    • Use a string builder to put together all the names
    • If you do not want ten different lines saying all the people that died. make a delayed task that will fire once, and clear the array.
     
Thread Status:
Not open for further replies.

Share This Page