Guest User

LSR - V2.1.1 INC

a guest
Jan 1st, 2011
714
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. *
  3. *   -= LSR INCLUDE =-
  4. *   Larceny Speed Radar
  5. *
  6. *   Autor: Larceny
  7. *   Special Thanks to: Protioso ([VGS]Protioso_OC)
  8. *   First    Release: 18, Setember, 2010 - V1.0.0
  9. *   Fix      Release: 00, 00000000, 0000 - V1.1.0
  10. *   Second   Release: 18, Setember, 2010 - V1.2.0
  11. *   Third    Release: 19, Setember, 2010 - V1.3.0
  12. *   Fix      Release: 00, 00000000, 0000 - V1.4.0
  13. *   Fix      Release: 00, 00000000, 0000 - V1.5.0
  14. *   Fix      Release: 00, 00000000, 0000 - V1.6.0
  15. *   Fourth   Release: 20, Setember, 2010 - V1.7.0
  16. *   Fifth    Release: 20, Setember, 2010 - V1.8.0
  17. *   Sixth    Release: 22, October,  2010 - V1.9.0
  18. *   Seven    Release: 27, December, 2010 - V2.0.0
  19. *   Fix      Release: 29, December, 0000 - V2.1.0
  20. *   Eight    Release: 01, January,  2010 - V2.1.1
  21. *
  22. */
  23. #include "a_samp"
  24.  
  25. #define MAX_Radar 100
  26. #define LSR_TIME_CHECK 1500 // Time in miliseconds.
  27.  
  28. /*Function List -----------------------------------------------------------------------------||
  29.  
  30. native CreateRadar(Float:x, Float:y, Float:z, speedmax, radiation, pickup, activated, virtualword = -1);
  31. native DestroyRadar(lrid);
  32. native RadarExists(lrid);
  33. native SetRadarPos(lrid, Float:x, Float:y, Float:z);
  34. native SetRadarVirtualWorld(lrid, virtualworld);
  35. native SetRadarActivate(lrid, toggle);
  36. native SetRadarMaxSpeed(lrid, speed);
  37. native SetRadarRadius(lrid, Float:radius);
  38. native SetRadarPickup(lrid, pickupid);
  39. native GetRadarPos(lrid, &Float:x, &Float:y, &Float:z);
  40. native GetRadarVirtualWorld(lrid);
  41. native LoadStaticRadarsFromFile(const filename[]);
  42. native GetPlayerSpeed(playerid, bool:velo);
  43. native GetVehicleSpeed(vehicleid);
  44. native AttachRadarToPlayer(playerid, speedlimit);
  45. native DettachRadarToPlayer(playerid);
  46. native IsPlayerRadarAttached(playerid);
  47.  
  48. /------------------------------------------------------------------------------------------------------------||*/
  49.  
  50. enum lrdef
  51. {
  52.     LSR_VW,
  53.     LSR_OID,
  54.     Float:LSR_X,
  55.     Float:LSR_Y,
  56.     Float:LSR_Z,
  57.     LSR_speedmax,
  58.     LSR_radiation,
  59.     LSR_pickup,
  60.     LSR_activated
  61. };
  62.  
  63. static  LSR_Timer, LSR_Total, LSR_Radar[MAX_Radar][lrdef];
  64.  
  65. #define LSR_CheckTimerAd() if(!LSR_Timer) LSR_Timer = SetTimer("CheckRadar", LSR_TIME_CHECK, 1)
  66. #define LSR_CheckTimerRe() if(!LSR_Total){KillTimer(LSR_Timer); LSR_Timer = 0;}
  67.  
  68. forward CheckRadar();
  69. forward HideRadar(playerid);
  70. forward PlayerInPoint(Float:radi, playerid, Float:x, Float:y, Float:z);
  71. forward OnPlayerEnterRadar(playerid, speed, radarid);
  72. forward UseFlashRadar();
  73. forward MoverPickup(lrid,Float:x,Float:y,Float:z);
  74.  
  75. new Text:Flash;
  76. new UseFlash;
  77. new RadarAttached[MAX_PLAYERS];
  78. new RadarAttachedSpeed[MAX_PLAYERS];
  79.  
  80. stock CreateRadar(Float:x, Float:y, Float:z, speedmax, radiation, pickup, activated, virtualword = -1)
  81. {
  82.     new bid = LSR_ProcurarIDLivre();
  83.     if(bid == -1)
  84.     {
  85.         printf("[LSP:] Radar limit was exceeded!(Max:%d) Increase the value or delete some...", MAX_Radar);
  86.         return 0;
  87.     }
  88.     LSR_Radar[bid][LSR_OID] = CreatePickup(pickup,1,x,y,z+2,-1);
  89.     LSR_Radar[bid][LSR_X] = x;
  90.     LSR_Radar[bid][LSR_Y] = y;
  91.     LSR_Radar[bid][LSR_Z] = z;
  92.     LSR_Radar[bid][LSR_speedmax] = speedmax;
  93.     LSR_Radar[bid][LSR_VW] = virtualword;
  94.     LSR_Radar[bid][LSR_radiation] = radiation;
  95.     LSR_Radar[bid][LSR_pickup] = pickup;
  96.     LSR_Radar[bid][LSR_activated] = activated;
  97.     LSR_CheckTimerAd();
  98.     LSR_Total++;
  99.     return bid;
  100. }
  101.  
  102. stock DestroyRadar(lrid)
  103. {
  104.     if(!LSR_Radar[lrid][LSR_OID]) return 0;
  105.     LSR_Total--;
  106.     DestroyPickup(LSR_Radar[lrid][LSR_pickup]);
  107.     LSR_Radar[lrid][LSR_OID] = 0;
  108.     LSR_CheckTimerRe()
  109.     return 1;
  110. }
  111.  
  112. stock RadarExists(lrid) return (!LSR_Radar[lrid][LSR_OID]) ? 0 : 1;
  113.  
  114. stock SetRadarPos(lrid, Float:x, Float:y, Float:z)
  115. {
  116.     if(!LSR_Radar[lrid][LSR_OID]) return 0;
  117.     LSR_Radar[lrid][LSR_X] = x;
  118.     LSR_Radar[lrid][LSR_Y] = y;
  119.     LSR_Radar[lrid][LSR_Z] = z;
  120.     return MoverPickup(LSR_Radar[lrid][LSR_OID], x, y, z);
  121. }
  122.  
  123. public MoverPickup(lrid,Float:x,Float:y,Float:z)
  124. {
  125.     if(LSR_Radar[lrid][LSR_OID])
  126.     {
  127.         DestroyPickup(LSR_Radar[lrid][LSR_OID]);
  128.         LSR_Radar[lrid][LSR_X] = x;
  129.         LSR_Radar[lrid][LSR_Y] = y;
  130.         LSR_Radar[lrid][LSR_Z] = z;
  131.         CreatePickup(LSR_Radar[lrid][LSR_pickup], 1, x, y, z, -1);
  132.         return 1;
  133.     }
  134.     return 0;
  135. }
  136.  
  137. stock SetRadarVirtualWorld(lrid, virtualworld)
  138. {
  139.     if(!LSR_Radar[lrid][LSR_OID]) return 0;
  140.     LSR_Radar[lrid][LSR_VW] = virtualworld;
  141.     DestroyPickup(LSR_Radar[lrid][LSR_OID]);
  142.     new x = LSR_Radar[lrid][LSR_X];
  143.     new y = LSR_Radar[lrid][LSR_Y];
  144.     new z = LSR_Radar[lrid][LSR_Z];
  145.     CreatePickup(LSR_Radar[lrid][LSR_pickup], 1, x, y, z, virtualworld);
  146.     return 1;
  147. }
  148.  
  149. stock SetRadarAtivate(lrid, toggle)
  150. {
  151.     if(!LSR_Radar[lrid][LSR_OID]) return 0;
  152.     if(toggle == 1 || toggle == true){LSR_Radar[lrid][LSR_ativado] = 1;}
  153.     if(toggle == 0 || toggle == false){LSR_Radar[lrid][LSR_ativado] = 0;}
  154.     return MoverPickup(LSR_Radar[lrid][LSR_OID], x, y, z);
  155. }
  156.  
  157. stock SetRadarMaxSpeed(lrid, speed)
  158. {
  159.     if(!LSR_Radar[lrid][LSR_OID]) return 0;
  160.     return LSR_Radar[lrid][LSR_speedmax] = speed;
  161. }
  162.  
  163. stock SetRadarRadius(lrid, Float:radius)
  164. {
  165.     if(!LSR_Radar[lrid][LSR_OID]) return 0;
  166.     return LSR_Radar[lrid][LSR_radiation] = radius;
  167. }
  168.  
  169. stock AttachRadarToPlayer(playerid, velocidade)
  170. {
  171.     RadarAttached[playerid] = 1;
  172.     RadarAttachedSpeed[playerid] = velocidade;
  173.     return 1;
  174. }
  175.  
  176. stock DettachRadarToPlayer(playerid)
  177. {
  178.     RadarAttached[playerid] = 0;
  179.     RadarAttachedSpeed[playerid] = 0;
  180.     return 1;
  181. }
  182.  
  183. stock IsPlayerRadarAttached(playerid)
  184. {
  185.     if(RadarAttached[playerid] == 1)return true;
  186.     if(RadarAttached[playerid] == 0)return false;
  187.     return 1;
  188. }
  189.  
  190. stock GetPlayerSpeed(playerid, bool:velo)
  191. {
  192.     new Float:Vx,Float:Vy,Float:Vz,Float:rtn;
  193.     if(IsPlayerInAnyVehicle(playerid)) GetVehicleVelocity(GetPlayerVehicleID(playerid),Vx,Vy,Vz); else GetPlayerVelocity(playerid,Vx,Vy,Vz);
  194.     rtn = floatsqroot(floatabs(floatpower(Vx + Vy + Vz,2)));
  195.     return velo?floatround(rtn * 100 * 1.61):floatround(rtn * 100);
  196. }
  197.  
  198. stock GetVehicleSpeed(vehicleid)
  199. {
  200.     new Float:X, Float:Y, Float:Z;
  201.     GetVehicleVelocity(vehicleid, X, Y, Z);
  202.     return floatround(floatsqroot(X * X + Y * Y + Z * Z) * 180);
  203. }
  204.  
  205. stock SetRadarPickup(lrid, pickupid)
  206. {
  207.     if(!LSR_Radar[lrid][LSR_OID]) return 0;
  208.     LSR_Radar[lrid][LSR_pickup] = pickupid;
  209.     return MoverPickup(lrid, LSR_Radar[lrid][LSR_X], LSR_Radar[lrid][LSR_Y], LSR_Radar[lrid][LSR_Z]+2);
  210. }
  211.  
  212. stock GetRadarPos(lrid, &Float:x, &Float:y, &Float:z)
  213. {
  214.     if(!LSR_Radar[lrid][LSR_OID])
  215.     {
  216.         x = 0.0;
  217.         y = 0.0;
  218.         z = 0.0;
  219.     }
  220.     x = LSR_Radar[lrid][LSR_X];
  221.     y = LSR_Radar[lrid][LSR_Y];
  222.     z = LSR_Radar[lrid][LSR_Z];
  223. }
  224.  
  225. stock GetRadarVirtualWorld(lrid)
  226. {
  227.     if(!LSR_Radar[lrid][LSR_OID]) return 0;
  228.     return LSR_Radar[lrid][LSR_VW];
  229. }
  230.  
  231. forward LSR_PlayerConnect(playerid);
  232. public LSR_PlayerConnect(playerid)
  233. {
  234.     RadarAttached[playerid] = 0;
  235.     RadarAttachedSpeed[playerid] = 0;
  236.     return 1;
  237. }
  238.  
  239. public PlayerInPoint(Float:radi, playerid, Float:x, Float:y, Float:z)
  240. {
  241.     if(IsPlayerConnected(playerid))
  242.     {
  243.         new Float:oldposx, Float:oldposy, Float:oldposz;
  244.         new Float:tempposx, Float:tempposy, Float:tempposz;
  245.         GetPlayerPos(playerid, oldposx, oldposy, oldposz);
  246.         tempposx = (oldposx -x);
  247.         tempposy = (oldposy -y);
  248.         tempposz = (oldposz -z);
  249.         if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
  250.         {
  251.             return 1;
  252.         }
  253.     }
  254.     return 0;
  255. }
  256.  
  257. public CheckRadar()
  258. {
  259.     for(new i = 0; i < MAX_PLAYERS; i++)
  260.     {
  261.         for(new b = 1; b <= LSR_Total; b++)
  262.         {
  263.             if(LSR_Radar[b][LSR_OID])
  264.             {
  265.                 if(LSR_Radar[b][LSR_activated] == 1)
  266.                 {
  267.                     if(LSR_Radar[b][LSR_VW] == -1 || GetPlayerVirtualWorld(i) == LSR_Radar[b][LSR_VW])
  268.                     {
  269.                         if(PlayerInPoint(LSR_Radar[b][LSR_radiation], i, LSR_Radar[b][LSR_X], LSR_Radar[b][LSR_Y], LSR_Radar[b][LSR_Z]))
  270.                         {
  271.                             RadarForPlayer(i, LSR_Radar[b][LSR_speedmax], LSR_Radar[b][LSR_OID]);
  272.                         }
  273.                     }
  274.                 }
  275.             }
  276.         }
  277.     }
  278. }
  279.  
  280. stock LSR_ProcurarIDLivre()
  281. {
  282.     for(new b = 1; b < MAX_Radar; b++) if(!LSR_Radar[b][LSR_OID]) return b;
  283.     return -1;
  284. }
  285.  
  286. stock GetSpeed(playerid, bool:velo)
  287. {
  288.     new Float:Vx,Float:Vy,Float:Vz,Float:rtn;
  289.     if(IsPlayerInAnyVehicle(playerid)) GetVehicleVelocity(GetPlayerVehicleID(playerid),Vx,Vy,Vz); else GetPlayerVelocity(playerid,Vx,Vy,Vz);
  290.     rtn = floatsqroot(floatabs(floatpower(Vx + Vy + Vz,2)));
  291.     return velo?floatround(rtn * 100 * 1.61):floatround(rtn * 100);
  292. }
  293.  
  294. stock LoadStaticRadarsFromFile(const filename[])
  295. {
  296.     new File:file_ptr;
  297.     new line[256];
  298.     new var_from_line[64];
  299.     new Float:SpawnX;
  300.     new Float:SpawnY;
  301.     new Float:SpawnZ;
  302.     new SpeedMax;
  303.     new Radiation, Pickup;
  304.     new Ativado, VirtualWorld;
  305.     new index;
  306.     new radars_loaded;
  307.  
  308.     file_ptr = fopen(filename,filemode:io_read);
  309.     if(!file_ptr) return 0;
  310.  
  311.     radars_loaded = 0;
  312.  
  313.     while(fread(file_ptr,line,256) > 0)
  314.     {
  315.         index = 0;
  316.  
  317.         // Read X, Y, Z, Rotation
  318.         index = token_by_delim(line,var_from_line,',',index);
  319.         if(index == (-1)) continue;
  320.         SpawnX = floatstr(var_from_line);
  321.  
  322.         index = token_by_delim(line,var_from_line,',',index+1);
  323.         if(index == (-1)) continue;
  324.         SpawnY = floatstr(var_from_line);
  325.  
  326.         index = token_by_delim(line,var_from_line,',',index+1);
  327.         if(index == (-1)) continue;
  328.         SpawnZ = floatstr(var_from_line);
  329.  
  330.         // Read Speed Max
  331.         index = token_by_delim(line,var_from_line,',',index+1);
  332.         if(index == (-1)) continue;
  333.         SpeedMax = strval(var_from_line);
  334.  
  335.         // Read Radiation, Pickup
  336.         index = token_by_delim(line,var_from_line,',',index+1);
  337.         if(index == (-1)) continue;
  338.         Radiation = strval(var_from_line);
  339.  
  340.         index = token_by_delim(line,var_from_line,',',index+1);
  341.         if(index == (-1)) continue;
  342.         Pickup = strval(var_from_line);
  343.  
  344.         //Read Ativado, VirtualWorld
  345.         index = token_by_delim(line,var_from_line,',',index+1);
  346.         if(index == (-1)) continue;
  347.         Ativado = strval(var_from_line);
  348.  
  349.         index = token_by_delim(line,var_from_line,';',index+1);
  350.         VirtualWorld = strval(var_from_line);
  351.  
  352.         CreateRadar(SpawnX, SpawnY, SpawnZ, SpeedMax, Radiation, Pickup, Ativado, VirtualWorld);
  353.         radars_loaded++;
  354.     }
  355.  
  356.     fclose(file_ptr);
  357.     printf("[LSR:] Loaded %d Radars from file: %s",radars_loaded,filename);
  358.     return radars_loaded;
  359. }
  360.  
  361. stock RadarForPlayer(playerid, speedlimit, radarid)
  362. {
  363.     new currentspeed = GetSpeed(playerid, true);
  364.     if(currentspeed >= speedlimit)
  365.     {
  366.         if(UseFlash == 1){TextDrawShowForPlayer(playerid, Flash); SetTimerEx("HideRadar", 1000, 0, "d", playerid);}
  367.         PlayerPlaySound(playerid,1132,0.0,0.0,0.0);
  368.         OnPlayerEnterRadar(playerid, currentspeed, radarid);
  369.     }
  370.     return 1;
  371. }
  372. public HideRadar(playerid)
  373. {
  374.     TextDrawHideForPlayer(playerid, Flash);
  375.     return 1;
  376. }
  377.  
  378. public UseFlashRadar()
  379. {
  380.     UseFlash = 1;
  381.     Flash = TextDrawCreate(635.000000, 432.000000, "__");
  382.     TextDrawBackgroundColor(Flash, 255);
  383.     TextDrawFont(Flash, 1);
  384.     TextDrawLetterSize(Flash, 0.500000, -45.900001);
  385.     TextDrawColor(Flash, -256);
  386.     TextDrawSetOutline(Flash, 0);
  387.     TextDrawSetProportional(Flash, 1);
  388.     TextDrawSetShadow(Flash, 1);
  389.     TextDrawUseBox(Flash, 1);
  390.     TextDrawBoxColor(Flash, -86);
  391.     TextDrawTextSize(Flash, 6.000000, 35.000000);
  392.     return 1;
  393. }
RAW Paste Data