1.8.8 Count hits of player to another player

Discussion in 'Spigot Plugin Development' started by SammyProXCoding, Sep 12, 2021.

Thread Status:
Not open for further replies.
  1. Hi!
    (Im a noob to coding currently, so i probably wont understand some things.)
    Im trying to count the hits of a player via a int variable, and want to show a scoreboard like this:

    __
    Score of Player 1: Hit count of player 1
    Score of Player 2: Hit count of player 2
    I've red about "hashmaps" but dont quite understand them. Can anyone help?
     
  2. So you don't understand HashMaps, which means you are a Java beginner. In that case, learn Java before coding a plugin - otherwise you'll stumble upon a lot of simple problems. You can't just write an essay in a language you don't know.
    Best wishes
     
    • Agree Agree x 3
    • Informative Informative x 1
    • Optimistic Optimistic x 1
  3. I rate that
     
  4. Well, my native language is not English, so i cant understand some of the tutorials. I also now know how to use hashmaps
     
  5. A Hashmap is like a phone book, it maps a key to a value, like name <> number in a phone book.
     
  6. I Stated, I learned about hashmaps yesterday ;)
     
  7. You don't need to know much english to watch the tutorials. Also, that's a motivation for you to learn English. My native language is also not English, but I have been studying it for 8 years and counting and it did give me some advantage. Lastly, you 99% can find a tutorial in your language. Cheers
     
  8. last time, already figured it out ;)
     
  9. Use EntityDamageByEntityEvent and check the player you hit name and add 1 for each hit. If you want to use HashMaps you can do so but I assume you need the number of punches saved, so save them in a config file with player uuid.
     
  10. I apologize on behalf of a great percentage of this forum. We were all beginners at one point and no one will ever learn if they're just told to learn elsewhere. Learning Java while learning Spigot API in my opinion is the best way to learn as you're being introduced to real-life scenarios.

    A Map is a type of Collection which stores entries as key->value mappings. It is basically like setting variables.

    In Java you could create a basic Map like this
    Code (Text):
    Map<UUID, Integer> map = new HashMap<>();
    A HashMap is the most basic implementation of a Map and will provide you with most likely everything you'd need for a while.

    To update the map
    Code (Text):
    map.put(uuid, 1);
    To query the map
    Code (Text):
    int hits = map.get(uuid);
    To increment (also initially puts)
    Code (Text):
    int currentHits = map.getOrDefault(uuid, 0); // returns the current value, or 0 if none
    map.put(uuid, currentHits + 1);
    Now that you understand a Map, you could implement it easily using the EntityDamageByEntityEvent
     
    • Friendly Friendly x 1
  11. ugh i already did it 3 days ago as i stated here:
     
    • Like Like x 1
  12. Please mark your thread as Solved
     
Thread Status:
Not open for further replies.