Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var larm;
- var larm2;
- var rarm;
- var rarm2;
- var body;
- var body2;
- var lleg;
- var lleg2;
- var rleg;
- var rleg2;
- var head;
- var head2; // all these variables are just for testing puppet animations
- /*function died(event){
- event.npc.timers.stop(9241)
- }*/
- // 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.
- // 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.
- function meleeAttack(event){
- 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
- rarm = event.npc.job.getPart(2) // right arm starting animation
- rarm2 = event.npc.job.getPart(8) // right arm ending animation
- rarm.setRotation(126,177,294);
- rarm2.setRotation(180,180,180);
- 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
- event.npc.timers.forceStart(9238,20,false); // backswing animation length
- event.npc.timers.forceStart(9241,20,false); // timer to reset attack values to normal
- event.npc.timers.reset(9245)
- } else {
- if(event.npc.timers.has(9245)){ // this forces the npc to not do an attack while their miss cooldown is active
- rarm = event.npc.job.getPart(2) // right arm starting animation
- rarm2 = event.npc.job.getPart(8) // right arm ending animation
- rarm.setRotation(175,175,175);
- rarm2.setRotation(185,185,185);
- event.npc.updateClient();
- event.setCanceled(true)
- event.npc.say("My attack is on cooldown") // debug for checking how many times they attack during their miss cooldown, not really important
- } else {
- rarm = event.npc.job.getPart(2) // right arm starting animation
- rarm2 = event.npc.job.getPart(8) // right arm ending animation
- rarm.setRotation(20,177,111);
- rarm2.setRotation(159,177,126);
- event.npc.updateClient();
- event.npc.say("I strike!")
- var m = event.npc.getStats().getMelee();
- m.setDelay(45); // this is the attack cooldown after they successfully hit their target
- 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.
- 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.
- var n = event.npc.getAi()
- n.setWalkingSpeed(3) // slow down or speed up the npc while they swing their weapon if desired
- 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
- event.npc.timers.forceStart(9238,25,false); // animation length
- 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.
- 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
- }
- }
- } function timer(event){
- 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.
- rarm = event.npc.job.getPart(2)
- rarm2 = event.npc.job.getPart(8)
- 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
- rarm2.setRotation(185,185,185);
- event.npc.updateClient();
- }
- if(event.id == 9241){ // this resets the npc melee stats so when they do the attack to do their animation there is no damage
- var m = event.npc.getStats().getMelee();
- 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
- m.setStrength(0); // keep this at 0 otherwise the npc will deal damage as they start their animation
- 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.
- var n = event.npc.getAi()
- n.setWalkingSpeed(4) // make npc walk normal speed again after finishing attack
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement