Advanced MATH, credits based on hits

Discussion in 'Plugin Development' started by 8803286, May 1, 2014.

Thread Status:
Not open for further replies.
  1. Hello,

    i think the title explains it all.

    KitPvP.com has the credit system (just saying) so you can look there if you don't understand what i'm saying

    //here is the loop that counts how many times you have hitted a specefic player
    //This loop will say how many times a player got hit
    for(Entry<UUID, Integer> cp : pl.entrySet()){ //pl is just a HashMap
    Bukkit.broadcastMessage(p.getName()+"..."+cp.getValue());
    }

    Max credits for each player is 40
    so if p1 hit p2 20 times
    and p3 hit p2 20 times and p2 die both p1 and p3 will get 20 credits

    I'm sorry if you don't understand this, i've tryed my best to explain
     
  2. Offline

    Garris0n

    So what are you asking? You've simply stated a bunch of facts about some server's KitPvP plugin.
     
  3. Offline

    Pew446

    Create a HashMap<UUID, HashMap<UUID, Integer>>. Every time a player joins the server, if they don't already have a record in the HashMap, add them like
    Code:java
    1. map.put(player.getUniqueId(), new HashMap<UUID, Integer>())


    The inner hasmap (with the Integer) will count how many times the player has been hit, and by who. So, when p1 hits p2, if p1 already has an entry in p2's integer map, add one to the value of p1's entry. If not, add p1's uuid to p2's entry with the integer = 1. Same with p3.

    When p2 dies, go through each uuid in their map, sum up all the values, then divide it out by giving each player:

    p1, for example:
    40 * (p1Value/TotalOfAllValues)
    The way this works is like this.. Let's say p1 hit p2 8 times and p3 hit p2 2 times.
    The total of the hits is 10. Let's calculate how much points p1 will get: 40 * (8/10) = 32.
    P1 gets 32 points.
    Now for P3: 40 * (2/10) = 8.
    P3 gets 8 points.
    That adds to 40.

    Then reset p2's hashmap so that all the values of the players who hit him reset.

    Hope this made any sense. Think about it.

    Not very advanced math, by the way.
     
  4. Thanks, Pew
     
    Pew446 likes this.
Thread Status:
Not open for further replies.

Share This Page