Liberty Unleashed
Scripting => Script Snippets => Topic started by: Theremin on March 12, 2016, 07:44:55 pm
-
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() ); }
-
Very Awesome release Theremin!!
This could be very useful in so many ways!
I will quote a way that this code code be modified for.
Say there is no toggle, It is the limit in general, But If you obtain a wanted star you can unlock this feature and make your vehicle go at higher speeds, maybe as well as higher on wanted star ids.
I Really like this code as for me it puts a Mafia I (game) feel to it. Nice work and Kudos to the release.
-
Say there is no toggle, It is the limit in general, But If you obtain a wanted star you can unlock this feature and make your vehicle go at higher speeds, maybe as well as higher on wanted star ids.
Exactly! I kinda decided to do it basic, to leave the possible implementing ideas up to the scripters. For example I thought of allowing the police to check the speed limit of vehicles passing by and then issue a fine, or forcing a global speed limit depending on certain zones, like faster in the bridges/porter tunnel, slower in urban/residential areas (and many other ideas).
I Really like this code as for me it puts a Mafia I (game) feel to it.
You got me right?! ;) I got the idea from there, in fact I was to add a speed limit sign as a GUI, the problem is that I had hard time syncing it with the speed limiter, blame both my noobness and the wiki being down (some pages still aren't visible even with the Wayback Machine), so I eventually gave up and decided to post this without the sign.