Author Topic: Basic speed limiter  (Read 1790 times)

Theremin

  • Full Member
  • ***
  • Posts: 154
  • Karma: +48/-18
  • Worst Server Owner
    • View Profile
    • Visit my YouTube channel
Basic speed limiter
« on: March 12, 2016, 08: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.

Code: (SERVER-SIDE) [Select]
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 ) );
}

Code: (SERVER-SIDE) [Select]
function onScriptLoad()
{
RegisterRemoteFunc ( "SpeedLimiter" );
}

And now the client script, I decided to bind it to the F1 key.

Code: (CLIENT-SIDE) [Select]
function onScriptLoad()
{
BindKey( KEY_F1, BINDTYPE_UP, "ToggleLimiter" );
}

Code: (CLIENT-SIDE) [Select]
function ToggleLimiter() { CallServerFunc( "SCRIPT_FOLDER/SCRIPT.nut", "SpeedLimiter", FindLocalPlayer() ); }
« Last Edit: March 12, 2016, 08:58:45 pm by Theremin »

Motley

  • Full Member
  • ***
  • Posts: 252
  • Karma: +32/-34
    • View Profile
Re: Basic speed limiter
« Reply #1 on: March 13, 2016, 09:06:16 am »
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.

Theremin

  • Full Member
  • ***
  • Posts: 154
  • Karma: +48/-18
  • Worst Server Owner
    • View Profile
    • Visit my YouTube channel
Re: Basic speed limiter
« Reply #2 on: March 13, 2016, 03:55:50 pm »
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.
« Last Edit: March 13, 2016, 03:57:39 pm by Theremin »

 

© Liberty Unleashed Team.