Guest User

Camacorn's Ultimate Vehicle Control, Dialog Edition! [0.3c]

a guest
Dec 8th, 2010
1,583
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 14.30 KB | None | 0 0
  1. // Ultimate Vehicle Control by Camacorn
  2. // Keep These Credits Please
  3.  
  4. // Includes
  5. #include <a_samp>
  6. #include <zcmd>
  7.  
  8. // Colors
  9. #define RED             0xE60000FF
  10. #define ORANGE          0xF97804FF
  11. #define NICESKY         0x00C2ECFF
  12. #define WHITE           0xFFFFFFFF
  13.  
  14. // Defines
  15. new bool:Engine[MAX_VEHICLES];
  16. new DoorInfo[MAX_PLAYERS], AlarmInfo[MAX_PLAYERS], HoodInfo[MAX_PLAYERS], TrunkInfo[MAX_PLAYERS];
  17. new LightPwr[3000];
  18.  
  19. // Script
  20. public OnFilterScriptInit()
  21. {
  22.     print("\n--------------------------------------");
  23.     print(" Ultimate Vehicle Control By Camacorn   ");
  24.     print(" Started..............................  ");
  25.     print("--------------------------------------\n");
  26.     for (new x=0; x<MAX_VEHICLES; x++)
  27.     {
  28.         LightPwr[x]=1;
  29.     }
  30.     return 1;
  31. }
  32. public OnFilterScriptExit()
  33. {
  34.     print("\n--------------------------------------");
  35.     print(" Ultimate Vehicle Control By Camacorn   ");
  36.     print(" Exited...............................  ");
  37.     print("--------------------------------------\n");
  38.     return 1;
  39. }
  40.  
  41. // Stocks
  42. stock sscanf(string[], format[], {Float,_}:...)
  43. {
  44.     #if defined isnull
  45.     if (isnull(string))
  46.         #else
  47.     if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  48.         #endif
  49.     {
  50.         return format[0];
  51.     }
  52.     #pragma tabsize 4
  53.     new
  54.     formatPos = 0,
  55.     stringPos = 0,
  56.     paramPos = 2,
  57.     paramCount = numargs(),
  58.     delim = ' ';
  59.     while (string[stringPos] && string[stringPos] <= ' ')
  60.     {
  61.         stringPos++;
  62.     }
  63.     while (paramPos < paramCount && string[stringPos])
  64.     {
  65.         switch (format[formatPos++])
  66.         {
  67.             case '\0':
  68.             {
  69.                 return 0;
  70.             }
  71.             case 'i', 'd':
  72.             {
  73.                 new
  74.                 neg = 1,
  75.                 num = 0,
  76.                 ch = string[stringPos];
  77.                 if (ch == '-')
  78.                 {
  79.                     neg = -1;
  80.                     ch = string[++stringPos];
  81.                 }
  82.                 do
  83.                 {
  84.                     stringPos++;
  85.                     if ('0' <= ch <= '9')
  86.                     {
  87.                         num = (num * 10) + (ch - '0');
  88.                     }
  89.                     else
  90.                     {
  91.                         return -1;
  92.                     }
  93.                 }
  94.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  95.                     setarg(paramPos, 0, num * neg);
  96.             }
  97.             case 'h', 'x':
  98.             {
  99.                 new
  100.                 num = 0,
  101.                 ch = string[stringPos];
  102.                 do
  103.                 {
  104.                     stringPos++;
  105.                     switch (ch)
  106.                     {
  107.                         case 'x', 'X':
  108.                         {
  109.                             num = 0;
  110.                             continue;
  111.                         }
  112.                         case '0' .. '9':
  113.                         {
  114.                             num = (num << 4) | (ch - '0');
  115.                         }
  116.                         case 'a' .. 'f':
  117.                         {
  118.                             num = (num << 4) | (ch - ('a' - 10));
  119.                         }
  120.                         case 'A' .. 'F':
  121.                         {
  122.                             num = (num << 4) | (ch - ('A' - 10));
  123.                         }
  124.                         default:
  125.                         {
  126.                             return -1;
  127.                         }
  128.                     }
  129.                 }
  130.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  131.                     setarg(paramPos, 0, num);
  132.             }
  133.             case 'c':
  134.             {
  135.                 setarg(paramPos, 0, string[stringPos++]);
  136.             }
  137.             case 'f':
  138.             {
  139.  
  140.                 new changestr[16], changepos = 0, strpos = stringPos;
  141.                 while(changepos < 16 && string[strpos] && string[strpos] != delim)
  142.                 {
  143.                     changestr[changepos++] = string[strpos++];
  144.                 }
  145.                 changestr[changepos] = '\0';
  146.                 setarg(paramPos,0,_:floatstr(changestr));
  147.             }
  148.             case 'p':
  149.             {
  150.                 delim = format[formatPos++];
  151.                 continue;
  152.             }
  153.             case '\'':
  154.             {
  155.                 new
  156.                 end = formatPos - 1,
  157.                 ch;
  158.                 while ((ch = format[++end]) && ch != '\'') {}
  159.                 if (!ch)
  160.                 {
  161.                     return -1;
  162.                 }
  163.                 format[end] = '\0';
  164.                 if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  165.                 {
  166.                     if (format[end + 1])
  167.                     {
  168.                         return -1;
  169.                     }
  170.                     return 0;
  171.                 }
  172.                 format[end] = '\'';
  173.                 stringPos = ch + (end - formatPos);
  174.                 formatPos = end + 1;
  175.             }
  176.             case 'u':
  177.             {
  178.                 new
  179.                 end = stringPos - 1,
  180.                 id = 0,
  181.                 bool:num = true,
  182.                 ch;
  183.                 while ((ch = string[++end]) && ch != delim)
  184.                 {
  185.                     if (num)
  186.                     {
  187.                         if ('0' <= ch <= '9')
  188.                         {
  189.                             id = (id * 10) + (ch - '0');
  190.                         }
  191.                         else
  192.                         {
  193.                             num = false;
  194.                         }
  195.                     }
  196.                 }
  197.                 if (num && IsPlayerConnected(id))
  198.                 {
  199.                     setarg(paramPos, 0, id);
  200.                 }
  201.                 else
  202.                 {
  203.                     #if !defined foreach
  204.                     #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  205.                     #define __SSCANF_FOREACH__
  206.                     #endif
  207.                     string[end] = '\0';
  208.                     num = false;
  209.                     new
  210.                     name[MAX_PLAYER_NAME];
  211.                     id = end - stringPos;
  212.                     foreach (Player, playerid)
  213.                     {
  214.                         GetPlayerName(playerid, name, sizeof (name));
  215.                         if (!strcmp(name, string[stringPos], true, id))
  216.                         {
  217.                             setarg(paramPos, 0, playerid);
  218.                             num = true;
  219.                             break;
  220.                         }
  221.                     }
  222.                     if (!num)
  223.                     {
  224.                         setarg(paramPos, 0, INVALID_PLAYER_ID);
  225.                     }
  226.                     string[end] = ch;
  227.                     #if defined __SSCANF_FOREACH__
  228.                     #undef foreach
  229.                     #undef __SSCANF_FOREACH__
  230.                     #endif
  231.                 }
  232.                 stringPos = end;
  233.             }
  234.             case 's', 'z':
  235.             {
  236.                 new
  237.                 i = 0,
  238.                 ch;
  239.                 if (format[formatPos])
  240.                 {
  241.                     while ((ch = string[stringPos++]) && ch != delim)
  242.                     {
  243.                         setarg(paramPos, i++, ch);
  244.                     }
  245.                     if (!i)
  246.                     {
  247.                         return -1;
  248.                     }
  249.                 }
  250.                 else
  251.                 {
  252.                     while ((ch = string[stringPos++]))
  253.                     {
  254.                         setarg(paramPos, i++, ch);
  255.                     }
  256.                 }
  257.                 stringPos--;
  258.                 setarg(paramPos, i, '\0');
  259.             }
  260.             default:
  261.             {
  262.                 continue;
  263.             }
  264.         }
  265.         while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  266.         {
  267.             stringPos++;
  268.         }
  269.         while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  270.         {
  271.             stringPos++;
  272.         }
  273.         paramPos++;
  274.     }
  275.     do
  276.     {
  277.         if ((delim = format[formatPos++]) > ' ')
  278.         {
  279.             if (delim == '\'')
  280.             {
  281.                 while ((delim = format[formatPos++]) && delim != '\'') {}
  282.             }
  283.             else if (delim != 'z')
  284.             {
  285.                 return delim;
  286.             }
  287.         }
  288.     }
  289.     while (delim > ' ');
  290.         return 0;
  291. }
  292.  
  293. public OnGameModeInit()
  294. {
  295.     ManualVehicleEngineAndLights();
  296.     return 1;
  297. }
  298.  
  299. public OnVehicleRespray( playerid, vehicleid, color1, color2)
  300. {
  301.     if (LightPwr[vehicleid] == 0)
  302.     {
  303.         new panels,doors,lights,tires;
  304.         GetVehicleDamageStatus(vehicleid,panels,doors,lights,tires);
  305.         UpdateVehicleDamageStatus(vehicleid, panels, doors, 5, tires);
  306.     }
  307.     return 1;
  308. }
  309. public OnDialogResponse( playerid, dialogid, response, listitem, inputtext[])
  310. {
  311.     if(dialogid == 1)
  312.     {
  313.         if(response)
  314.         {
  315.             new Float:x,Float:y,Float:z,Float:ang;
  316.             SetVehicleNumberPlate(GetPlayerVehicleID(playerid), inputtext);
  317.             GetVehiclePos(GetPlayerVehicleID(playerid),x,y,z);
  318.             GetVehicleZAngle(GetPlayerVehicleID(playerid),ang);
  319.             SetVehicleToRespawn(GetPlayerVehicleID(playerid));
  320.             SetVehiclePos(GetPlayerVehicleID(playerid),x,y,z);
  321.             PutPlayerInVehicle(playerid,GetPlayerVehicleID(playerid),0);
  322.             SetVehicleZAngle(GetPlayerVehicleID(playerid),ang);
  323.         }
  324.     }
  325.     if(dialogid == 999)
  326.     {
  327.         new Float:x,Float:y,Float:z,Float:ang;
  328.         new vehicleid = GetPlayerVehicleID(playerid);
  329.         new engine,lights,alarm,doors,bonnet,boot,objective,panels,tires;
  330.         if(!response) return SendClientMessage(playerid, ORANGE,"Sorry, You Clicked Cancel!");
  331.         switch(listitem)
  332.         {
  333.             case 0:
  334.             {
  335.                 if( LightPwr[vehicleid] == 1)
  336.                 {
  337.                     //vehicleid = GetPlayerVehicleID(playerid);
  338.                     GetVehicleDamageStatus(vehicleid,panels,doors,lights,tires);
  339.                     UpdateVehicleDamageStatus(vehicleid, panels, doors, 5, tires);
  340.                     SendClientMessage(playerid,WHITE,"Lights {E31919}off!");
  341.                     LightPwr[vehicleid] = 0;
  342.                 }
  343.                 else if( LightPwr[vehicleid] == 0)
  344.                 {
  345.                     //vehicleid = GetPlayerVehicleID(playerid);
  346.                     GetVehicleDamageStatus(vehicleid,panels,doors,lights,tires);
  347.                     UpdateVehicleDamageStatus(vehicleid, panels, doors, 0, tires);
  348.                     SendClientMessage(playerid,WHITE,"Lights {2F991A}on!");
  349.                     SendClientMessage(playerid,ORANGE,"Remember that if it's light out, the lights wont be visible!");
  350.                     LightPwr[vehicleid] = 1;
  351.                 }
  352.             }
  353.             case 1:
  354.             {
  355.                 if(DoorInfo[playerid] == 0)
  356.                 {
  357.                     GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
  358.                     SetVehicleParamsEx(vehicleid,engine,lights,alarm,VEHICLE_PARAMS_ON,bonnet,boot,objective);
  359.                     DoorInfo[playerid] = 1;
  360.                     SendClientMessage(playerid, WHITE, "Doors {E31919}Locked!");
  361.                 }
  362.                 else if(DoorInfo[playerid] == 1)
  363.                 {
  364.                     GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
  365.                     SetVehicleParamsEx(vehicleid,engine,lights,alarm,VEHICLE_PARAMS_OFF,bonnet,boot,objective);
  366.                     DoorInfo[playerid] = 0;
  367.                     SendClientMessage(playerid, WHITE, "Doors {2F991A}Unlocked!");
  368.                 }
  369.             }
  370.             case 2:
  371.             {
  372.                 if(HoodInfo[playerid] == 0)
  373.                 {
  374.                     GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
  375.                     SetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,VEHICLE_PARAMS_ON,boot,objective);
  376.                     HoodInfo[playerid] = 1;
  377.                     SendClientMessage(playerid, WHITE, "Hood {2F991A}open!");
  378.                 }
  379.                 else if(HoodInfo[playerid] == 1)
  380.                 {
  381.                     GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
  382.                     SetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,VEHICLE_PARAMS_OFF,boot,objective);
  383.                     HoodInfo[playerid] = 0;
  384.                     SendClientMessage(playerid, WHITE, "Hood {E31919}closed!");
  385.                 }
  386.             }
  387.             case 3:
  388.             {
  389.                 if(TrunkInfo[playerid] == 0)
  390.                 {
  391.                     GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
  392.                     SetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,VEHICLE_PARAMS_ON,objective);
  393.                     TrunkInfo[playerid] = 1;
  394.                     SendClientMessage(playerid, WHITE, "Trunk {2F991A}open!");
  395.                 }
  396.                 else if(TrunkInfo[playerid] == 1)
  397.                 {
  398.                     GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
  399.                     SetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,VEHICLE_PARAMS_OFF,objective);
  400.                     TrunkInfo[playerid] = 0;
  401.                     SendClientMessage(playerid, WHITE, "Trunk {E31919}closed!");
  402.                 }
  403.             }
  404.             case 4:
  405.             {
  406.                 if(Engine[vehicleid] == true)
  407.                 {
  408.                     if(!Engine[vehicleid]) return SendClientMessage(playerid,WHITE,"The Engine Is Already Switched {E31919}Off!");
  409.                     TogglePlayerControllable(playerid, true);
  410.                     SendClientMessage(playerid,WHITE,"The Engine Is Now Switched {E31919}Off!");
  411.                     GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
  412.                     SetVehicleParamsEx(vehicleid,VEHICLE_PARAMS_OFF,lights,alarm,doors,bonnet,boot,objective);
  413.                     Engine[vehicleid] = false;
  414.                 }
  415.                 else if(Engine[vehicleid] == false)
  416.                 {
  417.                     new Float:health;
  418.                     GetVehicleHealth(vehicleid, health);
  419.                     if(health >350)
  420.                     {
  421.                         if(Engine[vehicleid]) return SendClientMessage(playerid,WHITE,"The Engine Is Already Switched {2F991A}On!");
  422.                         TogglePlayerControllable(playerid, true);
  423.                         SendClientMessage(playerid,WHITE,"The Engine Is Now Switched {2F991A}On!");
  424.                         GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
  425.                         SetVehicleParamsEx(vehicleid,VEHICLE_PARAMS_ON,lights,alarm,doors,bonnet,boot,objective);
  426.                         Engine[vehicleid] = true;
  427.                     }
  428.                     else
  429.                     {
  430.                         SendClientMessage(playerid, ORANGE, "Your Vehicles Moter Is Damaged, Engine Off!");
  431.                         Engine[vehicleid] = false;
  432.                         RemovePlayerFromVehicle(playerid);
  433.                     }
  434.                 }
  435.             }
  436.             case 5:
  437.             {
  438.                 GetVehiclePos(GetPlayerVehicleID(playerid),x,y,z);
  439.                 GetVehicleZAngle(GetPlayerVehicleID(playerid),ang);
  440.                 if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,ORANGE,"You must be in a vehicle!");
  441.                 ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"License Plate","Please type your plate info below:","Complete","Abort");
  442.             }
  443.             case 6:
  444.             {
  445.                 if(AlarmInfo[playerid] == 0)
  446.                 {
  447.                     GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
  448.                     SetVehicleParamsEx(vehicleid,engine,lights,VEHICLE_PARAMS_ON,doors,bonnet,boot,objective);
  449.                     AlarmInfo[playerid] = 1;
  450.                     SendClientMessage(playerid, WHITE, "Alarm {2F991A}on!");
  451.                 }
  452.                 else if(AlarmInfo[playerid] == 1)
  453.                 {
  454.                     GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
  455.                     SetVehicleParamsEx(vehicleid,engine,lights,VEHICLE_PARAMS_OFF,doors,bonnet,boot,objective);
  456.                     AlarmInfo[playerid] = 0;
  457.                     SendClientMessage(playerid, WHITE, "Alarm {E31919}off!");
  458.                  }
  459.             }
  460.             case 7:
  461.             {
  462.                 if(AlarmInfo[playerid] == 0)
  463.                 {
  464.                     GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
  465.                     SetVehicleParamsEx(vehicleid,engine,lights,VEHICLE_PARAMS_ON,doors,bonnet,boot,objective);
  466.                     AlarmInfo[playerid] = 1;
  467.                     SendClientMessage(playerid, WHITE, "Alarm {2F991A}on!");
  468.                 }
  469.                 else if(AlarmInfo[playerid] == 1)
  470.                 {
  471.                     GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
  472.                     SetVehicleParamsEx(vehicleid,engine,lights,VEHICLE_PARAMS_OFF,doors,bonnet,boot,objective);
  473.                     AlarmInfo[playerid] = 0;
  474.                     SendClientMessage(playerid, WHITE, "Alarm {E31919}off!");
  475.                 }
  476.             }
  477.         }
  478.     }
  479.     return 1;
  480. }
  481.     public OnGameModeExit()
  482.     {
  483.         return 1;
  484.     }
  485.     command(vehinfo,playerid,params[])
  486.     {
  487.         ShowPlayerDialog(playerid, 999, DIALOG_STYLE_LIST, "Camacorn's Ultimate Vehicle Control", "Headlights\nDoors - Lock/Unlock\nHood/Bonnet\nTrunk/Boot\nEngine\nLicense Plate\nAlarm", "Select", "Cancel");
  488.         return 1;
  489.     }
  490.     public OnPlayerSpawn(playerid)
  491.     {
  492.         SendClientMessage(playerid, ORANGE, "This server uses Camacorns 'Ultimate Vehicle Control' script.");
  493.         SendClientMessage(playerid, WHITE,"Ultimate Vehicle Control Commands: [/VEHINFO]");
  494.         return 1;
  495.     }
  496.  
  497.     public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  498.     {
  499.         new engine,lights,alarm,doors,bonnet,boot,objective,panels,tires;
  500.         new car = GetPlayerVehicleID(playerid);
  501.         if (Engine[vehicleid] == false)
  502.         {
  503.             GetVehicleParamsEx(car,engine,lights,alarm,doors,bonnet,boot,objective);
  504.             SetVehicleParamsEx(car,VEHICLE_PARAMS_OFF,lights,alarm,doors,bonnet,boot,objective);
  505.         }
  506.         else if (Engine[vehicleid] == true)
  507.         {
  508.             GetVehicleParamsEx(car,engine,lights,alarm,doors,bonnet,boot,objective);
  509.             SetVehicleParamsEx(car,VEHICLE_PARAMS_ON,lights,alarm,doors,bonnet,boot,objective);
  510.         }
  511.         if (LightPwr[vehicleid] == 0)
  512.         {
  513.             GetVehicleDamageStatus(vehicleid,panels,doors,lights,tires);
  514.             UpdateVehicleDamageStatus(vehicleid, panels, doors, 5, tires);
  515.         }
  516.         else
  517.         {
  518.             GetVehicleDamageStatus(vehicleid,panels,doors,lights,tires);
  519.             UpdateVehicleDamageStatus(vehicleid, panels, doors, 0, tires);
  520.         }
  521.         return 1;
  522.     }
  523.  
  524.     // Ultimate Vehicle Control by Camacorn
  525.     // Keep These Credits Please
Advertisement
Add Comment
Please, Sign In to add comment