Identify when a hit is a critical hit

Discussion in 'Plugin Development' started by Zidkon, Oct 16, 2012.

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

    Zidkon

    As most of you know, minecraft PvP have Critical Hits, when player is falling and hits, and it occurs not 100% of times (as my testing gone or is really difficult to get 100% of times xD), anyway this is all calculated inside the server based on the actions of the player.

    My question is if there is any way to identify when a hit was a critical hit. I was checking the events, and the only one that is close to identify player vs player hits is EntityDamageByEntityEvent, and I can identify that the DamageCause was an ENTITY_ATTACK and as well I can get the damage but is a waste of code to check wich one was the weapon, material and damage, only to check if it was a critical hit, not mentioning I'm not sure if the damage I will get at that event have already the armor resistance calculated so is pretty complicated (but possible) to check all that only to see if it was a critical hit.

    So is there any other way to identify if the hit was a critical hit? or should I open a leaky to ask Bukkit Dev to add support to identify critical hits?

    Oh also, is there a way to cancel them? so the effect and all is cancelled too?

    Thanks for answers and support :D sorry for my english btw.

    Sorry for bump so early but i think this topic may be of interest for more than one :p

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  2. Offline

    gcflames5

    Are you sure vanilla Minecraft has critical hits?
     
  3. Offline

    Codex Arcanum

    Yes.
     
  4. Offline

    Hoolean

    I would also be interested in finding out if this is possible!
     
  5. Offline

    Deleted user

    MrBluebear3
    Zidkon

    Well this may not be the best or even the most efficient way of doing this but it would definitely work..
    When a player hits something get the item in there hand and then get the amount of damage was done the the entity this would of course all have to be done through the EntityDamageEvent I believe then you can get the attacker and what not. Anyways get the item and then you know lets say the attacker is holding a diamond sword, well on a regular diamond sword hit it will only deal 3 1/2 hearts of damage well check to see how much damage was done and if it was more then 3 1/2 hearts it was a critical hit.

    EDIT:
    Nvm this won't work it doesn't account for armor.
     
  6. Offline

    Zidkon

    I said is possible if we calculate both players weapon and armor, since is easy to get the initial damage, but the code gets too long, and is stupid since the server already made the checks to know that it was a critical hit.

    It would be nice if Bukkit adds support in the EntityDamageByEntityEvent about critical hit, and could cancel the critical hit. More usefull, it would be nice if we could make by code a critical hit possible, like setting the damage like a critical hit, so it will not be exactly needed that the player is falling and hit to make the effect of a critical hit.

    I don't think the trigger of the effect is clientside but I'm not sure :(
     
  7. Offline

    xGamingDudex

    The critical hist only occurs when the player that is hitting some one is falling. You have probably seen that players jumping in pvp. This is so that when you fall from the jump you deal critical hist, not when you are going upwards from the jump. You could then check the velocity and see if the player is falling=)
     
  8. Offline

    TwistedMexi

  9. Offline

    Zidkon

    I'm sorry I didn't get it all, is that the implementation of critical damage by steffengy? Then could be an option, as well if its necesary to implement it on code then I will try make a leaky about it since Bukkit itself doesn't support it.

    Thanks for your answer

    Well what about that is not 100% of times? I did a test and either I couldn't make it 100% of times or it didn't success 100% of times I cannot really say wich one is, or both of them, so I guess it would be dumb to check it without testing it further, not to mention Bukkit Server already make this check (I guess since I supose the critical is serverside), it would be like repeating the check when is not necesary when it could be implemented on the server files instead.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  10. Offline

    Allov

    Have you found a way yet?
     
  11. Offline

    NinjaW0lf

    Thisis possible, Take a look at how nocheatplus handles this. they have a custom boolean onGround(or it might be isGround) to check if player got a critical. Take a look at their critical hit check.

    NocheatPlus

    This is probably the best way your going to be able to get whether it was a critical.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  12. Offline

    Allov

    Yet, you have to know if the player is "droping" right? There must be something in Minecraft for that, I mean there's feedback on the client (stars showing).

    But, detecting if the player is on the ground may be the best way for now.
     
  13. Offline

    NinjaW0lf

    yea, that method is the best shot. it accounts for mostly everything
     
  14. Offline

    Zidkon

    Well, about the critical hit that I studied is that, when you are on the air and u are falling, you will not have 100% success having a critical hit.

    If there is no direct way by bukkit, I think the best way is to make the calculus of the damage, based on the weapon and the armor, plus the potions the person have, and checking if the damage is higher than the one you made, and you can calculate too the critical damage, there is a formula I think it is half plus 2.

    Because if you are going to check if the player is on ground or not, you are just Checking if the critical hit was possible or not, is like "oh he made a critical hit, lets see if he was on ground to see if he is hacking", but I think its impossible for a hacking client to make a critical hit, since the server is the one who manages all that.
     
  15. Offline

    NinjaW0lf

    hacking clients send packets to the server to fake criticals.

    IIRC if ur fly boolean was tru, u always got a crit. it was just the damage that was random. could be wrong.
    ill try testing something later.
     
  16. Offline

    Zidkon

    It is supposed that the critical hit is made when you perform a hit when you are falling, but it doesnt succed 100% of times, I think server manage the flying thing very well since they recognize when someone is flying too fast (of course some times its a mistake), so if you have a client that sends to the server that you are on ground and just before you hit u are falling, it will recognize a mistake on the logic, you first must jump and then it will recognize your falling, or something like that?

    Well I don't know how server check this all, but certainly is possible to check.
     
  17. Offline

    fireblast709

    when you fail to land a critical hit, is that not due yourself instead of the client?
     
  18. Offline

    Zidkon

    You suggest the client didn't send information correctly to the server?

    Well I tested it on my LAN server, so I don't know how much accurate the client can be.
     
  19. Offline

    Allov

    I used the PlayerMoveEvent to detect if the player is falling (locationY - lastLocationY > 0). I'm not sure if it's efficient performance wise, I could use a scheduled task to verify every X millis instead.

    Anyway, it works fine. I didn't see any problems not detecting crits (either server side or client side). I can post the code if you like. I'll do that once I get home tonight.
     
  20. Offline

    Zidkon

    That'd be great, I think u don't need to check each milli second, its dumb since the event is triggered every time it receives packets with movements, so check every interval of time is just useless and probably will do more process than needed.
     
Thread Status:
Not open for further replies.

Share This Page