Making a hit critical

Discussion in 'Plugin Development' started by boynedmaster, May 11, 2014.

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

    boynedmaster

    Is it possible to make it so when somebody attacks, it'll always be a crit? If so, how can I do it?
     
  2. Offline

    EgyptianKing

    Critical hits deal a random amount of damage, up to 50% more, plus one heart.

    So, whenever the player hits an entity, change the damage of the sword by using a formula like this:
    (Sword Damage) *= (Random<1-50> / 100)

    After that you can use a particle library or you can use packets and give the player the critical hit particle effect each time he or she hits.

    I hope I helped, but there might be an easier way. Sorry, but I cannot post code because I do not know how to use packets yet.
     
  3. Offline

    Drkmaster83

    Here's the code for playing a "Critical" effect, the last parameter in the packet constructor is the particle amount. I put 50.
    Code:
    double random = Math.random();
    if (random < 0.37d) {
        random = 0.45d;
    }
    PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles("crit", (float) player.getLocation().getX(), (float) player.getLocation().getY(), (float) player.getLocation().getZ(), (float) random, (float) 1, (float) random, (float) 0, 50);
    for (Player p : plug.getServer().getOnlinePlayers()) {
        ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
    }
    
     
  4. Offline

    shohouku

    You could do this:

    But I'm pretty sure theres a better way.

    Code:java
    1. Random random = new Random();
    2. int randomNum = random.nextInt(100) + 1;
    3. if (randomNum <= 30) {
    4.  
    5. //do nothing
    6.  
    7. } else {
    8.  
    9. }
    10.  
    11. } else {
    12. if (randomNum <= 20) {
    13. //CRITICAL KILL PLAYER
    14.  
    15. } else {
    16.  
    17. }
    18.  
    19. } else {
    20. if (randomNum <= 90) {
    21.  
    22. //do nothing
    23.  
    24. } else {
    25.  
    26. }
    27.  
    28. } else {
    29. if (randomNum <= 60) {
    30.  
    31. //do nothing
    32.  
    33. } else {
    34.  
    35. }
    36. giveXp(p, 0.1D);
    37. giveZen(p, 15);
    38. } else {
    39. if (randomNum <= 10) {
    40.  
    41. //do nothing
    42.  
    43. } else {
    44.  
    45. }
    46.  
    47. }
     
  5. Offline

    MineStein

    With a particle burst of critical stars, maybe you could do:
    Code:java
    1. sender.getHealth() - ?;

    Note* This is pseudo-code, replace the "?" with the amount you want to subtract.

    I'm not quite sure, sorry if my method doesn't work!
     
  6. Offline

    DrEinsteinium

    MineStein Don't use that... use this:
    Code:java
    1. player.setHealth(player.getHealth() - x);
     
  7. Offline

    MineStein

  8. Offline

    boynedmaster

Thread Status:
Not open for further replies.

Share This Page