Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. public override bool PreAI()
  2. {
  3. if (npc.ai[3] > 0)
  4. npc.realLife = (int)npc.ai[3];
  5. if (npc.target < 0 || npc.target == byte.MaxValue || Main.player[npc.target].dead)
  6. npc.TargetClosest(true);
  7. if (Main.player[npc.target].dead && npc.timeLeft > 300)
  8. npc.timeLeft = 300;
  9.  
  10. if (Main.netMode != 1)
  11. {
  12. if (!Main.npc[(int)npc.ai[1]].active)
  13. {
  14. npc.life = 0;
  15. npc.HitEffect(0, 10.0);
  16. npc.active = false;
  17. NetMessage.SendData(28, -1, -1, "", npc.whoAmI, -1f, 0.0f, 0.0f, 0, 0, 0);
  18. }
  19. }
  20.  
  21. if (npc.ai[1] < (double)Main.npc.Length)
  22. {
  23. // We're getting the center of this NPC.
  24. Vector2 npcCenter = new Vector2(npc.position.X + (float)npc.width * 0.5f, npc.position.Y + (float)npc.height * 0.5f);
  25. // Then using that center, we calculate the direction towards the 'parent NPC' of this NPC.
  26. float dirX = Main.npc[(int)npc.ai[1]].position.X + (float)(Main.npc[(int)npc.ai[1]].width / 2) - npcCenter.X;
  27. float dirY = Main.npc[(int)npc.ai[1]].position.Y + (float)(Main.npc[(int)npc.ai[1]].height / 2) - npcCenter.Y;
  28. // We then use Atan2 to get a correct rotation towards that parent NPC.
  29. npc.rotation = (float)Math.Atan2(dirY, dirX) + 1.57f;
  30. // We also get the length of the direction vector.
  31. float length = (float)Math.Sqrt(dirX * dirX + dirY * dirY);
  32. // We calculate a new, correct distance.
  33. float dist = (length - (float)npc.width) / length;
  34. float posX = dirX * dist;
  35. float posY = dirY * dist;
  36.  
  37. // Reset the velocity of this NPC, because we don't want it to move on its own
  38. npc.velocity = Vector2.Zero;
  39. // And set this NPCs position accordingly to that of this NPCs parent NPC.
  40. npc.position.X = npc.position.X + posX;
  41. npc.position.Y = npc.position.Y + posY;
  42. }
  43. return false;
  44. }
  45.  
  46. public override void AI()
  47. {
  48. npc.ai[0]++;
  49. Player P = Main.player[npc.target];
  50. if (npc.target < 0 || npc.target == 255 || Main.player[npc.target].dead || !Main.player[npc.target].active)
  51. {
  52. npc.TargetClosest(true);
  53. }
  54. npc.netUpdate = true;
  55.  
  56. npc.ai[1]++;
  57. if (npc.ai[1] >= Main.rand.Next(800, 1200)) //800 is projectile fire rate
  58. {
  59. Main.NewText("DEBUG");
  60. float Speed = 10f; //projectile speed
  61. Vector2 vector8 = new Vector2(npc.position.X + (npc.width / 2), npc.position.Y + (npc.height / 2));
  62. int damage = 100; //projectile damage
  63. int type = mod.ProjectileType("SuperVileSpit"); //put your projectile name here
  64. Main.PlaySound(SoundID.NPCHit8);
  65. float rotation = (float)Math.Atan2(npc.Center.Y - (P.position.Y + (P.height * 0.5f)), npc.Center.X - (P.position.X + (P.width * 0.5f)));
  66. int num54 = Projectile.NewProjectile(npc.Center.X, npc.Center.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 0f, 0);
  67. npc.ai[1] = 0;
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement