Guest User

SA-MP Light Control Script (posted by Pghpunkid)

a guest
Mar 23rd, 2012
3,263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.81 KB | None | 0 0
  1. /*------------------------------------------------------------------------------
  2.  
  3. Thanks for downloading the SA-MP Light Control FS by Pghpunkid. Please feel free
  4. to modify as you need. Also, please do not redistribute without my authorization
  5. first. And if you do (with or without my permission) Please leave this header
  6. section. To make this work, simply delete the "//" before "#include" on line 16
  7. then recompile! By doing this, you agree to the above requirements and are going
  8. to follow these few rules of using this free code.
  9.  
  10. Thanks and enjoy!
  11.  
  12. -Pghpunkid
  13.  
  14. ------------------------------------------------------------------------------*/
  15.  
  16. #include <a_samp>
  17.  
  18. new LightPwr[MAX_VEHICLES];
  19. new Flasher[MAX_VEHICLES];
  20. new FlasherState[MAX_VEHICLES];
  21. new FlashTimer;
  22.  
  23. public OnFilterScriptInit()
  24. {
  25.     print("\n-----------------------------------");
  26.     print("   Light Control FS by Pghpunkid");
  27.     print("-----------------------------------\n");
  28.     for (new x=0; x<MAX_VEHICLES; x++)
  29.     {
  30.         LightPwr[x]=1;
  31.         Flasher[x]=0;
  32.         FlasherState[x]=0;
  33.     }
  34.     FlashTimer = SetTimer("FlasherFunc",100,1);
  35.     return 1;
  36. }
  37.  
  38. public OnFilterScriptExit()
  39. {
  40.     print("\n-----------------------------------");
  41.     print("     Light Control FS Unloaded");
  42.     print("-----------------------------------\n");
  43.     KillTimer(FlashTimer);
  44.     return 1;
  45. }
  46.  
  47. public OnPlayerCommandText(playerid, cmdtext[])
  48. {
  49.     new cmd[256], idx;
  50.     cmd = strtok(cmdtext, idx);
  51.     new vehicleid,panels,doors,lights,tires;
  52.     if (strcmp("/lightsoff", cmd, true) == 0)
  53.     {
  54.         vehicleid = GetPlayerVehicleID(playerid);
  55.         GetVehicleDamageStatus(vehicleid,panels,doors,lights,tires);
  56.         UpdateVehicleDamageStatus(vehicleid, panels, doors, 5, tires);
  57.         LightPwr[vehicleid] = 0;
  58.         Flasher[vehicleid] = 0;
  59.         return 1;
  60.     }
  61.     if (strcmp("/lightswat", cmd, true) == 0)
  62.     {
  63.         vehicleid = GetPlayerVehicleID(playerid);
  64.         GetVehicleDamageStatus(vehicleid,panels,doors,lights,tires);
  65.         UpdateVehicleDamageStatus(vehicleid, panels, doors, 3, tires);
  66.         LightPwr[vehicleid] = 1;
  67.         Flasher[vehicleid] = 0;
  68.         return 1;
  69.     }
  70.     if (strcmp("/lightson", cmd, true) == 0)
  71.     {
  72.         vehicleid = GetPlayerVehicleID(playerid);
  73.         GetVehicleDamageStatus(vehicleid,panels,doors,lights,tires);
  74.         UpdateVehicleDamageStatus(vehicleid, panels, doors, 0, tires);
  75.         LightPwr[vehicleid] = 1;
  76.         Flasher[vehicleid] = 0;
  77.         return 1;
  78.     }
  79.     if (strcmp("/lightsflash", cmd, true) == 0)
  80.     {
  81.         vehicleid = GetPlayerVehicleID(playerid);
  82.         GetVehicleDamageStatus(vehicleid,panels,doors,lights,tires);
  83.         Flasher[vehicleid] = 1;
  84.         return 1;
  85.     }
  86.     if (strcmp("/lightsflashoff", cmd, true) == 0)
  87.     {
  88.         vehicleid = GetPlayerVehicleID(playerid);
  89.         GetVehicleDamageStatus(vehicleid,panels,doors,lights,tires);
  90.         if (LightPwr[vehicleid] == 1)
  91.             UpdateVehicleDamageStatus(vehicleid, panels, doors, 0, tires);
  92.         else
  93.             UpdateVehicleDamageStatus(vehicleid, panels, doors, 5, tires);
  94.         Flasher[vehicleid] = 0;
  95.         return 1;
  96.     }
  97.     return 0;
  98. }
  99.  
  100. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  101. {
  102.     if (LightPwr[vehicleid] == 0)
  103.     {
  104.         new panels,doors,lights,tires;
  105.         GetVehicleDamageStatus(vehicleid,panels,doors,lights,tires);
  106.         UpdateVehicleDamageStatus(vehicleid, panels, doors, 5, tires);
  107.     }
  108.     else
  109.     {
  110.         new panels,doors,lights,tires;
  111.         GetVehicleDamageStatus(vehicleid,panels,doors,lights,tires);
  112.         UpdateVehicleDamageStatus(vehicleid, panels, doors, 0, tires);
  113.     }
  114.     return 1;
  115. }
  116.  
  117. public OnPlayerExitVehicle(playerid, vehicleid)
  118. {
  119.     Flasher[vehicleid] = 0;
  120.     if (LightPwr[vehicleid] == 0)
  121.     {
  122.         new panels,doors,lights,tires;
  123.         GetVehicleDamageStatus(vehicleid,panels,doors,lights,tires);
  124.         UpdateVehicleDamageStatus(vehicleid, panels, doors, 5, tires);
  125.     }
  126.     else
  127.     {
  128.         new panels,doors,lights,tires;
  129.         GetVehicleDamageStatus(vehicleid,panels,doors,lights,tires);
  130.         UpdateVehicleDamageStatus(vehicleid, panels, doors, 0, tires);
  131.     }
  132.     return 1;
  133. }
  134.  
  135. public OnVehicleMod(playerid, vehicleid, componentid)
  136. {
  137.     return 1;
  138. }
  139.  
  140. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  141. {
  142.     if (LightPwr[vehicleid] == 0)
  143.     {
  144.         new panels,doors,lights,tires;
  145.         GetVehicleDamageStatus(vehicleid,panels,doors,lights,tires);
  146.         UpdateVehicleDamageStatus(vehicleid, panels, doors, 5, tires);
  147.     }
  148.     return 1;
  149. }
  150.  
  151. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  152. {
  153.     if (LightPwr[vehicleid] == 0)
  154.     {
  155.         new panels,doors,lights,tires;
  156.         GetVehicleDamageStatus(vehicleid,panels,doors,lights,tires);
  157.         UpdateVehicleDamageStatus(vehicleid, panels, doors, 5, tires);
  158.     }
  159.     return 1;
  160. }
  161.  
  162. public OnPlayerStreamIn(playerid, forplayerid)
  163. {
  164.     return 1;
  165. }
  166.  
  167. public OnPlayerStreamOut(playerid, forplayerid)
  168. {
  169.     return 1;
  170. }
  171.  
  172. public OnVehicleStreamIn(vehicleid, forplayerid)
  173. {
  174.     if (LightPwr[vehicleid] == 0)
  175.     {
  176.         new panels,doors,lights,tires;
  177.         GetVehicleDamageStatus(vehicleid,panels,doors,lights,tires);
  178.         UpdateVehicleDamageStatus(vehicleid, panels, doors, 5, tires);
  179.     }
  180.     return 1;
  181. }
  182.  
  183. public OnVehicleStreamOut(vehicleid, forplayerid)
  184. {
  185.     return 1;
  186. }
  187.  
  188. //Option A
  189. /*
  190. public OnPlayerUpdate(playerid)
  191. {
  192.     if (IsPlayerInAnyVehicle(playerid))
  193.     {
  194.         new id;
  195.         id = GetPlayerVehicleID(playerid);
  196.         if (Flasher[id] == 1)
  197.         {
  198.             if (FlasherState[id] == 1)
  199.             {
  200.                 new panels,doors,lights,tires;
  201.                 GetVehicleDamageStatus(id,panels,doors,lights,tires);
  202.                 UpdateVehicleDamageStatus(id, panels, doors, 4, tires);
  203.                 FlasherState[id] = 0;
  204.             }
  205.             else {
  206.                 new panels,doors,lights,tires;
  207.                 GetVehicleDamageStatus(id,panels,doors,lights,tires);
  208.                 UpdateVehicleDamageStatus(id, panels, doors, 1, tires);
  209.                 FlasherState[id] = 1;
  210.             }
  211.         }
  212.     }
  213.     return 1;
  214. }
  215. */
  216.  
  217. //Option B
  218.  
  219. forward FlasherFunc();
  220. public FlasherFunc() {
  221.     for (new p=0; p<MAX_PLAYERS; p++)
  222.     {
  223.         if (IsPlayerInAnyVehicle(p) && IsPlayerConnected(p) && !IsPlayerNPC(p))
  224.         {
  225.             new id;
  226.             new panelsx,doorsx,lightsx,tiresx;
  227.             id = GetPlayerVehicleID(p);
  228.             if (Flasher[id] == 1)
  229.             {
  230.                 if (FlasherState[id] == 1)
  231.                 {
  232.                     GetVehicleDamageStatus(id,panelsx,doorsx,lightsx,tiresx);
  233.                     UpdateVehicleDamageStatus(id, panelsx, doorsx, 4, tiresx);
  234.                     FlasherState[id] = 0;
  235.                 }
  236.                 else {
  237.                     GetVehicleDamageStatus(id,panelsx,doorsx,lightsx,tiresx);
  238.                     UpdateVehicleDamageStatus(id, panelsx, doorsx, 1, tiresx);
  239.                     FlasherState[id] = 1;
  240.                 }
  241.             }
  242.         }
  243.     }
  244.     return 1;
  245. }
  246.  
  247. strtok(const string[], &index)
  248. {
  249.     new length = strlen(string);
  250.     while ((index < length) && (string[index] <= ' '))
  251.     {
  252.         index++;
  253.     }
  254.  
  255.     new offset = index;
  256.     new result[20];
  257.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  258.     {
  259.         result[index - offset] = string[index];
  260.         index++;
  261.     }
  262.     result[index - offset] = EOS;
  263.     return result;
  264. }
  265.  
  266. stock DelPrint(string1[])
  267. {
  268.     strmid(string1, string1, 0, strlen(string1)-1, 255);
  269.     //printf("%s", string1);
  270.     return 1;
  271. }
Advertisement
Add Comment
Please, Sign In to add comment