Advertisement
Phanto90

PFuel & Engine & Lights System

Apr 27th, 2011
4,276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 14.77 KB | None | 0 0
  1. /*
  2. ================================================================================
  3.                                Phanto's Script
  4.                                      2011
  5. ________________________________________________________________________________
  6. •Script: PFuel&Engine&Lights •Scripter: Phanto90
  7. •Type: FS                    •File size: 15 Kb(.pwn) / 18 Kb(.amx)
  8. •Lines: 353                  •Version: 1.0v
  9. ________________________________________________________________________________
  10.                               * Description *
  11.                              
  12.            (As always, sorry for my bad way of writing english :D)
  13.  
  14. This week I decided to script a simple & nice fuel system, and in one hour of
  15. work and few tests here it is.
  16. I decided to use Incognito's Streamer for the TextLabel. Actually it is pretty
  17. useless for the Filterscript itself, but i thought a lot of Gamemodes uses it.
  18. If you don't use Incognito's streamer, simply modify the script.
  19.  
  20. System:
  21. •Fuel System
  22. •Engine System (Press ALT SX to turn on/off)
  23. •Lights System (Press 2 to turn on/off)
  24. •Some Fuel Station added (I don't think i added every fuel station in San Andreas,
  25.  but you can modify that by increasing/decreasing MAX_STATIONS and coords)
  26. •If your vehicle run out of fuel you can buy some tanks and refill it by typing
  27.  /refuel when you are in it.
  28.  
  29. Credits:
  30.  •Thanks to Incognito for his Streamer.
  31.  
  32. Faq:
  33.  -The Server do not run when I load PFuel. What should I do?
  34.  •Be sure to have Incognito's Streamer Plugin loaded. You can find it on forum-samp.
  35.  
  36. Note: -Be sure not to have other Fuel System loaded on your server.
  37.       -I noticed that if it is loaded Zamaroth's Textdraws Editor, the FS does
  38.        not work properly. Be sure not to have it loaded when using PFuel.
  39.  
  40.  
  41.                      Thanks for choosing Pawnoscripter!
  42.                      http://pawnoscripter.forumfree.it
  43.  
  44.                                                                       Phanto90
  45. ________________________________________________________________________________
  46. Do not remove credits.
  47. ================================================================================
  48. */
  49. #include <a_samp>
  50. #include <streamer>
  51. //===============DIALOGS
  52. #define MAINDIALOG 12056
  53. #define FUELDIALOG 12057
  54. #define TANKDIALOG 12058
  55. //===============FOR KEYS
  56. #define PRESSED(%0) \
  57.     (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
  58. //================VAR
  59. new Float:VFuel[MAX_VEHICLES];
  60. new Tank[MAX_PLAYERS];
  61. new engine,lights,alarm,doors,bonnet,boot,objective;
  62. //================FUEL_STATIONS
  63. #define MAX_STATIONS 26
  64. new Float:Station[MAX_STATIONS][3]={
  65. {1944.3717,-1772.7307,13.3906},
  66. {1939.1682,-1772.8269,13.3828},
  67. {-99.0707,-1173.1080,2.4191},
  68. {-93.8733,-1160.8280,2.1795},
  69. {-87.3328,-1164.6559,2.2693},
  70. {-91.9832,-1176.1752,2.1985},
  71. {-1668.9750,407.6899,7.1797},
  72. {-1675.1237,413.9737,7.1797},
  73. {-1681.9315,420.2315,7.1797},
  74. {-2407.6882,976.9827,45.2969},
  75. {-1609.0656,-2718.9431,48.5391},
  76. {-1605.5094,-2714.2961,48.5335},
  77. {-1602.4349,-2709.7388,48.5391},
  78. {-1465.0649,1866.5117,32.6328},
  79. {-1477.5488,1865.7651,32.6398},
  80. {-1477.4956,1858.0613,32.6398},
  81. {-1464.8992,1858.6085,32.6328},
  82. {-1328.7679,2671.9915,50.0625},
  83. {-1328.3496,2677.5759,50.0625},
  84. {-1327.6848,2682.9897,50.0625},
  85. {2205.7717,2474.5010,10.8203},
  86. {2199.0620,2474.8723,10.8203},
  87. {2639.7009,1102.9178,10.8203},
  88. {2639.8220,1109.6555,10.8203},
  89. {1381.3658,457.4052,19.9383},
  90. {1383.1332,461.8247,20.1210}
  91. };
  92. //================TEXT
  93. new Text:Background0,Text:Background1,Text:Fuel[MAX_VEHICLES],Text:FuelLvl;
  94.  
  95. //=====================================================================LOADPFUEL
  96. public OnFilterScriptInit()
  97. {
  98.     print("*______________________*");
  99.     print(" PFuel 1.0v by Phanto90 ");
  100.     print("*______________________*");
  101.     for(new i=0;i<MAX_STATIONS;i++)
  102.     {
  103.     CreateDynamic3DTextLabel("[{C14124}Fuel Station{FFFFFF}]\n  Press SPACE", 0xFFFFFFFF, Station[i][0], Station[i][1], Station[i][2], 100, INVALID_PLAYER_ID,INVALID_VEHICLE_ID,0, -1, -1,-1);
  104.     }
  105.     SetTimer("FuelTimer",10000,true);
  106.     SetTimer("TextDraw",500,true);
  107.     ManualVehicleEngineAndLights();
  108.    
  109.     Background0 = TextDrawCreate(504.000000, 130.000000, "Background");
  110.     TextDrawBackgroundColor(Background0, 0);
  111.     TextDrawFont(Background0, 1);
  112.     TextDrawLetterSize(Background0, 0.500000, 1.000000);
  113.     TextDrawColor(Background0, 0);
  114.     TextDrawSetOutline(Background0, 0);
  115.     TextDrawSetProportional(Background0, 1);
  116.     TextDrawSetShadow(Background0, 1);
  117.     TextDrawUseBox(Background0, 1);
  118.     TextDrawBoxColor(Background0, 255);
  119.     TextDrawTextSize(Background0, 602.000000, 0.000000);
  120.  
  121.     Background1 = TextDrawCreate(506.000000, 133.000000, "Background2");
  122.     TextDrawBackgroundColor(Background1, 0);
  123.     TextDrawFont(Background1, 1);
  124.     TextDrawLetterSize(Background1, 0.500000, 0.399999);
  125.     TextDrawColor(Background1, 0);
  126.     TextDrawSetOutline(Background1, 0);
  127.     TextDrawSetProportional(Background1, 1);
  128.     TextDrawSetShadow(Background1, 1);
  129.     TextDrawUseBox(Background1, 1);
  130.     TextDrawBoxColor(Background1, 2018514120);
  131.     TextDrawTextSize(Background1, 600.000000, 0.000000);
  132.  
  133.     FuelLvl = TextDrawCreate(502.000000, 114.000000, "Fuel level");
  134.     TextDrawBackgroundColor(FuelLvl, 255);
  135.     TextDrawFont(FuelLvl, 0);
  136.     TextDrawLetterSize(FuelLvl, 0.549999, 1.800000);
  137.     TextDrawColor(FuelLvl, -1);
  138.     TextDrawSetOutline(FuelLvl, 0);
  139.     TextDrawSetProportional(FuelLvl, 1);
  140.     TextDrawSetShadow(FuelLvl, 1);
  141.    
  142.     for(new i=1;i<MAX_VEHICLES;i++)
  143.     {
  144.     VFuel[i]=random(100);
  145.     Fuel[i] = TextDrawCreate(506.000000, 133.000000, "Fuel");
  146.     TextDrawBackgroundColor(Fuel[i], 0);
  147.     TextDrawFont(Fuel[i], 1);
  148.     TextDrawLetterSize(Fuel[i], 0.500000, 0.399999);
  149.     TextDrawColor(Fuel[i], 0);
  150.     TextDrawSetOutline(Fuel[i], 0);
  151.     TextDrawSetProportional(Fuel[i], 1);
  152.     TextDrawSetShadow(Fuel[i], 1);
  153.     TextDrawUseBox(Fuel[i], 1);
  154.     TextDrawBoxColor(Fuel[i], -932962561);
  155.     TextDrawTextSize(Fuel[i], 600.000000, 0.000000);
  156.     }
  157. }
  158. //=====================================================================FUELTIMER
  159. forward FuelTimer();
  160. public FuelTimer()
  161. {
  162.   for(new i=1;i<MAX_VEHICLES;i++)
  163.   {
  164.    TextDrawTextSize(Fuel[i], 500.0+VFuel[i], 0.000000);
  165.    GetVehicleParamsEx(i,engine,lights,alarm,doors,bonnet,boot,objective);
  166.    if(engine==1 && IsAValidVehicle(i))
  167.     {
  168.     VFuel[i]=VFuel[i]-0.1;
  169.     if(VFuel[i]<=0)
  170.      {
  171.      SetVehicleParamsEx(i,0,0,alarm,doors,bonnet,boot,objective);
  172.      VFuel[i]=0;
  173.      }
  174.     }
  175.   }
  176.   return 1;
  177. }
  178. //===========================================================ONPLAYERSTATECHANGE
  179. public OnPlayerStateChange(playerid,newstate,oldstate)
  180. {
  181.  if(newstate==PLAYER_STATE_DRIVER)
  182.  {
  183.  GetVehicleParamsEx(GetPlayerVehicleID(playerid),engine,lights,alarm,doors,bonnet,boot,objective);
  184.  if(!IsAValidVehicle(GetPlayerVehicleID(playerid))) return SetVehicleParamsEx(GetPlayerVehicleID(playerid),1,lights,alarm,doors,bonnet,boot,objective);
  185.  if(engine==1) SendClientMessage(playerid,0xFFFFFFFF,"[ENGINE:] The engine is on. To turn it off press {C14124}ALT SX");
  186.  else SendClientMessage(playerid,0xFFFFFFFF,"[ENGINE:] The engine is off. To turn it on press {C14124}ALT SX");
  187.  TextDrawShowForPlayer(playerid,Background0);
  188.  TextDrawShowForPlayer(playerid,Background1);
  189.  TextDrawShowForPlayer(playerid,FuelLvl);
  190.  TextDrawShowForPlayer(playerid,Fuel[GetPlayerVehicleID(playerid)]);
  191.  return 1;
  192.  }
  193.  if(newstate==PLAYER_STATE_ONFOOT)
  194.  {
  195.   TextDrawHideForPlayer(playerid,Fuel[playerid]);
  196.   TextDrawHideForPlayer(playerid,Background0);
  197.   TextDrawHideForPlayer(playerid,Background1);
  198.   TextDrawHideForPlayer(playerid,FuelLvl);
  199.   return 1;
  200.  }
  201.  return 1;
  202. }
  203. //===========================================================ONPLAYEREXITVEHICLE
  204. public OnPlayerExitVehicle(playerid)
  205. {
  206.   GetVehicleParamsEx(GetPlayerVehicleID(playerid),engine,lights,alarm,doors,bonnet,boot,objective);
  207.   if(!IsAValidVehicle(GetPlayerVehicleID(playerid))) SetVehicleParamsEx(GetPlayerVehicleID(playerid),0,lights,alarm,doors,bonnet,boot,objective);
  208.   return 1;
  209. }
  210. //========================================================ONPLAYERKEYSTATECHANGE
  211. public OnPlayerKeyStateChange(playerid,newkeys,oldkeys)
  212. {
  213.  if(PRESSED(KEY_SUBMISSION) && GetPlayerState(playerid)==PLAYER_STATE_DRIVER)
  214.  {
  215.  GetVehicleParamsEx(GetPlayerVehicleID(playerid),engine,lights,alarm,doors,bonnet,boot,objective);
  216.  if(lights==1)
  217.  SetVehicleParamsEx(GetPlayerVehicleID(playerid),engine,0,alarm,doors,bonnet,boot,objective);
  218.  else
  219.  SetVehicleParamsEx(GetPlayerVehicleID(playerid),engine,1,alarm,doors,bonnet,boot,objective);
  220.  return 1;
  221.  }
  222. //=====================================================KEYFIRE
  223.  if(PRESSED(KEY_FIRE))
  224.  {
  225.  //==================ENGINE ON
  226.  if(GetPlayerState(playerid)==PLAYER_STATE_DRIVER && IsAValidVehicle(GetPlayerVehicleID(playerid)))
  227.  {
  228.  GetVehicleParamsEx(GetPlayerVehicleID(playerid),engine,lights,alarm,doors,bonnet,boot,objective);
  229.  if(VFuel[GetPlayerVehicleID(playerid)]<=0) return SendClientMessage(playerid,0xFF0000FF,"[ERROR:] {FFFFFF}The vehicle run out of fuel.");
  230.  if(engine<=0)
  231.    {
  232.    SetVehicleParamsEx(GetPlayerVehicleID(playerid),1,lights,alarm,doors,bonnet,boot,objective);
  233.    SendClientMessage(playerid,0xFFFFFFFF,"[ENGINE:] You turn on the engine.");
  234.    return 1;
  235.    }
  236.  else
  237.    {
  238.    SetVehicleParamsEx(GetPlayerVehicleID(playerid),0,lights,alarm,doors,bonnet,boot,objective);
  239.    SendClientMessage(playerid,0xFFFFFFFF,"[ENGINE:] You turn off the engine.");
  240.    return 1;
  241.    }
  242.  }
  243.  }
  244. //=======================================================KEYBRAKE
  245.  if(PRESSED(KEY_HANDBRAKE) || PRESSED(KEY_SPRINT))
  246.  {
  247.  //================FUEL STATION
  248.  for(new i=0;i<MAX_STATIONS;i++)
  249.   {
  250.   if(IsPlayerInRangeOfPoint(playerid,3,Station[i][0],Station[i][1],Station[i][2]))
  251.     {
  252.     if(!IsPlayerInAnyVehicle(playerid) && PRESSED(KEY_SPRINT))
  253.     return ShowPlayerDialog(playerid,TANKDIALOG,0,"Tank menù","{DEDEDE}Do you want to buy a {c14124}Fuel Tank{DEDEDE} of 10 lt. \nfor {89FF56}40${DEDEDE}?","Yes","No");
  254.     else if(GetPlayerState(playerid)==PLAYER_STATE_DRIVER && IsAValidVehicle(GetPlayerVehicleID(playerid)) && PRESSED(KEY_HANDBRAKE))
  255.     return ShowPlayerDialog(playerid,MAINDIALOG,DIALOG_STYLE_LIST,"Station menù","{c14124}Refuel {DEDEDE} your vehicle.\nBuy a {c14124}Fuel Tank{DEDEDE} of 10 lt.","Select","Exit");
  256.     }
  257.   }
  258.  }
  259.  return 1;
  260. }
  261. //==============================================================ONDIALOGRESPONSE
  262. public OnDialogResponse(playerid,dialogid,response,listitem,inputtext[])
  263. {
  264.  //=========================TANKDIALOG
  265.  if(dialogid==TANKDIALOG && response)
  266.  {
  267.  GivePlayerMoney(playerid,-40);
  268.  SendClientMessage(playerid,0xFFFFFFFF,"[TANK:]You buyied a {C14124}fuel tank{FFFFFF}.");
  269.  Tank[playerid]+=1;
  270.  return 1;
  271.  }
  272.  //=========================MAINDIALOG
  273.  if(dialogid==MAINDIALOG && response)
  274.  {
  275.  if (listitem==0)
  276.  return ShowPlayerDialog(playerid,FUELDIALOG,DIALOG_STYLE_INPUT,"Fuel menu","{DEDEDE}Welcome to the gas station!\nPlease inserit the number of gallons you want to refill to your vehicle.\n {C14124}1 gallon {DEDEDE}= {C14124}2$","Refuel","Exit");
  277.  if (listitem==1)
  278.  return ShowPlayerDialog(playerid,TANKDIALOG,0,"Tank menù","{DEDEDE}Do you want to buy a {c14124}Fuel Tank{DEDEDE} of 10 lt. \nfor {89FF56}40${DEDEDE}?","Yes","No");
  279.  }
  280.  //=========================FUELDIALOG
  281.  if(dialogid==FUELDIALOG && response)
  282.  {
  283.  if(VFuel[GetPlayerVehicleID(playerid)]>=100) return SendClientMessage(playerid,0xFF0000FF,"[ERROR:] {FFFFFF}Your vehicle is full of fuel");
  284.  if(strval(inputtext)<=0 || strval(inputtext)>100)  return ShowPlayerDialog(playerid,FUELDIALOG,DIALOG_STYLE_INPUT,"Fuel menu","{C14124}Error: inserit a number between 0 and 100 gallons.\n\n{DEDEDE}Welcome to the gas station!\nPlease inserit the number of gallons you want to refill to your vehicle.\n {C14124}1 gallon {DEDEDE}= {C14124}2$","Refuel","Exit");
  285.  if(VFuel[GetPlayerVehicleID(playerid)]+ strval(inputtext) > 100.0) return SendClientMessage(playerid,0xFF0000FF,"[ERROR:] {FFFFFF}You can't refill your vehicle with so many gallons");
  286.  VFuel[GetPlayerVehicleID(playerid)]=VFuel[GetPlayerVehicleID(playerid)]+strval(inputtext);
  287.  GivePlayerMoney(playerid,-strval(inputtext)*2);
  288.  new stringa[256];
  289.  format(stringa,sizeof(stringa),"[FUEL:] You filled your vehicle with {C14124}%d {FFFFFF}gallons for {C14124}%d$",strval(inputtext),strval(inputtext)*2);
  290.  SendClientMessage(playerid,0xFFFFFFFF,stringa);
  291.  return 1;
  292.  }
  293.  return 1;
  294. }
  295. //===============================================================ISAVALIDVEHICLE
  296. stock IsAValidVehicle(vehicleid)
  297. {
  298.  new x=GetVehicleModel(vehicleid);
  299.  if(x>=400 && x!=509 && x!=481 && x!=510 && x!=548 && x!=425 && x!=417 && x!=487 && x!=488 && x!=497 && x!=563 && x!=447 && x!=469 && x!=592 && x!=577 && x!=511 && x!=512 && x!=593 && x!=520 && x!=553 && x!=476 && x!= 519 &&
  300.     x!=460 && x!=513 && x!=472 && x!=473 && x!=493 && x!=595 && x!=484 && x!=430 && x!=453 && x!=452 && x!=446 && x!=454 && x!=449 && x!=537 && x!=538)
  301.  return 1;
  302.  else return 0;
  303. }
  304. //================================================================ONPLAYERUPDATE
  305. forward TextDraw();
  306. public TextDraw()
  307. {
  308.  for(new i=0;i<MAX_PLAYERS;i++)
  309.  {
  310.  if(GetPlayerState(i)==PLAYER_STATE_DRIVER && GetPlayerState(i)!=PLAYER_STATE_EXIT_VEHICLE && IsAValidVehicle(GetPlayerVehicleID(i)))
  311.  {
  312.  TextDrawHideForPlayer(i,Fuel[GetPlayerVehicleID(i)]);
  313.  TextDrawTextSize(Fuel[GetPlayerVehicleID(i)], 500.0+VFuel[i], 0.000000);
  314.  TextDrawShowForPlayer(i,Fuel[GetPlayerVehicleID(i)]);
  315.  }
  316.  }
  317.  return 1;
  318. }
  319. //================================================================ONVEHICLESPAWN
  320. public OnVehicleSpawn(vehicleid)
  321. {
  322.  VFuel[vehicleid]=random(100);
  323.  return 1;
  324. }
  325. //===========================================================ONPLAYERCOMMANDTEXT
  326. public OnPlayerCommandText(playerid,cmdtext[])
  327. {
  328.  if(!strcmp("/refuel",cmdtext,true))
  329.  {
  330.  if(GetPlayerState(playerid)!=PLAYER_STATE_DRIVER) return SendClientMessage(playerid,0xFF0000FF,"[ERROR:] {FFFFFF}You are not driving a vehicle.");
  331.  if(!IsAValidVehicle(GetPlayerVehicleID(playerid))) return SendClientMessage(playerid,0xFF0000FF,"[ERROR:] {FFFFFF}This type of vehicle does not need to be refilled with fuel");
  332.  if(!Tank[playerid]) return SendClientMessage(playerid,0xFF0000FF,"[ERROR:] {FFFFFF}You have no tank to refuel the vehicle");
  333.  if(VFuel[GetPlayerVehicleID(playerid)]>90) return SendClientMessage(playerid,0xFF0000FF,"[ERROR:] {FFFFFF}You have enough fuel for now.");
  334.  Tank[playerid]--;
  335.  VFuel[GetPlayerVehicleID(playerid)]+=10;
  336.  SendClientMessage(playerid,0x00FF00FF,"[VEHICLE:] {FFFFFF}You refilled successfully your vehicle.");
  337.  return 1;
  338.  }
  339.  return 0;
  340. }
  341. //=====================================================================ISNUMERIC
  342. stock isNumeric(const string[])
  343. {
  344.     new length=strlen(string);
  345.     if (length==0) return false;
  346.     for (new i = 0; i < length; i++) {
  347.         if (
  348.         (string[i] > '9' || string[i] < '0' && string[i]!='-' && string[i]!='+')
  349.         || (string[i]=='-' && i!=0)
  350.         || (string[i]=='+' && i!=0)
  351.         ) return false;
  352.     }
  353.     if (length==1 && (string[0]=='-' || string[0]=='+')) return false;
  354.     return true;
  355. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement