Killstreak Help.

Discussion in 'Plugin Development' started by MCraftGamer35, Aug 5, 2014.

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

    MCraftGamer35

    Hello! I am developing a Killstreak plugin, at 5 kills, I want there to be a nuke, which would basically kill all players and count as a kill for the player that got the killstreak, I believe I'll have problems. So if there is any advice or help anyone could give that be great!
     
  2. Offline

    luigieai

    Can you show us your code that you already tried??
     
  3. Offline

    JustinsCool15

    MCraftGamer35
    When the player dies set add them to a hashmap with a value of 1
    Check the value of the hashmap
    If the value is 5 then kill everyone

    When they die remove them from the hashmap
     
  4. Offline

    MCraftGamer35

    here's the code.
    Code:java
    1. package me.Alex.ElectricityKillstreak;
    2.  
    3. import java.util.HashMap;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9. public class Killstreaks extends JavaPlugin {
    10.  
    11. private HashMap<String, Integer> killstreak = new HashMap<String, Integer>(); {
    12. }
    13. Player p = (Player) sender;
    14. if(killstreak.containsKey(player.getName()))
    15. killstreak.put(player.getName(), killstreak.get(player.getName()) + 1);
    16. else
    17. killstreak.put(player.getName(), 1);
    18. if(killstreak.get(player.getName()) >= 5)
    19. {
    20. Player player = (Player) sender;
    21. player.sendMessage(ChatColor.GREEN + "A nuke has been called in!");
    22. {
    23.  
    24.  
    25. }
    26.  
    27. }
    28.  
    29. }
    30.  
    31. }
     
  5. Offline

    JustinsCool15

  6. Offline

    krazytraynz

  7. Offline

    MCraftGamer35

    I know what I'm doing, i've coded multiple plugins.
     
  8. Offline

    JustinsCool15

    mine-care likes this.
  9. Offline

    MCraftGamer35

    Exactly. That's why I posted this. xD
     
  10. Offline

    krazytraynz

    Not to be rude, but are you sure? You have random brackets all over the place, you're missing both onEnable() and onDisable() methods, and the code that should to add/check for kills isn't even inside of a method. It seems to me like you need a lot more experience than you have right now before you start making plugins.
     
    mine-care likes this.
  11. Offline

    MCraftGamer35

    I have made a couple plugins. With a little help from tutorials. Also I haven't coded in 2 weeks, so I'm a little rusty.
     
  12. Offline

    Gater12

    MCraftGamer35
    The amount of plugins you made doesn't really determine how well you are good with Java.
    Quantity != Quality

    krazytraynz
    You don't need an onEnable or onDisable method in your main class. You only need one or both of them when you need to execute code when the plugin starts up is enabled (onEnable) or when the plugin is going to be disabled (onDisable).

    Edit: Silly onLoad is where the plugin is loaded.
     
  13. Offline

    Dragonphase

  14. Offline

    MCraftGamer35

    Here, this is my less sloppy version, and more working on version. Sorry for the confusion. I am tired and rusty.

    Code:java
    1. package me.Alex.ElectricityKillstreak;
    2.  
    3. import java.util.HashMap;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class Killstreaks extends JavaPlugin {
    11.  
    12. public void onEnable() {
    13. Bukkit.getServer().getLogger().info("Plugin enabled!");
    14. }
    15.  
    16. public void onDisable() {
    17. Bukkit.getServer().getLogger().info("Plugin enabled!");
    18. }
    19.  
    20. private HashMap<String, Integer> killstreak = new HashMap<String, Integer>(); {
    21.  
    22. }
    23.  
    24. if(killstreak.containsKey(player.getName()))
    25. killstreak.put(player.getName(), killstreak.get(player.getName()) + 1);
    26. else
    27. killstreak.put(player.getName(), 1);
    28. if(killstreak.get(player.getName()) >= 5);
    29. }
    30. }
    31.  
     
  15. Offline

    krazytraynz

    Gater12
    Huh, I've always assumed those were needed. My bad.
    Spoiler (open)
    [​IMG]
     
    mine-care likes this.
  16. Offline

    _Cookie_

    Why do you have brackets when you use your HashMap? Weird.

    [CLUE]: Try use onDeathEvent
    Get the person who killed them? Then get there name? Use it as the key for the HashMap? Add a point to there name?
    That is all I'm going to say.
     
  17. Offline

    JustinsCool15

    MCraftGamer35
    I'd recommend you watch some more video tutorials. I don't think you fully understand the Syntax of Java.

    Edit:
    You should do some independent research on Java and Object Oriented Programming.
     
  18. Offline

    Dragonphase

  19. Offline

    JustinsCool15

  20. Offline

    Dragonphase

    JustinsCool15


    You should be telling him to do some independent research on Java and Object Oriented Programming...
     
    mine-care and JustinsCool15 like this.
  21. Offline

    KaitouKidFTW

    Its always a good idea to plan before coding so you know what your going to do.
    Let me help you out.

    > Listen for player death.
    > Get the killer and add that player to a hash map and give them a kill streak.
    > If the player has 5 kills on the hash map then kill all players.
    > Get how many people that were killed and add that number to the number of kill streak player has.

    > If player dies then reset his kill streak to 0
     
  22. Offline

    mine-care

    Okk, my sugestion is:
    1. first learn java! Cough cough Player casting, random brackets,ect.
    2. Dont copy paste code or see the "tutorial" and type the code shown. You dont learn a thing from it.
    3. read java docs when needed,
    No offence, how would you rate yourself in a scale of 1-10 in terms of java knowledge?
     
Thread Status:
Not open for further replies.

Share This Page