Advertisement
Guest User

Vehicle Speed Boost

a guest
Jul 26th, 2011
2,519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 8.37 KB | None | 0 0
  1. // -----------------------------------------------------------------------------
  2. // -----------------------------------------------------------------------------
  3. // Vehicle Speed Boost FilterScript for SAMP 0.3
  4. // 2nd September 2009
  5. // By Matite
  6. // Special thanks to kc!
  7. // v1.0.1
  8. // -----------------------------------------------------------------------------
  9. // -----------------------------------------------------------------------------
  10.  
  11. // -----------------------------------------------------------------------------
  12. // Includes...
  13. // -----------
  14.  
  15. // SAMP
  16. #include <a_samp>
  17.  
  18. // -----------------------------------------------------------------------------
  19. // Defines...
  20. // ----------
  21.  
  22. // Used for messages sent to the player
  23. #define COLOR_MESSAGE_YELLOW            0xFFDD00AA
  24.  
  25. // -----------------------------------------------------------------------------
  26. // Variables...
  27. // ------------
  28.  
  29. // Stores the players speed boost factor
  30. // (it is set to the default of 1.5 when the FS is loaded or when a player connects)
  31. new Float:SpeedBoostMultiplier[MAX_PLAYERS];
  32.  
  33. // -----------------------------------------------------------------------------
  34. // -----------------------------------------------------------------------------
  35. // -----------------------------------------------------------------------------
  36.  
  37. public OnFilterScriptInit()
  38. {
  39.     // Print to server console
  40.     print("\n-------------------------------------------------");
  41.     print(" Speed Boost Filterscript for SAMP 0.3 by Matite");
  42.     print("-------------------------------------------------\n");
  43.    
  44.     // Loop
  45.     for (new i = 0; i < MAX_PLAYERS; i++)
  46.     {
  47.         // Check if player is connected and not a NPC
  48.         if (IsPlayerConnected(i) && !IsPlayerNPC(i))
  49.         {
  50.             // Set the default speed boost for each player
  51.             SpeedBoostMultiplier[i] = 1.5;
  52.         }
  53.     }
  54.    
  55.     // Exit here
  56.     return 1;
  57. }
  58.  
  59. // -----------------------------------------------------------------------------
  60.  
  61. public OnFilterScriptExit()
  62. {
  63.     // Print to server console
  64.     print("\n------------------------------------------------");
  65.     print(" Unloaded Speed Boost Filterscript for SAMP 0.3");
  66.     print("------------------------------------------------\n");
  67.  
  68.     // Exit here
  69.     return 1;
  70. }
  71.  
  72. // -----------------------------------------------------------------------------
  73.  
  74. public OnPlayerCommandText(playerid, cmdtext[])
  75. {
  76.     // Create variables
  77.     new cmd[256];
  78.     new idx;
  79.    
  80.     // Get the command
  81.     cmd = strtok(cmdtext, idx);
  82.    
  83.     // Check command typed
  84.     if (strcmp(cmd, "/setspeedboost", true) == 0 || strcmp(cmd, "/ssb", true) == 0)
  85.     {
  86.         // Create string variables
  87.         new strBoostMultiplier[256];
  88.         new strTempString[256];
  89.  
  90.         // Get the vaue typed
  91.         strBoostMultiplier = strtok(cmdtext, idx);
  92.  
  93.         // Check a boost factor was supplied
  94.         if (!strlen(strBoostMultiplier))
  95.         {
  96.             // Send message and exit here
  97.             SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "** Usage: /setspeedboost <SpeedBoostMultiplier>");
  98.             SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "*  Allows you to set the speed boost multiplier that is applied when you press the horn key.");
  99.             SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "*  Accepted speed boost multiplier values are between 1.0 and 3.0");
  100.             SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "*  The shortcut for this command is: /ssb");
  101.             format(strTempString,sizeof(strTempString), "*  Your current speed boost multiplier is: %0.2f", SpeedBoostMultiplier[playerid]);
  102.             SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, strTempString);
  103.             return 1;
  104.         }
  105.  
  106.         // Check the boost factor supplied is numeric
  107.         if (!IsNumeric2(strBoostMultiplier))
  108.         {
  109.             // Send message and exit here
  110.             SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "** Usage: /setspeedboost <BoostMultiplier>");
  111.             SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "*  Allows you to set the speed boost multiplier that is applied when you press the horn key.");
  112.             SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "*  Accepted speed boost multiplier values are between 1.0 and 3.0");
  113.             SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "*  The shortcut for this command is: /ssb");
  114.             format(strTempString,sizeof(strTempString), "*  Your current speed boost multiplier is: %0.2f", SpeedBoostMultiplier[playerid]);
  115.             SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, strTempString);
  116.             return 1;
  117.         }
  118.  
  119.         // Convert to float
  120.         new Float:BoostMultiplier = floatstr(strBoostMultiplier);
  121.  
  122.         // Check speed boost multiplier is not too high or low
  123.         if (BoostMultiplier < 1.0 || BoostMultiplier > 3.0)
  124.         {
  125.             // Send message and exit here
  126.             SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "* Sorry, you must enter a speed boost multiplier between 1.0 and 3.0");
  127.             return 1;
  128.         }
  129.  
  130.         // Store the new speed boost multiplier value for the player
  131.         SpeedBoostMultiplier[playerid] = BoostMultiplier;
  132.  
  133.         // Format and send message
  134.         format(strTempString,sizeof(strTempString), "* You set your speed boost multiplier to %0.2f", SpeedBoostMultiplier[playerid]);
  135.         SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, strTempString);
  136.  
  137.         // Exit here
  138.         return 1;
  139.     }
  140.  
  141.     // Exit here and return 0 (the command was not processed here)
  142.     return 0;
  143. }
  144.  
  145. // -----------------------------------------------------------------------------
  146.  
  147. public OnPlayerConnect(playerid)
  148. {
  149.     // Set the default speed boost for the player
  150.     // (the previous player may of changed it)
  151.     SpeedBoostMultiplier[playerid] = 1.5;
  152.    
  153.     // Send message
  154.     SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "* Speed Boost v1.01 by Matite - type /ssb to set your speed boost factor.");
  155.            
  156.     // Exit here
  157.     return 1;
  158. }
  159.  
  160. // -----------------------------------------------------------------------------
  161.  
  162. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  163. {
  164.     // Check if the player is in any vehicle and is the driver
  165.     if (IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
  166.     {
  167.         // Check for the HORN key (Crouch key is the same as the horn key)
  168.         if (newkeys & KEY_CROUCH)
  169.         {
  170.             // Create variables
  171.             new Float:vx, Float:vy, Float:vz;
  172.            
  173.             // Get the vehicles velocity
  174.             GetVehicleVelocity(GetPlayerVehicleID(playerid), vx, vy, vz);
  175.            
  176.             // Check the values are not too high already
  177.             if (floatabs(vx) < 3 && floatabs(vy) < 3 && floatabs(vz) < 3)
  178.             {
  179.                 // Boost the vehicle speed
  180.                 SetVehicleVelocity(GetPlayerVehicleID(playerid), vx * SpeedBoostMultiplier[playerid], vy * SpeedBoostMultiplier[playerid], vz * SpeedBoostMultiplier[playerid]);
  181.             }
  182.            
  183.             // Exit here
  184.             return 1;
  185.         }
  186.     }
  187.  
  188.     // Exit here
  189.     return 1;
  190. }
  191.  
  192. // -----------------------------------------------------------------------------
  193. // -----------------------------------------------------------------------------
  194. // -----------------------------------------------------------------------------
  195.  
  196. stock strtok(const string[], &index)
  197. {
  198.     new length = strlen(string);
  199.     while ((index < length) && (string[index] <= ' '))
  200.     {
  201.         index++;
  202.     }
  203.  
  204.     new offset = index;
  205.     new result[20];
  206.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  207.     {
  208.         result[index - offset] = string[index];
  209.         index++;
  210.     }
  211.     result[index - offset] = EOS;
  212.     return result;
  213. }
  214.  
  215. // -----------------------------------------------------------------------------
  216.  
  217. IsNumeric2(const string[])
  218. {
  219.     // Is Numeric Check 2
  220.     // ------------------
  221.     // By DracoBlue... handles negative numbers
  222.  
  223.     new length=strlen(string);
  224.     if (length==0) return false;
  225.     for (new i = 0; i < length; i++)
  226.     {
  227.       if((string[i] > '9' || string[i] < '0' && string[i]!='-' && string[i]!='+' && string[i]!='.') // Not a number,'+' or '-' or '.'
  228.              || (string[i]=='-' && i!=0)                                             // A '-' but not first char.
  229.              || (string[i]=='+' && i!=0)                                             // A '+' but not first char.
  230.          ) return false;
  231.     }
  232.     if (length==1 && (string[0]=='-' || string[0]=='+' || string[0]=='.')) return false;
  233.     return true;
  234. }
  235.  
  236. // -----------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement