Advertisement
Guest User

Npc attack animation script

a guest
Jun 2nd, 2019
3,627
-1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.30 KB | None | 0 1
  1. var larm;
  2. var larm2;
  3. var rarm;
  4. var rarm2;
  5. var body;
  6. var body2;
  7. var lleg;
  8. var lleg2;
  9. var rleg;
  10. var rleg2;
  11. var head;
  12. var head2; // all these variables are just for testing puppet animations
  13. /*function died(event){
  14. event.npc.timers.stop(9241)
  15. }*/
  16. // the holy script of npc attack animation, make sure the npc has the puppet job and is animated, you can edit the setRotation() values as you please to change what type of animation the npc performs, as well as change animation speed with the npc wand to try and create your own perfect animation.
  17. // in this example script the values are set to a npc who would swing a large weapon slowly, i used a npc holding a iron greatsword from variedcommodities, to use this script for other types of attacks modify the values as necessary, hopefully i labelled each part correctly.
  18. function meleeAttack(event){
  19. if(event.npc.timers.has(9244)) { // this cancels an attack animation on the attack that actually deals damage to prevent weird animations. However in this case i have used it to create a "backswing" animation when the npc hits you. You can customize this animation or set the values for rarm and rarm2 to 180 to just reset the animation to neutral
  20. rarm = event.npc.job.getPart(2) // right arm starting animation
  21. rarm2 = event.npc.job.getPart(8) // right arm ending animation
  22. rarm.setRotation(126,177,294);
  23. rarm2.setRotation(180,180,180);
  24. event.npc.updateClient(); // if modifying this script always have these events after the setRotation changes as these ensure that the npc immediately performs their animation, otherwise there is a random amount of delay
  25. event.npc.timers.forceStart(9238,20,false); // backswing animation length
  26. event.npc.timers.forceStart(9241,20,false); // timer to reset attack values to normal
  27. event.npc.timers.reset(9245)
  28. } else {
  29. if(event.npc.timers.has(9245)){ // this forces the npc to not do an attack while their miss cooldown is active
  30. rarm = event.npc.job.getPart(2) // right arm starting animation
  31. rarm2 = event.npc.job.getPart(8) // right arm ending animation
  32. rarm.setRotation(175,175,175);
  33. rarm2.setRotation(185,185,185);
  34. event.npc.updateClient();
  35. event.setCanceled(true)
  36. event.npc.say("My attack is on cooldown") // debug for checking how many times they attack during their miss cooldown, not really important
  37. } else {
  38. rarm = event.npc.job.getPart(2) // right arm starting animation
  39. rarm2 = event.npc.job.getPart(8) // right arm ending animation
  40. rarm.setRotation(20,177,111);
  41. rarm2.setRotation(159,177,126);
  42. event.npc.updateClient();
  43. event.npc.say("I strike!")
  44. var m = event.npc.getStats().getMelee();
  45. m.setDelay(45); // this is the attack cooldown after they successfully hit their target
  46. m.setStrength(8); // damage the npc will do on their actual attack that should occur roughly around when their attack animation would collide with their target.
  47. m.setRange(2); // how far away they can deal damage to their target, set to smaller if the npc has a small weapon, and larger if the npc has a larger weapon.
  48. var n = event.npc.getAi()
  49. n.setWalkingSpeed(3) // slow down or speed up the npc while they swing their weapon if desired
  50. event.npc.timers.forceStart(9244,20,false); // time for the npc to do a second animation on hitting you, make sure this isnt lower than the npc default attack delay which is set by timer 9241 otherwise the npc will be unable to actually hurt you
  51. event.npc.timers.forceStart(9238,25,false); // animation length
  52. event.npc.timers.forceStart(9241,21,false); // timer to reset attack if the npc hits you this will be reset again, this makes it so that if the npc misses their melee stats are set back to normal, and if they hit you they are also set back to normal.
  53. event.npc.timers.forceStart(9245,45,false); // timer that forces an attack cooldown if their attack misses, make sure this is same as the setDelay() of the attacks if you want to keep the same cooldown for an attack missed or attack hit
  54. }
  55. }
  56. } function timer(event){
  57. if(event.id == 9238){ // this sets the npc right arm limb to a default position, giving it a sort of a stiff-arm, since setting the right arm to 'disabled' in the script causes the npc to have their NBT data updated which messes up their AI briefly, causing many problems with targetting and general movement.
  58. rarm = event.npc.job.getPart(2)
  59. rarm2 = event.npc.job.getPart(8)
  60. rarm.setRotation(175,175,175); // a minor difference in the start and end setRotation() values can make a small bit of movement that offsets the stiff-arm look
  61. rarm2.setRotation(185,185,185);
  62. event.npc.updateClient();
  63. }
  64. if(event.id == 9241){ // this resets the npc melee stats so when they do the attack to do their animation there is no damage
  65. var m = event.npc.getStats().getMelee();
  66. m.setDelay(20); // set this to the time you want the npc to deal damage to you, so in this case, around the time where the npc attack animation is colliding with their target, experiment with this to find what suits your attack animation best
  67. m.setStrength(0); // keep this at 0 otherwise the npc will deal damage as they start their animation
  68. m.setRange(2); // this will be the range at which the npc will start doing their animation as an attack, set to higher if you want the npc to start doing their animation as they approach a target.
  69. var n = event.npc.getAi()
  70. n.setWalkingSpeed(4) // make npc walk normal speed again after finishing attack
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement