# Making a hit critical

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

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?

#1
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.

#2
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);
}
```

#3
4. Offline

### shohouku

You could do this:

But I'm pretty sure theres a better way.

Code:java
`        Random random = new Random();                            int randomNum = random.nextInt(100) + 1;                            if (randomNum <= 30) {                              //do nothing                                 } else {                                 }                             } else {                            if (randomNum <= 20) {                           //CRITICAL KILL PLAYER                                 } else {                                 }                             } else {                  if (randomNum <= 90) {                     //do nothing                         } else {                         }                             } else {                  if (randomNum <= 60) {                     //do nothing                         } else {                         }                        giveXp(p, 0.1D);                        giveZen(p, 15);                  } else {                  if (randomNum <= 10) {                  //do nothing                         } else {                         }                   }`

#4
5. Offline

### MineStein

With a particle burst of critical stars, maybe you could do:
Code:java
`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!

#5
6. Offline

### DrEinsteinium

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

#6
7. Offline

#7
8. Offline

Thanks

#8