Solved Player score

Discussion in 'Plugin Development' started by TheAJ471, Apr 6, 2014.

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

    TheAJ471

    So I am creating a KitPvP plugin and I dont know how to make it so when a player joins the game it would set their 'Points' to 0 and every time they kill someone they get 1 point abd when they die they go back to 0 points again. Then I want to be able to see how many points the player has and when they get for example 10 points it will give them upgraded items.

    Thanks, TheAJ471
     
  2. Offline

    The_Coder

    Okay...First here is the event list that you will need: PlayerLoginEvent and PlayerDeathEvent. If you follow the bukkit plugin tutorial and know a little about java then it will be easy. If you need more help just let me know. :p
     
  3. Offline

    TheAJ471

    The_Coder So how would I add 1 point to the player who killed the dead player. (I know how to get the killer of that player btw)
     
  4. Offline

    GaaTavares

    HashMaps..
     
  5. Offline

    The_Coder

    EntityDeathEvent
     
  6. Offline

    FlareLine

    The_Coder I'm thinking you'd want PlayerJoinEvent for this, rather than PlayerLoginEvent
     
  7. Offline

    TheAJ471

    FlareLine The_Coder GaaTavares So I thought of a possible easier way to do this maybe. Each time the player gets a kill I could give them 1 diamond in their inventory. So how would I get how many diamonds are in the inventory?
     
  8. Offline

    coasterman10

    To check how many of an item are in someone's inventory, iterate over their whole inventory, and if an itemstack's type is diamond, add its quantity to a running total.

    It would also be much easier to store a Map of String (UUID for 1.7.5 forwards) to Integers storing the players' scores.
     
  9. Offline

    xTigerRebornx

  10. Offline

    coasterman10

    xTigerRebornx Getting/creating that whole hashmap each time would be unnecessarily taxing on processor cycles and memory.
     
  11. Offline

    TheAJ471

    coasterman10 xTigerRebornx So I have this. haven't tested it yet and sto is a int of 5 and I have all the inventories defined for the people like killer and stuff.

    Code:java
    1. if(plugin.pvp.contains(p) && pk.containsAtLeast(diamond, sto)){
    2. killer.getInventory().setHelmet(new ItemStack(Material.AIR));
    3. killer.getInventory().setChestplate(new ItemStack(Material.CHAINMAIL_CHESTPLATE));
    4. killer.getInventory().setLeggings(new ItemStack(Material.CHAINMAIL_LEGGINGS));
    5. killer.getInventory().setBoots(new ItemStack(Material.CHAINMAIL_BOOTS));
    6. ItemStack sword = new ItemStack(Material.STONE_SWORD, 1);
    7. sword.addUnsafeEnchantment(Enchantment.DURABILITY, 1);
    8. pk.addItem(sword);
    9. killer.sendMessage(ChatColor.AQUA + "You are on a" + ChatColor.GOLD + " 5 " + ChatColor.AQUA + "kill streak and have been upgraded!");
     
  12. Offline

    coasterman10

    TheAJ471 That should work, though unless you specifically want them to have diamonds showing their killstreak, it would probably be better just to store it in a Map.
     
  13. Offline

    TheAJ471

    coasterman10 Well what I have works for now so i will probably just keep it with what I have but thanks for all the help. [diamond]
     
  14. Offline

    The_Coder

    FlareLine
    I can never remember which one is which. Thanks!
     
  15. It would be a lot easier to create an int to count how many kills/deaths a player has. Whenever he dies reset the int...
     
Thread Status:
Not open for further replies.

Share This Page