Guest User

[Include] Radar Veicular

a guest
Jun 6th, 2011
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.24 KB | None | 0 0
  1. /*
  2. *
  3. *   -=Maior Moral =-
  4. *   Larceny Radar Veícular
  5. *
  6. *   Autor: Larceny
  7. *
  8. */
  9. #include "a_samp"
  10.  
  11. #define MAX_Radar 100
  12. #define LR_TEMPO_CHECAGEM 1500 // Tempo em milisegundos.
  13.  
  14. /*Lista de funções do sistema LR -----------------------------------------------------------------------------||
  15.  
  16. native lr_CriarRadar(Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, virtualword = -1);
  17. native lr_DestruirRadar(lrid);
  18. native lr_RadarExiste(lrid);
  19. native lr_MudarPosRadar(lrid, Float:x, Float:y, Float:z);
  20. native lr_MudarVWRadar(lrid, virtualworld);
  21. native lr_PegarPosRadar(lrid, &Float:x, &Float:y, &Float:z);
  22. native lr_PegarVWRadar(lrid);
  23.  
  24. /------------------------------------------------------------------------------------------------------------||*/
  25.  
  26. enum lrdef
  27. {
  28.     lr_VW,
  29.     lr_OID,
  30.     Float:lr_X,
  31.     Float:lr_Y,
  32.     Float:lr_Z,
  33.     lr_speedmax,
  34. };
  35.  
  36. static  lr_Timer, lr_Total, lr_Radar[MAX_Radar][lrdef];
  37.  
  38. #define lr_ChecarTimerAd() if(!lr_Timer) lr_Timer = SetTimer("lr_ChecarRadar", LR_TEMPO_CHECAGEM, 1)
  39. #define lr_ChecarTimerRe() if(!lr_Total){KillTimer(lr_Timer); lr_Timer = 0;}
  40.  
  41. forward lr_ChecarRadar();
  42. forward OcultarRadar(playerid);
  43. forward JogadorNoPonto(Float:radi, playerid, Float:x, Float:y, Float:z);
  44. forward OnPlayerEnterRadar(playerid);
  45. forward CreateRadar();
  46.  
  47. new Text:Radar;
  48.  
  49. stock lr_CriarRadar(Float:x, Float:y, Float:z, speedmax, virtualword = -1)
  50. {
  51.     new bid = lr_ProcurarIDLivre();
  52.     if(bid == -1)
  53.     {
  54.         printf("[lr]: Limite de Radar (MAX_Radar = %d) foi excedido! Aumente o valor ou apague algum...", MAX_Radar);
  55.         return 0;
  56.     }
  57.     lr_Radar[bid][lr_OID] = CreatePickup(1318,1,x,y,z+2,-1);
  58.     lr_Radar[bid][lr_X] = x;
  59.     lr_Radar[bid][lr_Y] = y;
  60.     lr_Radar[bid][lr_Z] = z;
  61.     lr_Radar[bid][lr_speedmax] = speedmax;
  62.     lr_Radar[bid][lr_VW] = virtualword;
  63.     lr_ChecarTimerAd();
  64.     lr_Total++;
  65.     return bid;
  66. }
  67.  
  68. stock lr_DestruirRadar(lrid)
  69. {
  70.     if(!lr_Radar[lrid][lr_OID]) return 0;
  71.     lr_Total--;
  72.     pso_RemoverObjeto(lr_Radar[lrid][lr_OID]);
  73.     lr_Radar[lrid][lr_OID] = 0;
  74.     lr_ChecarTimerRe()
  75.     return 1;
  76. }
  77.  
  78. stock lr_RadarExiste(lrid)  return (!lr_Radar[lrid][lr_OID]) ? 0 : 1;
  79.  
  80. stock lr_MudarPosRadar(lrid, Float:x, Float:y, Float:z)
  81. {
  82.     if(!lr_Radar[lrid][lr_OID]) return 0;
  83.     lr_Radar[lrid][lr_X] = x;
  84.     lr_Radar[lrid][lr_Y] = y;
  85.     lr_Radar[lrid][lr_Z] = z;
  86.     return pso_MudarPosObjeto(lr_Radar[lrid][lr_OID], x, y, z);
  87. }
  88.  
  89. stock lr_MudarVWRadar(lrid, virtualworld)
  90. {
  91.     if(!lr_Radar[lrid][lr_OID]) return 0;
  92.     lr_Radar[lrid][lr_VW] = virtualworld;
  93.     return pso_MudarVirtualWorldObjeto(lr_Radar[lrid][lr_OID], virtualworld);
  94. }
  95.  
  96. stock lr_PegarPosRadar(lrid, &Float:x, &Float:y, &Float:z)
  97. {
  98.     if(!lr_Radar[lrid][lr_OID])
  99.     {
  100.         x = 0.0;
  101.         y = 0.0;
  102.         z = 0.0;
  103.     }
  104.     x = lr_Radar[lrid][lr_X];
  105.     y = lr_Radar[lrid][lr_Y];
  106.     z = lr_Radar[lrid][lr_Z];
  107. }
  108.  
  109. stock lr_PegarVWRadar(lrid)
  110. {
  111.     if(!lr_Radar[lrid][lr_OID]) return 0;
  112.     return lr_Radar[lrid][lr_VW];
  113. }
  114.  
  115. public JogadorNoPonto(Float:radi, playerid, Float:x, Float:y, Float:z)
  116. {
  117.     if(IsPlayerConnected(playerid))
  118.     {
  119.         new Float:oldposx, Float:oldposy, Float:oldposz;
  120.         new Float:tempposx, Float:tempposy, Float:tempposz;
  121.         GetPlayerPos(playerid, oldposx, oldposy, oldposz);
  122.         tempposx = (oldposx -x);
  123.         tempposy = (oldposy -y);
  124.         tempposz = (oldposz -z);
  125.         if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
  126.         {
  127.             return 1;
  128.         }
  129.     }
  130.     return 0;
  131. }
  132.  
  133. public lr_ChecarRadar()
  134. {
  135.     for(new i = 0; i < MAX_PLAYERS; i++)
  136.     {
  137.         for(new b = 1; b <= lr_Total; b++)
  138.         {
  139.             if(lr_Radar[b][lr_OID])
  140.             {
  141.                 if(lr_Radar[b][lr_VW] == -1 || GetPlayerVirtualWorld(i) == lr_Radar[b][lr_VW])
  142.                 {
  143.                     if(JogadorNoPonto(20.0, i, lr_Radar[b][lr_X], lr_Radar[b][lr_Y], lr_Radar[b][lr_Z]))
  144.                     {
  145.                         RadarForPlayer(i, lr_Radar[b][lr_speedmax]);
  146.                     }  
  147.                 }
  148.             }
  149.         }
  150.     }
  151. }
  152.  
  153. stock lr_ProcurarIDLivre()
  154. {
  155.     for(new b = 1; b < MAX_Radar; b++) if(!lr_Radar[b][lr_OID]) return b;
  156.     return -1;
  157. }
  158.  
  159. stock ObterVelocidade(playerid, bool:velo)
  160. {
  161.     new Float:Vx,Float:Vy,Float:Vz,Float:rtn;
  162.     if(IsPlayerInAnyVehicle(playerid)) GetVehicleVelocity(GetPlayerVehicleID(playerid),Vx,Vy,Vz); else GetPlayerVelocity(playerid,Vx,Vy,Vz);
  163.     rtn = floatsqroot(floatabs(floatpower(Vx + Vy + Vz,2)));
  164.     return velo?floatround(rtn * 100 * 1.61):floatround(rtn * 100);
  165. }
  166.  
  167. stock RadarForPlayer(playerid, velocidademax)
  168. {
  169.     new velocidadeatual = ObterVelocidade(playerid, true);
  170.     if(velocidadeatual >= velocidademax)
  171.     {
  172.         TextDrawShowForPlayer(playerid, Radar);
  173.         PlayerPlaySound(playerid,1132,0.0,0.0,0.0);
  174.         SetTimerEx("OcultarRadar", 1500, 0, "d", playerid);
  175.         OnPlayerEnterRadar(playerid);
  176.     }
  177.     return 1;
  178. }
  179. public OcultarRadar(playerid)
  180. {
  181.     TextDrawHideForPlayer(playerid, Radar);
  182.     PlayerPlaySound(playerid,1132,0.0,0.0,0.0);
  183.     return 1;
  184. }
  185.  
  186. public CreateRadar()
  187. {
  188.     Radar = TextDrawCreate(635.000000, 432.000000, "__");
  189.     TextDrawBackgroundColor(Radar, 255);
  190.     TextDrawFont(Radar, 1);
  191.     TextDrawLetterSize(Radar, 0.500000, -45.900001);
  192.     TextDrawColor(Radar, -256);
  193.     TextDrawSetOutline(Radar, 0);
  194.     TextDrawSetProportional(Radar, 1);
  195.     TextDrawSetShadow(Radar, 1);
  196.     TextDrawUseBox(Radar, 1);
  197.     TextDrawBoxColor(Radar, -86);
  198.     TextDrawTextSize(Radar, 6.000000, 35.000000);
  199.     return 1;
  200. }
Advertisement
Add Comment
Please, Sign In to add comment