Advertisement
Ghecco

Algoritmo-Copchase + test (testing)

Nov 3rd, 2020
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.51 KB | None | 0 0
  1. /*
  2.         Algoritmo posizionamento veicoli copchase
  3.                                                         */
  4.  
  5. #include <a_samp>
  6. #include <Pawn.CMD>
  7.  
  8. #define DISTANZA_FUGGITIVO              (10.5)
  9. #define DISTANZA_FILA_POLIZIA            (5.5)
  10.  
  11.  
  12.  
  13. main(){}
  14.  
  15.  
  16.  
  17. public OnPlayerText(playerid, text[])
  18. {
  19.     if(IsPlayerInAnyVehicle(playerid))
  20.     {
  21.         new Float:x, Float:y, Float:z, Float:angle;
  22.         new veh = GetPlayerVehicleID(playerid);
  23.         AlgoritmoCopchase(veh, strval(text), x, y, z, angle);
  24.         CreateVehicle(400, x, y, z, angle, -1, -1, 0);
  25.     }
  26.     new Float:gx, Float:gy, Float:gz;
  27.     GetPlayerPos(playerid, gx, gy, gz);
  28.     CreateVehicle(400, gx, gy, gz, 0.0, -1, -1, 0);
  29.  
  30.     return 1;
  31. }
  32. new counter = 1;
  33. CMD:c(playerid, params[])
  34. {
  35.      new Float:x, Float:y, Float:z, Float:angle;
  36.     new veh = GetPlayerVehicleID(playerid);
  37.     AlgoritmoCopchase(veh, counter, x, y, z, angle);
  38.     CreateVehicle(400, x, y, z, angle, -1, -1, 0);
  39.     counter++;
  40.     return 1;
  41. }
  42.  
  43.  
  44. stock AlgoritmoCopchase(vid_fuggitivo, numeroPosizioneID, &Float:ret_x, &Float:ret_y, &Float:ret_z, &Float:ret_angle)
  45. {
  46.     new Float:fuggitivo_x, Float:fuggitivo_y, Float:fuggitivo_z, Float:fuggitivo_angolazione;
  47.     GetVehiclePos(vid_fuggitivo, fuggitivo_x, fuggitivo_y, fuggitivo_z);
  48.     GetVehicleZAngle(vid_fuggitivo, fuggitivo_angolazione);
  49.    
  50.     GetSideOfVehicle(vid_fuggitivo, 0, DISTANZA_FUGGITIVO, fuggitivo_x, fuggitivo_y, fuggitivo_z, fuggitivo_angolazione);
  51.  
  52.  
  53.  
  54.     new posizione, linea, Float:poliziotto_x, Float:poliziotto_y, Float:poliziotto_z;
  55.     GetPosizioneLinea(numeroPosizioneID, posizione, linea);
  56.     switch(posizione)
  57.     {
  58.         case 1:GetSideOfPos(poliziotto_x, poliziotto_y, poliziotto_z,fuggitivo_x, fuggitivo_y, fuggitivo_z, fuggitivo_angolazione, 2, 8, linea);
  59.         case 2:GetSideOfPos(poliziotto_x, poliziotto_y, poliziotto_z,fuggitivo_x, fuggitivo_y, fuggitivo_z, fuggitivo_angolazione, 2, 4, linea);
  60.         case 3:GetSideOfPos(poliziotto_x, poliziotto_y, poliziotto_z, fuggitivo_x, fuggitivo_y, fuggitivo_z, fuggitivo_angolazione, 0, 0 , linea);
  61.         case 4:GetSideOfPos(poliziotto_x, poliziotto_y, poliziotto_z,fuggitivo_x, fuggitivo_y, fuggitivo_z, fuggitivo_angolazione, 3, 4, linea);
  62.         case 5:GetSideOfPos(poliziotto_x, poliziotto_y, poliziotto_z,fuggitivo_x, fuggitivo_y, fuggitivo_z, fuggitivo_angolazione, 3, 8, linea);
  63.    
  64.  
  65.     }
  66.  
  67.     ret_x = poliziotto_x;
  68.     ret_y = poliziotto_y;
  69.     ret_z = poliziotto_z;
  70.     ret_angle = fuggitivo_angolazione;
  71.     return 1;
  72. }
  73.  
  74.  
  75. stock GetPosizioneLinea(numeroPosizione, &posizione, &linea)
  76. {
  77.     new numeroMinore = 1, numeroMaggiore = 5, linea_n = 1;
  78.     for ( ; ; )
  79.     {
  80.         if(numeroPosizione >= numeroMinore && numeroPosizione <= numeroMaggiore)
  81.         {
  82.             if(linea_n == 1) posizione = numeroPosizione;
  83.             else posizione = numeroPosizione -= (5*(linea_n-1));
  84.             linea = linea_n;
  85.             break;
  86.         }
  87.         else
  88.         {
  89.             numeroMinore += 5;
  90.             numeroMaggiore += 5;
  91.         }
  92.         linea_n ++;
  93.     }
  94.     return 1;
  95. }
  96.  
  97.  
  98. stock GetSideOfPos(&Float:x, &Float:y, &Float:z, Float:distanza_x, Float:distanza_y, Float:distanza_z, Float:angle, side, Float:distance, linea) // Funzione per ottenere il backside di un veicolo
  99. {      
  100.  
  101.     x = distanza_x;
  102.     y = distanza_y;
  103.     z = distanza_z;
  104.  
  105.  
  106.         x -= ((DISTANZA_FILA_POLIZIA*linea) * floatsin(-angle, degrees));
  107.         y -= ((DISTANZA_FILA_POLIZIA*linea) * floatcos(-angle, degrees));
  108.    
  109.  
  110.  
  111.     switch(side) // 0 back | 1 front | 2 sx | 3 dx
  112.     {
  113.         case 0: // backside
  114.         {
  115.             x -= (distance * floatsin(-angle, degrees));
  116.             y -= (distance * floatcos(-angle, degrees));
  117.  
  118.         }
  119.         case 1: // backside
  120.         {
  121.             x -= (distance * floatsin(angle, degrees));
  122.             y -= (distance * floatcos(angle, degrees));
  123.  
  124.         }
  125.         case 2:
  126.         {
  127.  
  128.             //angle= angle+90.0;
  129.  
  130.             x += (distance * floatsin(-angle-90, degrees));
  131.             y += (distance * floatcos(-angle-90, degrees));
  132.  
  133.             //angle = angle - 90.0;
  134.    
  135.         }
  136.           case 3:
  137.         {
  138.  
  139.             //angle= angle+90.0;
  140.  
  141.             x += (distance * floatsin(-angle+90, degrees));
  142.             y += (distance * floatcos(-angle+90, degrees));
  143.  
  144.            // angle = angle - 90.0;
  145.    
  146.         }
  147.     }
  148.     return 1;
  149. }
  150.  
  151.  
  152.  
  153. stock GetSideOfVehicle(vehicleid, side, Float:distance, &Float:x, &Float:y, &Float:z, &Float:angle) // Funzione per ottenere il backside di un veicolo
  154. {      
  155.     GetVehiclePos(vehicleid, x, y, z);
  156.     GetVehicleZAngle(vehicleid, angle);
  157.  
  158.     switch(side) // 0 back | 1 front | 2 sx | 3 dx
  159.     {
  160.         case 0: // backside
  161.         {
  162.             x -= (distance * floatsin(-angle, degrees));
  163.             y -= (distance * floatcos(-angle, degrees));
  164.  
  165.             GetVehicleZAngle(vehicleid, angle);
  166.         }
  167.         case 1: // backside
  168.         {
  169.             x -= (distance * floatsin(angle, degrees));
  170.             y -= (distance * floatcos(angle, degrees));
  171.  
  172.             GetVehicleZAngle(vehicleid, angle);
  173.         }
  174.         case 2:
  175.         {
  176.  
  177.             angle= angle+90.0;
  178.  
  179.             x += (distance * floatsin(-angle, degrees));
  180.             y += (distance * floatcos(-angle, degrees));
  181.  
  182.             angle = angle - 90.0;
  183.    
  184.         }
  185.           case 3:
  186.         {
  187.  
  188.             angle= angle+90.0;
  189.  
  190.             x += (distance * floatsin(angle, degrees));
  191.             y += (distance * floatcos(angle, degrees));
  192.  
  193.             angle = angle - 90.0;
  194.    
  195.         }
  196.     }
  197.     return 1;
  198. }
  199.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement