Advertisement
VaynePlayer

Project Name: Shark Attack

Oct 1st, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.14 KB | None | 0 0
  1. // SHARK ID: 1608
  2.  
  3. new sharkobject;
  4. new Float: playerPos[MAX_PLAYERS][3];
  5. new thisplayerfollowingbyshark[MAX_PLAYERS];
  6. new Float: startedfollowinghere[MAX_PLAYERS][3];
  7.  
  8. stock IsPlayerSwimming(playerid)
  9. {
  10. new result = 0; // starting as player is not swimming and it will be change as 1 if player is swimming.
  11. if(GetPlayerAnimationIndex(playerid) == 1538
  12. || GetPlayerAnimationIndex(playerid) == 1539
  13. || GetPlayerAnimationIndex(playerid) == 1540
  14. || GetPlayerAnimationIndex(playerid) == 1541
  15. || GetPlayerAnimationIndex(playerid) == 1542
  16. || GetPlayerAnimationIndex(playerid) == 1543
  17. || GetPlayerAnimationIndex(playerid) == 1544
  18. || GetPlayerAnimationIndex(playerid) == 1250)
  19. {
  20. result = 1; // I found out this animations to check is player swimmming.
  21. }
  22. return result;
  23. }
  24.  
  25. forward EachSecond();
  26. public EachSecond()
  27. {
  28. foreach(Player, i) // foreach is better than counting to 500 (I mean Max players)
  29. {
  30. if(thisplayerfollowingbyshark[i] == 1)
  31. {
  32. new Float: HP;
  33. GetPlayerHealth(i, HP);
  34. SetPlayerHealth(i, HP-2); // each second a bite and each bite 2 hp.
  35. new Float: fDistance = GetPlayerDistanceFromPoint(i, startedfollowinghere[i][0], startedfollowinghere[i][1], startedfollowinghere[i][2]);
  36. if(fDistance == 40)
  37. // player got away from shark, actually got away from the shark's original position.
  38. // If That's not right, just text me to fix it, I mean If I did not get right write it :)
  39. {
  40. thisplayerfollowingbyshark[i] = 0;
  41. MoveObject(sharkobject, 884.9488,-2006.6652,-0.2070,4.0,179.5435,46,26); // let it go to it's original location
  42. }
  43. }
  44. if(IsPlayerSwimming(i)) // Firstly, we need to check this.
  45. { // Yes, player is swimming, now let's check if player is near shark
  46. new Float: x, Float: y, Float: z;
  47. GetObjectPos(sharkobject, x, y, z);
  48. if(IsPlayerInRangeOfPoint(i, 5, x, y, z)) // to stop shark
  49. {
  50. GetObjectPos(sharkobject, x, y, z);
  51. MoveObject(sharkobject, x, y, z, 4.0);
  52. }
  53. else if(IsPlayerInRangeOfPoint(i, 40, x, y, z)) // player is near shark, as you wanted 40 radius.
  54. {
  55. thisplayerfollowingbyshark[i] = 1;
  56. GetPlayerPos(i, playerPos[i][0], playerPos[i][1], playerPos[i][2]); // We got positions
  57. startedfollowinghere[i][0] = playerPos[i][0];
  58. startedfollowinghere[i][1] = playerPos[i][1];
  59. startedfollowinghere[i][2] = playerPos[i][2];
  60. MoveObject(sharkobject,playerPos[i][0], playerPos[i][1], playerPos[i][2], 4.0); // used them here
  61. // as you wanted 4.0 speed.
  62. SetObjectToFaceCords(sharkobject, playerPos[i][0], playerPos[i][1], playerPos[i][2]); // used them here, too.
  63. }
  64. }
  65. else // If Player is not swimming
  66. {
  67. if(thisplayerfollowingbyshark[i] == 1) // and if player is following by shark
  68. {
  69. thisplayerfollowingbyshark[i] = 0;
  70. MoveObject(sharkobject, 884.9488,-2006.6652,-0.2070,4.0,179.5435,46,26); // let it go to it's original location
  71. }
  72. }
  73. }
  74. return 1;
  75. }
  76.  
  77. stock SetObjectToFaceCords(objectid, Float:x1,Float:y1,Float:z1) // taken from application.
  78. {
  79. // SetObjectToFaceCords() By LucifeR //
  80.  
  81. // setting the objects cords
  82. new Float:x2,Float:y2,Float:z2;
  83. GetObjectPos(objectid, x2,y2,z2);
  84.  
  85. // setting the distance values
  86. new Float:DX = floatabs(x2-x1);
  87. new Float:DY = floatabs(y2-y1);
  88. new Float:DZ = floatabs(z2-z1);
  89.  
  90. // defining the angles and setting them to 0
  91. new Float:yaw = 0;
  92. new Float:pitch = 0;
  93.  
  94. // check that there isnt any 0 in one of the distances,
  95. // if there is any use the given parameters:
  96. if(DY == 0 || DX == 0)
  97. {
  98. if(DY == 0 && DX > 0) {
  99. yaw = 00;
  100. pitch = 0; }
  101. else if(DY == 0 && DX < 0) {
  102. yaw = 180;
  103. pitch = 180; }
  104. else if(DY > 0 && DX == 0) {
  105. yaw = 90;
  106. pitch = 90; }
  107. else if(DY < 0 && DX == 0) {
  108. yaw = 270;
  109. pitch = 270; }
  110. else if(DY == 0 && DX == 0) {
  111. yaw = 0;
  112. pitch = 0; }
  113. }
  114. // calculating the angale using atan
  115. else // non of the distances is 0.
  116. {
  117. // calculatin the angles
  118. yaw = atan(DX/DY);
  119. pitch = atan(floatsqroot(DX*DX + DZ*DZ) / DY);
  120. // there are three quarters in a circle, now i will
  121. // check wich circle this is and change the angles
  122. // according to it.
  123. if(x1 > x2 && y1 <= y2) {
  124. yaw = yaw + 90;
  125. pitch = pitch - 45; }
  126. else if(x1 <= x2 && y1 < y2) {
  127. yaw = 90 - yaw;
  128. pitch = pitch - 45; }
  129. else if(x1 < x2 && y1 >= y2) {
  130. yaw = yaw - 90;
  131. pitch = pitch - 45; }
  132. else if(x1 >= x2 && y1 > y2) {
  133. yaw = 270 - yaw;
  134. pitch = pitch + 315; }
  135.  
  136. // the pitch could be only in two quarters, lets see wich one:
  137. if(z1 < z2)
  138. pitch = 360-pitch;
  139. }
  140. // setting the object rotation (should be twice cuz of lame GTA rotation system)
  141. SetObjectRot(objectid, 0, 0, yaw);
  142. SetObjectRot(objectid, 0, pitch, yaw+90);
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement