This is just a basic script for a speed limiter, I personally chose to set the limit to 72.4 km/h (~45 mph) which is the speed limit in Liberty City's real-life counterpart (or at least I think it was back in 2001). In my opinion it can be useful for roleplay servers. Feel free to suggest possible improvements or report bugs if there are any.
function SpeedLimiter( player )
{
local veh = player.Vehicle;
if ( veh )
{
if ( veh.Driver && veh.Driver.ID == player.ID )
{
if ( FindVehicle(veh.ID).GetHandlingData(9) != 72.4 )
{
FindVehicle(veh.ID).SetHandlingData( 9, 72.4 );
MessagePlayer( "Enabling speed limiter.", player, Colour( 255, 255, 255 ) );
}
else
{
local defaultspeed = GetVehicleHandlingData( veh.Model, 9 );
FindVehicle(veh.ID).SetHandlingData( 9, defaultspeed );
MessagePlayer( "Disabling speed limiter.", player, Colour( 255, 255, 255 ) );
}
}
else MessagePlayer( "You are a passenger, you must be the driver to toggle speed limiter.", player, Colour( 255, 255, 255 ) );
}
else MessagePlayer( "You must be driving a vehicle in order to toggle the speed limiter.", player, Colour( 255, 255, 255 ) );
}
function onScriptLoad()
{
RegisterRemoteFunc ( "SpeedLimiter" );
}
And now the client script, I decided to bind it to the F1 key.
function onScriptLoad()
{
BindKey( KEY_F1, BINDTYPE_UP, "ToggleLimiter" );
}
function ToggleLimiter() { CallServerFunc( "SCRIPT_FOLDER/SCRIPT.nut", "SpeedLimiter", FindLocalPlayer() ); }