Increase PvP reach with a plugin

Discussion in 'Plugin Development' started by Huskije, Oct 17, 2017.

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

    Huskije

    Hey,
    The title is pretty clear.How could I possibly increase the pvp reach so I could hit an entity say 5 blocks away (instead of the default 3).
    The thing is the entity has to get knocked back depending on the position of the attacker, exactly like if I were to hit you 2 blocks away.
    Could I do this with packets (I don't know much about packets) ?
    check if an entity is <5 blocks away from me, check if i'm looking at it, and then send a hit packet? (taking into consideration our positions, as it would be weird if i hit you from in front and you take forward knockback)

    TL;DR how do I increase reach so I can hit entities from more than the default 3 blocks ?

    Hope it's pretty clear, cheers.
     
  2. Check distance from player to target, check if is in line of sight (gl) and then just damage the player and set their velocity to something (you can make it so they are knocked away from the player).

    Good luck :)
     
    Huskije likes this.
  3. Offline

    MightyOne

    Damaging a player has nothing to do with client side. So you do not have to use any packets.
    The interesting part will be to find out which body part got hit :D
     
    Last edited: Oct 17, 2017
    Huskije likes this.
  4. Offline

    Zombie_Striker

    @Sulphate
    LineOfSight checks if the entity is within 45° of the direct line of sight.

    @Huskije
    1. On Player Interact Event
    2. Create a new Vector. This will be equal to the the direction the player is looking.
    3. Create a new location. This will be equal to the player's eye level.
    4. Create a for double loop. Loop up to 6 (or the max distance you want to check). Each time it loops, increase the double by 0.25. This make sure the check is more accurate.
    5. Add the Vector to the location.
    6. If the block's type at that location is not solid.
    7. Get the nearby entities with a range of 0.6.
    8. If there is an entity in that list, then the player was most likely attacking that target (If you want to be more precise, you can add bounding box for more accuracy)
    9. Then damage the entity using Entity#damage(Damager);
     
    Sulphate and Huskije like this.
  5. Offline

    Huskije

    Definately making this when I get home.Cheers @Zombie_Striker !
     
  6. Offline

    MightyOne

  7. Offline

    Zombie_Striker

    @MightyOne
    1. Get the player's "location", which is the center of the player at their feet.
    2. Get the min corner by subtracting 0.47, 0, 0.47 from the XYZ respectively. (0.47 for XZ because the player is not exactly 1 block wide.)
    3. Get the max by adding 0.47, 1.8 ,0.47 to the XYZ respectively. (1.8 because the player is not exactly 2 blocks tall)
    4. If the location you're testing for is within those two values, then you are looking directly at the player.
     
  8. Offline

    MightyOne

    @Zombie_Striker Just asking because there is this ((CraftPlayer) player).getHandle().getBoundingBox() or something like this
     
  9. Offline

    Zombie_Striker

    @MightyOne
    True, but that requires NMS, which makes it version dependent (unless you use reflection, and then it just gets complicated)
     
  10. Offline

    MightyOne

    @Zombie_Striker well now where I have worked a little with NMS ifd actually lile to try out reflection
     
Thread Status:
Not open for further replies.

Share This Page