Advertisement
S4T3K

Tank feature from GTA V to SAMP

May 24th, 2014
1,161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.55 KB | None | 0 0
  1. #include <a_samp>
  2. #include <streamer>
  3.  
  4. #define TANK (432)
  5.  
  6. native IsValidVehicle(vehicleid);
  7.  
  8. new safeVehs[] = {417, 425, 427, 428, 430, 432, 446, 447, 449, 450, 452, 453, 454, 460, 464, 469, 472, 473, 476, 484, 487, 488, 493, 497, 511, 512, 513, 519, 520, 537, 538, 548, 533,
  9.                   563, 569, 570, 577, 590, 591, 592, 593, 595, 606, 607, 608, 610, 611};
  10.  
  11. new t_tank[MAX_PLAYERS], debris[MAX_VEHICLES], vw, v;
  12.  
  13. stock Float:GetDistanceBetweenPoints(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2)
  14. {
  15.     return VectorSize(x1-x2, y1-y2, z1-z2);
  16. }
  17.  
  18. stock GetVehicleIDInRange(Float:radius, Float:x, Float:y, Float:z)
  19. {
  20.     new Float:pos[3];
  21.     for(v = 0; v < MAX_VEHICLES; v++)
  22.     {
  23.         if(!IsValidVehicle(v)) continue;
  24.         GetVehiclePos(v, pos[0], pos[1], pos[2]);
  25.         if(GetDistanceBetweenPoints(pos[0], pos[1], pos[2], x, y, z) <= radius) return v;
  26.     }
  27.     return -1;
  28. }
  29.  
  30. stock IsASafeCar(vehicleid)
  31. {
  32.     if(!IsValidVehicle(vehicleid)) return false;
  33.     for(new i = 0; i < sizeof(safeVehs); i++)
  34.     {
  35.         if(safeVehs[i] == GetVehicleModel(vehicleid)) return true;
  36.     }
  37.     return false;
  38. }
  39.  
  40. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  41. {
  42.     if(GetVehicleModel(vehicleid) == TANK) t_tank[playerid] = SetTimerEx("CheckTank", 500, true, "i", playerid);
  43.     return 1;
  44. }
  45.  
  46. public OnPlayerExitVehicle(playerid, vehicleid)
  47. {
  48.     if(GetVehicleModel(vehicleid) == TANK) KillTimer(t_tank[playerid]);
  49.     return 1;
  50. }
  51.  
  52. forward CheckTank(playerid);
  53. public CheckTank(playerid)
  54. {
  55.     new Float:pos[3];
  56.     GetVehiclePos(GetPlayerVehicleID(playerid), pos[0], pos[1], pos[2]);
  57.     if(IsAnyVehicleInRangeOfPoint(1.5, pos[0], pos[1], pos[2]))
  58.     {
  59.         v = GetVehicleIDInRange(1.5, pos[0], pos[1], pos[2]);
  60.         if(IsASafeCar(v)) return 1;
  61.         new Float:pos1[4];
  62.         GetVehiclePos(v, pos1[0], pos1[1], pos1[2]);
  63.         if(pos1[2] >= floatadd(pos[2], 1.0))
  64.         {
  65.             GetVehicleZAngle(v, pos1[3]);
  66.             vw = GetVehicleVirtualWorld(v);
  67.             if(GetVehicleModel(v) != 584)
  68.             {
  69.                 DestroyVehicle(v);
  70.                 CreateExplosion(pos1[0], pos1[1], pos1[2], 2, 10.0);
  71.                 debris[v] = CreateDynamicObject(3594, pos1[0], pos1[1], pos1[2], 0.0, 0.0, pos1[3], vw);
  72.             }
  73.             else
  74.             {
  75.                 DestroyVehicle(v);
  76.                 CreateExplosion(pos1[0], pos1[1], pos1[2], 3, 15.0);
  77.             }
  78.         }
  79.     }
  80.     return 1;
  81. }
  82.  
  83.  
  84. stock IsAnyVehicleInRangeOfPoint(Float:range, Float:x, Float:y, Float:z)
  85. {
  86.     new Float:pos[3];
  87.     for(v = 0; v < MAX_VEHICLES; v++)
  88.     {
  89.         if(!IsValidVehicle(v)) continue;
  90.         GetVehiclePos(v, pos[0], pos[1], pos[2]);
  91.         if(GetDistanceBetweenPoints(pos[0], pos[1], pos[2], x, y, z) <= range) return true;
  92.     }
  93.     return false;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement