How to detect who made first hit in PvP?

Discussion in 'Spigot Plugin Development' started by RokkoEffe, May 1, 2017.

  1. I have to detect a player, who made first hit in PvP. For example:
    When one player kills other player, I have to detect, who made first hit in their battle.
     
    • Optimistic Optimistic x 1
  2. Have an event so, when a player hits another player, put them in a list, and if one of them dies you have the player who hit first.
     
  3. No, you didn't understand me. I want to detect who started the battle, who made first hit, first strike, who is agressor.
     
    • Optimistic Optimistic x 1
  4. I think he does understand, he's saying that when a player attacks another player, store the attacker somewhere, and when you want to check who attacked first, you can retrieve the attacker from wherever you stored it
     
  5. Ok, but can you explain me what is "list" and how it should look in code? And are there any other ways? I'm a beginner in Java. (and english:))
     
    • Optimistic Optimistic x 1
  6. You should really learn basic Java if you don't understand what a List is. Spigot is written in Java, so it will truly benefit you in the long run before trying to write something in a language you can't write in. I know others will agree with me, just from personal experience. Time and time again there are threads similar to this, and even myself initially felt like I could do it without proper Java knowledge, but it only came to hurt me long term, and I lost a lot of time.

    Just search some beginner series and get used to the fundamentals of the language and get comfortable enough to write and read basic programs. I promise it will do a lot for you.
     
    • Agree Agree x 4
    • Optimistic Optimistic x 1
  7. Why use a list? How about a HashMap, and then you can store a Long variable to check if like, 15 minutes has pasted since the last battle
     
    • Informative Informative x 1
  8. I didn't mean just a java List object specifically, I meant a list as an array of items generally, it could be a List, HashMap, or a custom list. Sorry if it didn't sound that way.