Guest User

RealCop228 / Slice's Speedcap FS - Include Version

a guest
Jun 15th, 2013
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.58 KB | None | 0 0
  1. /*
  2.     Vehicle speed cap filterscript.
  3.     -----------
  4.     This makes it possible to limit the maxspeed of vehicles; there are, however, a few things to consider.
  5.     * This will not work well on people with high pings.
  6.     * This works best with lower server rates.
  7.     * Driving at the speed limit will cause the handling to be different; however, if
  8.       used for roleplay, driving real-life like shouldn't be an issue with this at all!
  9.    
  10.     How do I get started with this?
  11.    
  12.     First off,
  13.     Try it on to see if it works. Load the filterscript, go ingame, and log in with /rcon login.
  14.     Now, use the testing command /myspeedcap to see if it works. An example of a value that feels like 50 km/h is 0.3.
  15.    
  16.     So, simply:
  17.         /myspeedcap 0.3
  18.    
  19.     Put the macros below in your other scripts and do this for example:
  20.         SetPlayerSpeedCap( playerid, 0.3 );
  21.    
  22.     Another example that disables speed cap only for the NRG:
  23.         public OnPlayerEnterVehicle( playerid, vehicleid, ispassenger )
  24.         {
  25.             new modelid = GetVehicleModel( vehicleid );
  26.            
  27.             if ( modelid == 522 ) // 522 - NRG-500
  28.                 SetPlayerSpeedCap( playerid, 0.4 );
  29.             else
  30.                 DisablePlayerSpeedCap( playerid );
  31.         }
  32.    
  33.     Put this in other scripts so they can change the speed cap easily.
  34.    
  35.     #define SetPlayerSpeedCap(%0,%1) CallRemoteFunction( "SetPlayerSpeedCap", "if", %0, %1 )
  36.     #define DisablePlayerSpeedCap(%0) CallRemoteFunction( "DisablePlayerSpeedCap", "i", %0 )
  37.    
  38.     Author: Slice
  39. */
  40.  
  41. #include <YSI\y_hooks>
  42.  
  43. forward SetPlayerSpeedCap( playerid, Float:value );
  44. forward DisablePlayerSpeedCap( playerid );
  45.  
  46. new
  47.     Float:g_fSpeedCap[ MAX_PLAYERS ] = { 0.0, ... }
  48. ;
  49.  
  50. hook OnPlayerUpdate( playerid )
  51. {
  52.     static
  53.         s_iVehicle
  54.     ;
  55.    
  56.     if ( g_fSpeedCap[ playerid ] != 0.0 && GetPlayerState( playerid ) == PLAYER_STATE_DRIVER )
  57.     {
  58.         s_iVehicle = GetPlayerVehicleID( playerid );
  59.        
  60.         if ( s_iVehicle )
  61.         {
  62.             static
  63.                 Float:s_fX,
  64.                 Float:s_fY,
  65.                 Float:s_fZ,
  66.                 Float:s_fVX,
  67.                 Float:s_fVY,
  68.                 Float:s_fVZ
  69.             ;
  70.            
  71.             GetVehiclePos( s_iVehicle, s_fX, s_fY, s_fZ );
  72.             GetVehicleVelocity( s_iVehicle, s_fVX, s_fVY, s_fVZ );
  73.            
  74.             if ( !IsPlayerInRangeOfPoint( playerid, g_fSpeedCap[ playerid ] + 0.05, s_fX + s_fVX, s_fY + s_fVY, s_fZ + s_fVZ ) )
  75.             {
  76.                 static
  77.                     Float:s_fLength
  78.                 ;
  79.                
  80.                 s_fLength = floatsqroot( ( s_fVX * s_fVX ) + ( s_fVY * s_fVY ) + ( s_fVZ * s_fVZ ) );
  81.                
  82.                 s_fVX = ( s_fVX / s_fLength ) * g_fSpeedCap[ playerid ];
  83.                 s_fVY = ( s_fVY / s_fLength ) * g_fSpeedCap[ playerid ];
  84.                 s_fVZ = ( s_fVZ / s_fLength ) * g_fSpeedCap[ playerid ];
  85.                
  86.                 if ( s_iVehicle )
  87.                     SetVehicleVelocity( s_iVehicle, s_fVX, s_fVY, s_fVZ );
  88.                 else
  89.                     SetPlayerVelocity( playerid, s_fVX, s_fVY, s_fVZ );
  90.             }
  91.         }
  92.     }
  93.    
  94.     return 1;
  95. }
  96.  
  97. hook OnPlayerCommandText( playerid, cmdtext[ ] )
  98. {
  99.     if ( !strcmp( "/myspeedcap", cmdtext, true, 11 ) )
  100.     {
  101.         new
  102.             szMessage[ 24 ]
  103.         ;
  104.        
  105.         if ( !( cmdtext[ 11 ] && cmdtext[ 12 ] ) )
  106.         {
  107.             SendClientMessage( playerid, -1, "USAGE: /myspeedcap [max speed]" );
  108.             SendClientMessage( playerid, -1, "USAGE: 0 will disable the speed cap." );
  109.            
  110.             return 1;
  111.         }
  112.        
  113.         g_fSpeedCap[ playerid ] = floatstr( cmdtext[ 12 ] );
  114.        
  115.         format( szMessage, sizeof( szMessage ), "* Speed cap: %0.4f", g_fSpeedCap[ playerid ] );
  116.        
  117.         SendClientMessage( playerid, 0xFFFF00FF, szMessage );
  118.        
  119.         return 1;
  120.     }
  121.    
  122.     return 0;
  123. }
  124.  
  125. public SetPlayerSpeedCap( playerid, Float:value )
  126. {
  127.     if ( 0 <= playerid < sizeof( g_fSpeedCap ) )
  128.         g_fSpeedCap[ playerid ] = value;
  129. }
  130.  
  131. public DisablePlayerSpeedCap( playerid )
  132. {
  133.     if ( 0 <= playerid < sizeof( g_fSpeedCap ) )
  134.         g_fSpeedCap[ playerid ] = 0.0;
  135. }
Advertisement
Add Comment
Please, Sign In to add comment