Advertisement
Guest User

Real Vehicle Lights v2 By Cyber_Punk

a guest
Mar 29th, 2010
660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 9.50 KB | None | 0 0
  1. /*************************************************
  2. Infinite-Gaming.com Presents:
  3. Real Vehicle Lights v.2 by Cyber_Punk
  4.  
  5. DO NOT REMOVE CREDITS
  6. If you borrow bits of code would be nice to..
  7. credit the original authors
  8.  
  9. NEW - Public vehicles - Police, FBI, FIRE, Medic have flashing lights with the siren button (horn)
  10. NEWv2 - Fixed a couple bugs, reworked the blinker system PRESS Look Left or Look Right to activate blinker
  11. If you turn the wheel in the opposite direction than the blinker it will auto shut off. Just like a real car :P
  12.  
  13. Know issues (not script bugs)
  14. Lights still will not flash in the day time,
  15. Rear lights do not flash......
  16. Hope for a samp fix in 0.3b code should still work
  17. *************************************************/
  18. #include <a_samp>
  19.  
  20. #define BLINK_RATE      400 // This is the rate of flash (also rate of timer in milliseconds, same for pflash)
  21. #define PFLASH_RATE     300 // This controls the rate of flash for public vehicle lights, works for all police, fire, ambulance vehicles
  22. #define LIGHT_KEY       KEY_SUBMISSION // Set this to whatever key you want to turn the lights on
  23.  
  24. //Put MAX PLAYERS HERE (sorry its for the timer..)
  25. #undef MAX_PLAYERS
  26.     #define MAX_PLAYERS 50
  27.    
  28. // Macro from SAMP wiki Credits to the author
  29. #define PRESSED(%0) \
  30.     (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
  31.  
  32. new BlinkTime[MAX_PLAYERS];
  33.  
  34. public OnFilterScriptInit()
  35. {
  36.     print("\n--------------------------------------");
  37.     print(" Infinite-Gaming.com Presents:");
  38.     print(" Real Vehicle Lights v2 by Cyber_Punk");
  39.     print("--------------------------------------\n");
  40.     return 1;
  41. }
  42.  
  43. public OnFilterScriptExit()
  44. {
  45.     print("\n--------------------------------------");
  46.     print(" Real Vehicle Lights UNLOADED");
  47.     print("--------------------------------------\n");
  48.     return 1;
  49. }
  50.  
  51. public OnPlayerConnect(playerid)
  52. {
  53.     return 1;
  54. }
  55.  
  56. public OnPlayerDisconnect(playerid, reason)
  57. {
  58.     KillTimer(BlinkTime[playerid]);
  59.     return 1;
  60. }
  61.  
  62. public OnPlayerStateChange(playerid, newstate, oldstate)
  63. {
  64.     if(newstate == PLAYER_STATE_DRIVER)
  65.     {
  66.         new panels, doors, lights, tires;
  67.         new carid = GetPlayerVehicleID(playerid);
  68.         GetVehicleDamageStatus(carid, panels, doors, lights, tires);
  69.         lights = encode_lights(1, 1, 1, 1);
  70.         SetPVarInt(playerid, "vMainOn", 0);
  71.         UpdateVehicleDamageStatus(carid, panels, doors, lights, tires);
  72.     }
  73.     else if(newstate == PLAYER_STATE_ONFOOT)
  74.     {
  75.         KillTimer(BlinkTime[playerid]);
  76.         SetPVarInt(playerid, "CopFlash", 0);
  77.     }
  78.     return 1;
  79. }
  80.  
  81. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  82. {
  83.     if(PRESSED(LIGHT_KEY))
  84.     {
  85.         if(IsPlayerInAnyVehicle(playerid) && GetPlayerVehicleSeat(playerid) == 0)
  86.         {
  87.             if(GetPVarInt(playerid, "CopFlash") == 0)
  88.             {
  89.                 new panels, doors, lights, tires;
  90.                 new carid = GetPlayerVehicleID(playerid);
  91.                 GetVehicleDamageStatus(carid, panels, doors, lights, tires);
  92.                 switch(GetPVarInt(playerid, "vMainOn"))
  93.                 {
  94.                     case 0:{
  95.                         lights = encode_lights(0, 0, 0, 0);
  96.                         SetPVarInt(playerid, "vMainOn", 1);
  97.                     }
  98.                     case 1:{
  99.                         lights = encode_lights(1, 1, 1, 1);
  100.                         SetPVarInt(playerid, "vMainOn", 0);
  101.                     }
  102.                 }
  103.                 UpdateVehicleDamageStatus(carid, panels, doors, lights, tires);
  104.             }
  105.         }
  106.     }
  107.     if(PRESSED(KEY_CROUCH))
  108.     {
  109.         if(IsPublicService(GetPlayerVehicleID(playerid)) && GetPlayerVehicleSeat(playerid) == 0)
  110.         {
  111.             switch(GetPVarInt(playerid, "CopFlash"))
  112.             {
  113.                 case 0:{
  114.                     KillTimer(BlinkTime[playerid]);
  115.                     BlinkTime[playerid] = SetTimerEx("vBlinker", PFLASH_RATE, 1, "i", playerid);
  116.                     SetPVarInt(playerid, "CopFlash", 1);
  117.                 }
  118.                 case 1:{
  119.                     KillTimer(BlinkTime[playerid]);
  120.                     new panels, doors, lights, tires;
  121.                     new carid = GetPlayerVehicleID(playerid);
  122.                     GetVehicleDamageStatus(carid, panels, doors, lights, tires);
  123.                     lights = encode_lights(1, 1, 1, 1);
  124.                     UpdateVehicleDamageStatus(carid, panels, doors, lights, tires);
  125.                     SetPVarInt(playerid, "CopFlash", 0);
  126.                 }
  127.             }
  128.         }
  129.     }
  130.     if(PRESSED(KEY_LOOK_LEFT))
  131.     {
  132.         if(GetPlayerVehicleSeat(playerid) == 0)
  133.         {
  134.             if(GetPVarInt(playerid, "vBLeft") == 0)
  135.             {
  136.                 KillTimer(BlinkTime[playerid]);
  137.                 BlinkTime[playerid] = SetTimerEx("vBlinker", BLINK_RATE, 1, "i", playerid);
  138.                 SetPVarInt(playerid, "vBLeft", 1);
  139.                 SetPVarInt(playerid, "vBRight", 0);
  140.             }else{
  141.                 KillTimer(BlinkTime[playerid]);
  142.                 new panels, doors, lights, tires;
  143.                 new carid = GetPlayerVehicleID(playerid);
  144.                 GetVehicleDamageStatus(carid, panels, doors, lights, tires);
  145.                 switch(GetPVarInt(playerid, "vMainOn")){
  146.                     case 0:{
  147.                         lights = encode_lights(1, 1, 1, 1);
  148.                     }
  149.                     case 1:{
  150.                         lights = encode_lights(0, 0, 0, 0);
  151.                     }
  152.                 }
  153.                 UpdateVehicleDamageStatus(carid, panels, doors, lights, tires);
  154.                 SetPVarInt(playerid, "vBLeft", 0);
  155.             }
  156.         }
  157.     }
  158.     if(PRESSED(KEY_LOOK_RIGHT))
  159.     {
  160.         if(GetPlayerVehicleSeat(playerid) == 0)
  161.         {
  162.             if(GetPVarInt(playerid, "vBRight") == 0)
  163.             {
  164.                 KillTimer(BlinkTime[playerid]);
  165.                 BlinkTime[playerid] = SetTimerEx("vBlinker", BLINK_RATE, 1, "i", playerid);
  166.                 SetPVarInt(playerid, "vBRight", 1);
  167.                 SetPVarInt(playerid, "vBLeft", 0);
  168.             }else{
  169.                 KillTimer(BlinkTime[playerid]);
  170.                 new panels, doors, lights, tires;
  171.                 new carid = GetPlayerVehicleID(playerid);
  172.                 GetVehicleDamageStatus(carid, panels, doors, lights, tires);
  173.                 switch(GetPVarInt(playerid, "vMainOn")){
  174.                     case 0:{
  175.                         lights = encode_lights(1, 1, 1, 1);
  176.                     }
  177.                     case 1:{
  178.                         lights = encode_lights(0, 0, 0, 0);
  179.                     }
  180.                 }
  181.                 UpdateVehicleDamageStatus(carid, panels, doors, lights, tires);
  182.                 SetPVarInt(playerid, "vBRight", 0);
  183.             }
  184.         }
  185.     }
  186.     return 1;
  187. }
  188.  
  189. forward vBlinker(playerid);
  190. public vBlinker(playerid)
  191. {
  192.     if(IsPlayerInAnyVehicle(playerid) && GetPVarInt(playerid, "CopFlash") != 1)
  193.     {
  194.         new Keys, ud, lr, panels, doors, lights, tires;
  195.         new carid = GetPlayerVehicleID(playerid);
  196.         GetPlayerKeys(playerid, Keys, ud, lr);
  197.         GetVehicleDamageStatus(carid, panels, doors, lights, tires);
  198.  
  199.         if(lr > 0)
  200.         {
  201.             if(GetPVarInt(playerid, "vBLeft") == 1)
  202.             {
  203.                 KillTimer(BlinkTime[playerid]);
  204.                 switch(GetPVarInt(playerid, "vMainOn")){
  205.                     case 0:{
  206.                         lights = encode_lights(1, 1, 1, 1);
  207.                     }
  208.                     case 1:{
  209.                         lights = encode_lights(0, 0, 0, 0);
  210.                     }
  211.                 }
  212.                 UpdateVehicleDamageStatus(carid, panels, doors, lights, tires);
  213.                 SetPVarInt(playerid, "vBLeft", 0);
  214.                 return 1;
  215.             }
  216.         }
  217.         else if(lr < 0)
  218.         {
  219.             if(GetPVarInt(playerid, "vBRight") == 1)
  220.             {
  221.                 KillTimer(BlinkTime[playerid]);
  222.                 switch(GetPVarInt(playerid, "vMainOn")){
  223.                     case 0:{
  224.                         lights = encode_lights(1, 1, 1, 1);
  225.                     }
  226.                     case 1:{
  227.                         lights = encode_lights(0, 0, 0, 0);
  228.                     }
  229.                 }
  230.                 UpdateVehicleDamageStatus(carid, panels, doors, lights, tires);
  231.                 SetPVarInt(playerid, "vBRight", 0);
  232.                 return 1;
  233.             }
  234.         }
  235.  
  236.         if(GetPVarInt(playerid, "vBRight") == 1)
  237.         {
  238.             switch(GetPVarInt(playerid, "vMainOn")){
  239.                 case 0:{
  240.                     switch(GetPVarInt(playerid, "vBlinkOn")){
  241.                         case 0:{
  242.                             lights = encode_lights(1, 1, 0, 0);
  243.                             SetPVarInt(playerid, "vBlinkOn", 1);
  244.                         }
  245.                         case 1:{
  246.                             lights = encode_lights(1, 1, 1, 1);
  247.                             SetPVarInt(playerid, "vBlinkOn", 0);
  248.                         }
  249.                     }
  250.                 }
  251.                 case 1:{
  252.                     switch(GetPVarInt(playerid, "vBlinkOn")){
  253.                         case 0:{
  254.                             lights = encode_lights(0, 0, 1, 1);
  255.                             SetPVarInt(playerid, "vBlinkOn", 1);
  256.                         }
  257.                         case 1:{
  258.                             lights = encode_lights(0, 0, 0, 0);
  259.                             SetPVarInt(playerid, "vBlinkOn", 0);
  260.                         }
  261.                     }
  262.                 }
  263.             }
  264.         }
  265.        
  266.         if(GetPVarInt(playerid, "vBLeft") == 1)
  267.         {
  268.             switch(GetPVarInt(playerid, "vMainOn")){
  269.                 case 0:{
  270.                     switch(GetPVarInt(playerid, "vBlinkOn")){
  271.                         case 0:{
  272.                             lights = encode_lights(0, 0, 1, 1);
  273.                             SetPVarInt(playerid, "vBlinkOn", 1);
  274.                         }
  275.                         case 1:{
  276.                             lights = encode_lights(1, 1, 1, 1);
  277.                             SetPVarInt(playerid, "vBlinkOn", 0);
  278.                         }
  279.                     }
  280.                 }
  281.                 case 1:{
  282.                     switch(GetPVarInt(playerid, "vBlinkOn")){
  283.                         case 0:{
  284.                             lights = encode_lights(1, 1, 0, 0);
  285.                             SetPVarInt(playerid, "vBlinkOn", 1);
  286.                         }
  287.                         case 1:{
  288.                             lights = encode_lights(0, 0, 0, 0);
  289.                             SetPVarInt(playerid, "vBlinkOn", 0);
  290.                         }
  291.                     }
  292.                 }
  293.             }
  294.         }
  295.         UpdateVehicleDamageStatus(carid, panels, doors, lights, tires);
  296.     }
  297.     else if(GetPVarInt(playerid, "CopFlash") == 1)
  298.     {
  299.         new d[4];
  300.         new carid = GetPlayerVehicleID(playerid);
  301.         GetVehicleDamageStatus(carid, d[0], d[1], d[2], d[3]);
  302.  
  303.         switch(GetPVarInt(playerid, "vBlinkOn"))
  304.         {
  305.            case 0:{
  306.                 d[2] = encode_lights(1, 1, 0, 0);
  307.                 SetPVarInt(playerid, "vBlinkOn", 1);
  308.            }
  309.            case 1:{
  310.                 d[2] = encode_lights(0, 0, 1, 1);
  311.                 SetPVarInt(playerid, "vBlinkOn", 0);
  312.            }
  313.         }
  314.         UpdateVehicleDamageStatus(carid, d[0], d[1], d[2], d[3]);
  315.         return 1;
  316.     }
  317.     return 1;
  318. }
  319. // Thanks to JernejL (RedShirt)
  320. encode_lights(light1, light2, light3, light4) {
  321.  
  322.     return light1 | (light2 << 1) | (light3 << 2) | (light4 << 3);
  323.  
  324. }
  325.  
  326. IsPublicService(carid)
  327. {
  328.     new PS[11] = { 416, 427, 490, 528, 407, 544, 596, 598, 597, 599, 601 };
  329.     for(new i = 0; i < sizeof(PS); i++)
  330.     {
  331.         if(GetVehicleModel(carid) == PS[i]) return 1;
  332.     }
  333.     return 0;
  334. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement