Adding custom expierience

Discussion in 'Plugin Development' started by PingschelleMC, Oct 15, 2014.

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

    PingschelleMC

    I have no idea how to add a custom value of expierience to the player, when he kills my custom mob; I tried many ways, but they glitch (at level up), etc. Maybe some of you have valid code for that?

    My Event
    Code:java
    1. @EventHandler
    2. public void onEntityKill(EntityDeathEvent event) {
    3. if(event.getEntity() instanceof Chicken) {
    4. Chicken c = (Chicken) event.getEntity();
    5. if(c.getKiller() != null) {
    6. if(c.getCustomName().equals("§aHofhenne §8[§6Lv 1§8]")) {
    7. Player p = c.getKiller();
    8. System.out.println("--- Ein Level 1 Huhn wurde getötet! ---");
    9. Core.chickenLv1--;
    10. event.getDrops().clear();
    11. event.setDroppedExp(0);
    12. p.playSound(p.getLocation(), Sound.NOTE_PLING, 1, 2);
    13.  
    14. //Here I want to add expierience to the player, when he kills my custom mob and NO,
    15. //I don't wanna remove event.setDropped(0), because my server is going to be a RPG
    16. //one and I wanna add a lot of different expieriences to the player for killing different
    17. //custom mobs.
    18. }
    19. }
    20. }
    21. }
     
  2. Offline

    mythbusterma

    PingschelleMC

    You forgot to check if the killer was indeed a player, and why can't you just set the mob to drop more or less experience than usual? That would work.
     
  3. Offline

    PingschelleMC

    Example code?
     
  4. Offline

    fireblast709

    mythbusterma getKiller() will either return a Player or null :p.
    PingschelleMC I would have multiple fields, one for each skill, each tracking the experience for that skill (or a Map where the key is the skill - perhaps a Skill enum with an EnumMap).
     
  5. Offline

    mythbusterma

    fireblast709

    Right, should've checked the docs, my mistake.

    PingschelleMC

    You set the dropped experience to 0 above, just make it something else instead.
     
Thread Status:
Not open for further replies.

Share This Page