Advertisement
RobsonSilva

Shark Attack

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