Advertisement
RobsonSilva

Shark Attack

Oct 23rd, 2011
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.11 KB | None | 0 0
  1. // Criado por [S]trong, obrigado a LucifeR pelo SetObjectToFaceCords
  2. // Agradecimentos a [iPs] Team
  3.  
  4. #include <a_samp>
  5.  
  6. new
  7.     Shark,
  8.     Hunting;
  9.    
  10. ToFace(playerid);
  11.  
  12. SetObjectToFaceCords(objectid, Float:x1,Float:y1,Float:z1)
  13. {
  14. //   SetObjectToFaceCords() By LucifeR   //
  15. //                LucifeR@vgames.co.il   //
  16.  
  17. // setting the objects cords
  18.     new Float:x2,Float:y2,Float:z2;
  19.     GetObjectPos(objectid, x2,y2,z2);
  20.  
  21. // setting the distance values
  22.     new Float:DX = floatabs(x2-x1);
  23.     new Float:DY = floatabs(y2-y1);
  24.     new Float:DZ = floatabs(z2-z1);
  25.  
  26. // defining the angles and setting them to 0
  27.     new Float:yaw = 0;
  28.     new Float:pitch = 0;
  29.  
  30. // check that there isnt any 0 in one of the distances,
  31. // if there is any  use the given parameters:
  32.     if(DY == 0 || DX == 0) {
  33.         if(DY == 0 && DX > 0) {
  34.             yaw = 00;
  35.             pitch = 0;
  36.         }
  37.         else if(DY == 0 && DX < 0) {
  38.             yaw = 180;
  39.             pitch = 180;
  40.         }
  41.         else if(DY > 0 && DX == 0) {
  42.             yaw = 90;
  43.             pitch = 90;
  44.         }
  45.         else if(DY < 0 && DX == 0) {
  46.             yaw = 270;
  47.             pitch = 270;
  48.         }
  49.         else if(DY == 0 && DX == 0) {
  50.             yaw = 0;
  51.             pitch = 0;
  52.         }
  53.     }
  54. // calculating the angale using atan
  55.     else {                                        // non of the distances is 0.
  56. // calculatin the angles
  57.         yaw = atan(DX/DY);
  58.         pitch = atan(floatsqroot(DX*DX + DZ*DZ) / DY);
  59. // there are three quarters in a circle, now i will
  60. // check wich circle this is and change the angles
  61. // according to it.
  62.         if(x1 > x2 && y1 <= y2) {
  63.             yaw = yaw + 90;
  64.             pitch = pitch - 45;
  65.         }
  66.         else if(x1 <= x2 && y1 < y2) {
  67.             yaw = 90 - yaw;
  68.             pitch = pitch - 45;
  69.         }
  70.         else if(x1 < x2 && y1 >= y2) {
  71.             yaw = yaw - 90;
  72.             pitch = pitch - 45;
  73.         }
  74.         else if(x1 >= x2 && y1 > y2) {
  75.             yaw = 270 - yaw;
  76.             pitch = pitch + 315;
  77.         }
  78.  
  79. // the pitch could be only in two quarters, lets see wich one:
  80.         if(z1 < z2)
  81.             pitch = 360-pitch;
  82.     }
  83. // setting the object rotation (should be twice cuz of lame GTA rotation system)
  84.     SetObjectRot(objectid, 0, 0, yaw);
  85.     SetObjectRot(objectid, 0, pitch, yaw+90);
  86. }
  87.  
  88.  
  89. public OnFilterScriptInit()
  90.     return Shark = CreateObject(1608, 688.4228, -2163.0522, -0.7187, 0.0, 0.0, 80.0, 300.0);
  91.  
  92. public OnFilterScriptExit()
  93.     return 1;
  94.  
  95. public ToFace(playerid) {
  96.  
  97.     new
  98.         Float: x,
  99.         Float: y,
  100.         Float: z;
  101.  
  102.     GetObjectPos(Shark, x, y, z);
  103.    
  104.     if (IsPlayerInRangeOfPoint(playerid, 5.0, x, y, z)) {
  105.    
  106.         new
  107.             Float: h;
  108.            
  109.         GetPlayerHealth(playerid, h);
  110.         SetPlayerHealth(playerid, h - 15);
  111.        
  112.         GetPlayerPos(playerid, x, y, z);
  113.         SetObjectToFaceCords(Shark, x, y, z);
  114.        
  115.         Hunting += 1600;
  116.        
  117.         SetTimerEx("ToFace", 1500, 0, "i", playerid);
  118.         return SendClientMessage(playerid, -1, "AVISO: Você foi mordido por um tubarão, fuja rápido!");
  119.     }
  120.    
  121.     if (!IsPlayerInRangeOfPoint(playerid, 40.0, 688.4228, -2163.0522, -0.7187)) {
  122.    
  123.         new
  124.             time;
  125.  
  126.         time = MoveObject(Shark, 688.4228, -2163.0522, -0.7187, 2.5);
  127.         Hunting = gettime() + time + 50;
  128.     }
  129.    
  130.     else {
  131.    
  132.         new
  133.             time;
  134.  
  135.         GetPlayerPos(playerid, x, y, z);
  136.         time = MoveObject(Shark, x, y, z, 2.5);
  137.        
  138.         SetTimerEx("ToFace", time + 10, 0, "i", playerid);
  139.         Hunting = gettime() + time + 50;
  140.     }
  141.    
  142.     return 1;
  143. }
  144.  
  145. public OnPlayerUpdate(playerid) {
  146.  
  147.     new
  148.         anim = GetPlayerAnimationIndex(playerid);
  149.        
  150.     if (((anim == 1543 || anim == 1538 || anim == 1539)) && gettime() > (Hunting + 20)  && IsPlayerInRangeOfPoint(playerid, 40.0, 688.4228, -2163.0522, -0.7187)) {
  151.    
  152.         new
  153.             time,
  154.             Float: x,
  155.             Float: y,
  156.             Float: z;
  157.  
  158.         GetPlayerPos(playerid, x, y, z);
  159.        
  160.         time = MoveObject(Shark, x, y, z, 2.5);
  161.         SetTimerEx("ToFace", time + 10, 0, "i", playerid);
  162.        
  163.         Hunting = gettime() + time + 50;
  164.     }
  165.    
  166.     return 1;
  167. }
  168.  
  169.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement