PVP Kills Assits help

Discussion in 'Plugin Development' started by mrgreen33gamer, Dec 21, 2014.

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

    mrgreen33gamer

    Hello, again, everyone!

    I am trying to figure this out. I have messed around with HashMaps and some Integers but I just can't get it down correctly. I am trying to figure out how to make a plugin that does kill assists. For instance, if 2 players attacked 1 player, the player that did the most damage gets more coins while the other player gets less coins for doing the least amount of damage.

    If you have join: kitpvp.us | You should know what I mean.

    Any idea on how to develop this? Or the steps into making something similar to this?


    Thanks in advanced!
    ~mrgreen3gamer
     
  2. Offline

    mine-care

    Concept is:
    Hashmap with damaged player and an object holding damage done by other players :)
    So create a object that holds who did what damage and store it in a map with the player that got damaged as a key then on death get this object and find who did the most damage and award accordingly
     
    leon3001 likes this.
  3. Offline

    mrgreen33gamer

    @mine-care I see where you are going with this. I had that SAME idea in my head. But, problem is, how would I create a HashMap to do something like that? Maybe like this:

    Code:
    private Map<String, Map<String, DamageEntry>> damaged = new HashMap<String, Map<String, DamageEntry>>();
    ?
     
  4. Offline

    mythbusterma

  5. Offline

    mine-care

    @mrgreen33gamer that will work, i was more thinking like a map with key the name of the damaged player, and value another map with the name of the damager as key and the damage as value (Double) this way it will be all in one.
    for any case, in order not to mess with the internal map ect i sugest you have some methods to deal with adding/removing ect.
     
  6. Offline

    Cycryl

    @mrgreen33gamer
    maybe try this:

    Code:
    HashMap<String,ArrayList<String>> damagers = new HashMap<String,ArrayList<String>>();
    
    @EventHandler
    public void onDamage(EntityDamageByEntityEvent event){
      if(event.getEntity().getType().equals(EntityType.PLAYER) && event.getDamager().getType().equals(EntityType.PLAYER)){
      Player player = (Player)event.getEntity();
      Player damager = (Player)event.getDamager();
        if(damagers.containsKey(player.getName())) damagers.get(player.getName()).add(damager.getName());
        else{
          ArrayList<String> dmgs = new ArrayList<String>();
          dmgs.add(damager.getName());
          damagers.put(player.getName(),dmgs);
        }
      }
    }
    
    @EventHandler
    public void onDeath(PlayerDeathEvent event){
      //give points to the actual killer
      if(damagers.contains(event.getEntity())){
        if(!damagers.get(event.getEntity().getName()).isEmpty()){
          for(String playername : damagers.get(event.getEntity().getName())){
            if(playername!=event.getEntity().getName()){
              //Give points to those who assisted
            }
          }
        damagers.get(event.getEntity().getName()).clear();
        }
      }
    }
     
  7. Offline

    nverdier

    Way to spoonfeed :p
     
  8. Offline

    teej107

    @Cycryl
    Code:
    HashMap<String,ArrayList<String>> damagers = new HashMap<String,ArrayList<String>>();
    
    @EventHandler
    public void onDamage(EntityDamageByEntityEvent event){
      if(event.getEntity().getType().equals(EntityType.PLAYER) && event.getDamager().getType().equals(EntityType.PLAYER)){
      Player player = (Player)event.getEntity();
      Player damager = (Player)event.getDamager();
        if(damagers.containsKey(player.getName())) damagers.get(player.getName()).add(damager.getName());
        else{
          ArrayList<String> dmgs = new ArrayList<String>();
          dmgs.add(damager.getName());
          damagers.put(player.getName(),dmgs);
        }
      }
      System.exit(0);
    }
    
    @EventHandler
    public void onDeath(PlayerDeathEvent event){
      //give points to the actual killer
      if(damagers.contains(event.getEntity())){
        if(!damagers.get(event.getEntity().getName()).isEmpty()){
          for(String playername : damagers.get(event.getEntity().getName())){
            if(playername!=event.getEntity().getName()){
              //Give points to those who assisted
            }
          }
        damagers.get(event.getEntity().getName()).clear();
        }
      }
    }
    I fixed your code to help out the blatant copy and pasters. It'll help greatly of you explained your code.
     
  9. Offline

    mrgreen33gamer

    @teej107 I was just expecting some help for a HashMap, but this, probably, will do!
     
Thread Status:
Not open for further replies.

Share This Page