Damage advice!

Discussion in 'Plugin Development' started by mrgreen33gamer, Jan 2, 2015.

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

    mrgreen33gamer

    Alright guys, I need some advice!

    So, I am a KitPvP coder, nearly ALL of my code realize on me to use a Damage event. What I have noticed in the passed 2 months is that if a player is attacked by another player, if the player being damaged waits about 5 seconds without typing /kill, the other player doesn't get the kill. Don't understand? Let me explain:

    If someone was to be damaged by a player and typed /kill within a type period of 2 seconds of the attack, it counts as a kill, even without a custom code. Now, if that player waited about 7+ seconds, and they type: /kill. Then it doesn't count as a kill. So what am I trying to get to?

    Well, I want to manipulate the amount of time a player has till they can die WITHOUT it counting as a kill.

    Anyone got an idea how I can manipulate this? Or how to extend the time?

    ~mrgreen33gamer
     
  2. Offline

    Gamesareme

    @mrgreen33gamer Well, when a player gets damaged add them to a map, with the player that damaged them. Then have a count down that goes for how long you want, then remove the player from the map. Then have a check, when a player dies and see if they are in the map. If they are give the kill to the player that hurt the other, also saved in the map. If the player hurt is not in the map, then they were not killed by any one.
     
  3. Offline

    mrgreen33gamer

    @Gamesareme That's a good idea, but a problem with this is, if I do that and add a countdown to removed them, every single time I hit them they're added to the map and the a message might spam!
     
  4. Offline

    Konato_K

    @mrgreen33gamer You don't need a countdown, you can store a long with the time they were hit, when they are hit again just put the new time in the map, if they die then get the long and compare the time difference
     
  5. Offline

    nj2miami

    Why would a message spam "on hit"? Run a scheduled task to check the contents on the map and remove any which are expired. For instance, if you want kills to "count" for 15 seconds, run the timer every second and remove any which have been there for > 15.

    The simplest way is TWO maps.

    Timing Map -> Map<UUID, Long> - UUID of player who was hit and Long with the time they were hit
    Hit tracker -> Map<UUID, UUID> First UUID is the player who was hit, second being who hit them.

    Now when a player dies, see if they are in the first Map and make sure they are within your time frame, then pull the UUID of the player who last hit them from the second map.

    For tidiness, I would remove the player from both maps on death as well even though your scheduler should be grabbing them but if a player died once by a player and then say by falling before being cleared you could get instances where a player gets credit for a kill which wasn't theirs. (Small chance but better to be clean.)
     
Thread Status:
Not open for further replies.

Share This Page