Mob Kills!

Discussion in 'Plugin Development' started by jusjus112, Nov 19, 2013.

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

    jusjus112

    What i will is, if you kill 100 zombies your getting an item in your inventory.
    and 200 anothere item and remove the first item?
    can someone help me with this?
     
  2. jusjus112

    Code:java
    1. public Map<String, Integer> kills = new HashMap<String, Integer>();
    2.  
    3. @EventHandler
    4. public void kill(EntityDeathEvent e) {
    5. Entity zombie = e.getEntity();
    6. if (zombie instanceof Zombie) {
    7. if (((Zombie) zombie).getKiller() instanceof Player) {
    8. Player p = ((Zombie) zombie).getKiller();
    9. if (kills.containsKey(p.getName())) {
    10. kills.put(p.getName(), kills.get(p.getName()) + 1);
    11. } else {
    12. kills.put(p.getName(), 1);
    13. }
    14.  
    15. if(kills.get(p.getName()) == 100) {
    16. p.getInventory().addItem(new ItemStack(Material.DIAMOND_ORE));
    17. }
    18.  
    19. if(kills.get(p.getName()) == 200) {
    20. p.getInventory().contains(Material.DIAMOND_ORE);
    21. p.getInventory().remove(new ItemStack(Material.DIAMOND_ORE));
    22. //Add new
    23. }
    24.  
    25. }
    26. }
    27. }
     
    jusjus112 and user_90854156 like this.
  3. Offline

    jusjus112

    DreTaX
    Nice, but what must i do if is saves.
    If the player leaves, ands again joins, then hes lost.
    What must i do so that e remember that every player has there own items if they killed 100 zombies.

    Example: a player kills 100 zombies, they get an diamond in there inventory.
    if an player leaves, then must remember it and getting him the item thats getting a player if they reached 100 kills
     
  4. You could do a config.

    public FileConfiguration config;

    config = getConfig();

    If player joins do:

    Main.config.set("Players.Kills." + p.getName(), kills.get(p.getName()))

    Later you can get it from the config. Or just what ever you would like to
     
  5. Offline

    jusjus112

    DreTaX
    Must i put it in my onEnable or JoinEvent?
     
  6. Wait a sec
     
  7. Offline

    jusjus112

    DreTaX
    ???
    i dont understand
     
  8. This should work.

    Code:java
    1. private FileConfiguration config;
    2. public Map<String, Integer> kills = new HashMap<String, Integer>();
    3.  
    4. public void onEnable(){
    5. config = this.getConfig();
    6. saveConfig();
    7.  
    8. }
    9.  
    10. @EventHandler
    11. public void join(PlayerJoinEvent e) {
    12. Player p = e.getPlayer();
    13. if (!config.contains(p.getName() + ".Kills")) {
    14. config.set(p.getName() + ".Kills", 0);
    15. saveConfig();
    16. kills.put(p.getName(), 0);
    17. }
    18. else {
    19. kills.put(p.getName(), config.getInt(p.getName() + ".Kills"));
    20. }
    21. }
    22.  
    23. @EventHandler
    24. public void kill(EntityDeathEvent e) {
    25. Entity zombie = e.getEntity();
    26. if (zombie instanceof Zombie) {
    27. if (((Zombie) zombie).getKiller() instanceof Player) {
    28. Player p = ((Zombie) zombie).getKiller();
    29. if (kills.containsKey(p.getName())) {
    30. kills.put(p.getName(), kills.get(p.getName()) + 1);
    31. }
    32.  
    33. if(kills.get(p.getName()) == 100) {
    34. p.getInventory().addItem(new ItemStack(Material.DIAMOND_ORE));
    35. }
    36.  
    37. else if(kills.get(p.getName()) == 200) {
    38. p.getInventory().contains(Material.DIAMOND_ORE);
    39. p.getInventory().remove(new ItemStack(Material.DIAMOND_ORE));
    40. //Add new
    41. }
    42.  
    43. }
    44. }
    45. }
    46.  
    47. @EventHandler
    48. public void leave(PlayerQuitEvent e) {
    49. Player p = e.getPlayer();
    50. config.set(p.getName() + ".Kills", kills.get(p.getName()) + 1);
    51. saveConfig();
    52. }
    53. }


    Also on leave event remove the player from the kills.

    I guess like this:

    @EventHandler
    public void leave(PlayerQuitEvent e) {
    Player p = e.getPlayer();
    config.set(p.getName() + ".Kills", kills.get(p.getName()) + 1);
    saveConfig();
    kills.remove(p.getName());
    }

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  9. Offline

    jusjus112

    DreTaX
    Very thanks, it hoops it will work.
    I just said almost i love you
    Not gay ;-0
     
    DreTaX likes this.
  10. xD np

    Oh shit. On leave event i made a mistake. Remove the +1 config.set(p.getName()+".Kills", kills.get(p.getName())+1);

    So it will be: config.set(p.getName()+".Kills", kills.get(p.getName());

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  11. Offline

    jusjus112

    DreTaX
    i am usign 3 classes, but how to do the onEnable in my main class, and the itemlores e.t.c in my other class?
     
  12. Offline

    CookieGamer100

    #LifeSaverThread
     
  13. Offline

    jusjus112

    DreTaX
    Can i use your system for xp. so that players getting xp.

    And how do i make an command, that you see how many kills you have?
     
  14. Wait wut?:D
     
  15. Offline

    jusjus112

    DreTaX
    Now if a player types /kills they see how many zombies they have killed!
    use the code that you have send above!
     
  16. So everything works?
     
  17. Offline

    jusjus112

    DreTaX
    no, i ask you him to do this?
    with your code?

    Or make an scoreboard were they can see how many kills they have
     
  18. So you want me to type a /kills command which gets the kills?
     
  19. Offline

    jusjus112

    DreTaX
    Yes, i think you getting the player from the config, or maybe im wrong?
    But i dont no how to do this?
     

  20. Code:java
    1. getCommand("stats").setExecutor(this);
    2.  
    3. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    4. if (args.length > 0) {
    5. if (!(sender instanceof Player)) {
    6. sender.sendMessage("You aren't a player");
    7. return false;
    8. }
    9. else {
    10. Player p = (sender);
    11. String name = p.getName();
    12. if (args[0].equalsIgnoreCase("kills")) {
    13. int pkills = kills.get(name);
    14. p.sendMessage(ChatColor.GREEN + "You have killed sofar: " + ChatColor.RED + pkills + ChatColor.GREEN + " zombies";
    15. }
    16. }
    17. }
    18. return false;
    19. }
     
    jusjus112 likes this.
  21. Offline

    jusjus112

    DreTaX
    Very thanks :D, my problem is now gone :D
    if this dont work! You will hear from me.

    DreTaX
    Hes is giving my this error:
    PHP:
    21.11 19:23:58 [Multicraftjusjus112 ran command Bericht van de dag
    21.11 19
    :23:58 [ServerINFO ... 14 more
    21.11 19
    :23:58 [ServerINFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
    21.11 19:23:58 [ServerINFO at java.lang.reflect.Method.invoke(Method.java:601)
    21.11 19:23:58 [ServerINFO at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    21.11 19:23:58 [ServerINFO at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    21.11 19:23:58 [ServerINFO at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    21.11 19:23:58 [ServerINFO at Ranks.TestInventory.onPlayerJoin(TestInventory.java:53)
    21.11 19:23:58 [ServerINFO Caused byjava.lang.NullPointerException
    21.11 19
    :23:58 [ServerINFO at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
    21.11 19:23:58 [ServerINFO at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:419)
    21.11 19:23:58 [ServerINFO at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:486)
    21.11 19:23:58 [ServerINFO at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:226)
    21.11 19:23:58 [ServerINFO at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:590)
    21.11 19:23:58 [ServerINFO at net.minecraft.server.v1_6_R2.DedicatedServerConnection.b(SourceFile:29)
    21.11 19:23:58 [ServerINFO at net.minecraft.server.v1_6_R2.DedicatedServerConnectionThread.a(DedicatedServerConnectionThread.java:41)
    21.11 19:23:58 [ServerINFO at net.minecraft.server.v1_6_R2.PendingConnection.d(PendingConnection.java:43)
    21.11 19:23:58 [ServerINFO at net.minecraft.server.v1_6_R2.PendingConnection.e(PendingConnection.java:133)
    21.11 19:23:58 [ServerINFO at net.minecraft.server.v1_6_R2.PlayerList.a(PlayerList.java:103)
    21.11 19:23:58 [ServerINFO at net.minecraft.server.v1_6_R2.PlayerList.c(PlayerList.java:207)
    21.11 19:23:58 [ServerINFO at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
    21.11 19:23:58 [ServerINFO at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
    21.11 19:23:58 [ServerINFO at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    21.11 19:23:58 [ServerINFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
    21.11 19:23:58 [ServerINFO org.bukkit.event.EventException
    21.11 19
    :23:58 [ServerSEVERE Could not pass event PlayerJoinEvent to zombieRanks v0.1
    21.11 19
    :23:58 [ConnectUser jusjus112IP 85.150.161.214
    21.11 19
    :23:55 [ServerINFO §ejusjus112 left the game.
    21.11 19:23:55 [ServerINFO ... 14 more
    21.11 19
    :23:55 [ServerINFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
    21.11 19:23:55 [ServerINFO at java.lang.reflect.Method.invoke(Method.java:601)
    21.11 19:23:55 [ServerINFO at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    21.11 19:23:55 [ServerINFO at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    21.11 19:23:55 [ServerINFO at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    21.11 19:23:55 [ServerINFO at Ranks.TestInventory.leave(TestInventory.java:423)
    21.11 19:23:55 [ServerINFO Caused byjava.lang.NullPointerException
    21.11 19
    :23:55 [ServerINFO at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
    21.11 19:23:55 [ServerINFO at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:419)
    21.11 19:23:55 [ServerINFO at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:486)
    21.11 19:23:55 [ServerINFO at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:226)
    21.11 19:23:55 [ServerINFO at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:590)
    21.11 19:23:55 [ServerINFO at net.minecraft.server.v1_6_R2.DedicatedServerConnection.b(SourceFile:30)
    21.11 19:23:55 [ServerINFO at net.minecraft.server.v1_6_R2.ServerConnection.b(SourceFile:37)
    21.11 19:23:55 [ServerINFO at net.minecraft.server.v1_6_R2.PlayerConnection.e(PlayerConnection.java:116)
    21.11 19:23:55 [ServerINFO at net.minecraft.server.v1_6_R2.NetworkManager.b(NetworkManager.java:302)
    21.11 19:23:55 [ServerINFO at net.minecraft.server.v1_6_R2.PlayerConnection.a(PlayerConnection.java:688)
    21.11 19:23:55 [ServerINFO at net.minecraft.server.v1_6_R2.PlayerList.disconnect(PlayerList.java:259)
    21.11 19:23:55 [ServerINFO at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
    21.11 19:23:55 [ServerINFO at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
    21.11 19:23:55 [ServerINFO at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    21.11 19:23:55 [ServerINFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
    21.11 19:23:55 [ServerINFO org.bukkit.event.EventException
    21.11 19
    :23:55 [ServerSEVERE Could not pass event PlayerQuitEvent to zombieRanks v0.1
    And this is my line 423:
    Code:java
    1. config.set(p.getName() + ".kills", kills.get(p.getName()));

    And my code for line 53:
    Code:java
    1. if (!config.contains(p.getName() + ".kills")) {
    2.  


    I hope you can fiks this!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
    DreTaX likes this.
  22. Send the code in pm
     
  23. Offline

    jusjus112

    DreTaX
    pm? Wich code? My full code is the code that you give it to me in 2e thread!
     
Thread Status:
Not open for further replies.

Share This Page