Advertisement
VaynePlayer

Project Name: Shark Attack

Oct 1st, 2014
189
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. // LucifeR@vgames.co.il //
  81.  
  82. // setting the objects cords
  83. new Float:x2,Float:y2,Float:z2;
  84. GetObjectPos(objectid, x2,y2,z2);
  85.  
  86. // setting the distance values
  87. new Float:DX = floatabs(x2-x1);
  88. new Float:DY = floatabs(y2-y1);
  89. new Float:DZ = floatabs(z2-z1);
  90.  
  91. // defining the angles and setting them to 0
  92. new Float:yaw = 0;
  93. new Float:pitch = 0;
  94.  
  95. // check that there isnt any 0 in one of the distances,
  96. // if there is any use the given parameters:
  97. if(DY == 0 || DX == 0)
  98. {
  99. if(DY == 0 && DX > 0) {
  100. yaw = 00;
  101. pitch = 0; }
  102. else if(DY == 0 && DX < 0) {
  103. yaw = 180;
  104. pitch = 180; }
  105. else if(DY > 0 && DX == 0) {
  106. yaw = 90;
  107. pitch = 90; }
  108. else if(DY < 0 && DX == 0) {
  109. yaw = 270;
  110. pitch = 270; }
  111. else if(DY == 0 && DX == 0) {
  112. yaw = 0;
  113. pitch = 0; }
  114. }
  115. // calculating the angale using atan
  116. else // non of the distances is 0.
  117. {
  118. // calculatin the angles
  119. yaw = atan(DX/DY);
  120. pitch = atan(floatsqroot(DX*DX + DZ*DZ) / DY);
  121. // there are three quarters in a circle, now i will
  122. // check wich circle this is and change the angles
  123. // according to it.
  124. if(x1 > x2 && y1 <= y2) {
  125. yaw = yaw + 90;
  126. pitch = pitch - 45; }
  127. else if(x1 <= x2 && y1 < y2) {
  128. yaw = 90 - yaw;
  129. pitch = pitch - 45; }
  130. else if(x1 < x2 && y1 >= y2) {
  131. yaw = yaw - 90;
  132. pitch = pitch - 45; }
  133. else if(x1 >= x2 && y1 > y2) {
  134. yaw = 270 - yaw;
  135. pitch = pitch + 315; }
  136.  
  137. // the pitch could be only in two quarters, lets see wich one:
  138. if(z1 < z2)
  139. pitch = 360-pitch;
  140. }
  141. // setting the object rotation (should be twice cuz of lame GTA rotation system)
  142. SetObjectRot(objectid, 0, 0, yaw);
  143. SetObjectRot(objectid, 0, pitch, yaw+90);
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement