[FilterScript] Speed cap - Limit the vehicle maxspeed!
#27

As requested - a custom version that doesn't affect Z-speed.

Note: Untested!

pawn Код:
/*
    Vehicle speed cap filterscript.
    -----------
    This makes it possible to limit the maxspeed of vehicles; there are, however, a few things to consider.
    * This will not work well on people with high pings.
    * This works best with lower server rates.
    * Driving at the speed limit will cause the handling to be different; however, if
      used for roleplay, driving real-life like shouldn't be an issue with this at all!
   
    How do I get started with this?
   
    First off,
    Try it on to see if it works. Load the filterscript, go ingame, and log in with /rcon login.
    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.
   
    So, simply:
        /myspeedcap 0.3
   
    Put the macros below in your other scripts and do this for example:
        SetPlayerSpeedCap( playerid, 0.3 );
   
    Another example that disables speed cap only for the NRG:
        public OnPlayerEnterVehicle( playerid, vehicleid, ispassenger )
        {
            new modelid = GetVehicleModel( vehicleid );
           
            if ( modelid == 522 ) // 522 - NRG-500
                SetPlayerSpeedCap( playerid, 0.4 );
            else
                DisablePlayerSpeedCap( playerid );
        }
   
    Put this in other scripts so they can change the speed cap easily.
   
    #define SetPlayerSpeedCap(%0,%1) CallRemoteFunction( "SetPlayerSpeedCap", "if", %0, %1 )
    #define DisablePlayerSpeedCap(%0) CallRemoteFunction( "DisablePlayerSpeedCap", "i", %0 )
   
    Author: Slice
*/


#include <a_samp>

forward SetPlayerSpeedCap( playerid, Float:value );
forward DisablePlayerSpeedCap( playerid );

new
    Float:g_fSpeedCap[ MAX_PLAYERS ] = { 0.0, ... }
;

public OnPlayerUpdate( playerid )
{
    static
        s_iVehicle
    ;
   
    if ( g_fSpeedCap[ playerid ] != 0.0 && GetPlayerState( playerid ) == PLAYER_STATE_DRIVER )
    {
        s_iVehicle = GetPlayerVehicleID( playerid );
       
        if ( s_iVehicle )
        {
            static
                Float:s_fX,
                Float:s_fY,
                Float:s_fZ,
                Float:s_fVX,
                Float:s_fVY,
                Float:s_fVZ
            ;
           
            GetVehiclePos( s_iVehicle, s_fX, s_fY, s_fZ );
            GetVehicleVelocity( s_iVehicle, s_fVX, s_fVY, s_fVZ );
           
            if ( !IsPlayerInRangeOfPoint( playerid, g_fSpeedCap[ playerid ] + 0.05, s_fX + s_fVX, s_fY + s_fVY, s_fZ ) )
            {
                static
                    Float:s_fLength
                ;
               
                s_fLength = floatsqroot( ( s_fVX * s_fVX ) + ( s_fVY * s_fVY ) );
               
                s_fVX = ( s_fVX / s_fLength ) * g_fSpeedCap[ playerid ];
                s_fVY = ( s_fVY / s_fLength ) * g_fSpeedCap[ playerid ];
               
                SetVehicleVelocity( s_iVehicle, s_fVX, s_fVY, s_fVZ );
            }
        }
    }
   
    return 1;
}

public OnPlayerCommandText( playerid, cmdtext[ ] )
{
    if ( !IsPlayerAdmin( playerid ) )
        return 0;
   
    if ( !strcmp( "/myspeedcap", cmdtext, true, 11 ) )
    {
        new
            szMessage[ 24 ]
        ;
       
        if ( !( cmdtext[ 11 ] && cmdtext[ 12 ] ) )
        {
            SendClientMessage( playerid, -1, "USAGE: /myspeedcap [max speed]" );
            SendClientMessage( playerid, -1, "USAGE: 0 will disable the speed cap." );
           
            return 1;
        }
       
        g_fSpeedCap[ playerid ] = floatstr( cmdtext[ 12 ] );
       
        format( szMessage, sizeof( szMessage ), "* Speed cap: %0.4f", g_fSpeedCap[ playerid ] );
       
        SendClientMessage( playerid, 0xFFFF00FF, szMessage );
       
        return 1;
    }
   
    return 0;
}

public SetPlayerSpeedCap( playerid, Float:value )
{
    if ( 0 <= playerid < sizeof( g_fSpeedCap ) )
        g_fSpeedCap[ playerid ] = value;
}

public DisablePlayerSpeedCap( playerid )
{
    if ( 0 <= playerid < sizeof( g_fSpeedCap ) )
        g_fSpeedCap[ playerid ] = 0.0;
}
Reply


Messages In This Thread
Speed cap - Limit the vehicle maxspeed! - by Slice - 25.09.2010, 13:30
Re: Speed cap - Limit the vehicle maxspeed! - by Basicz - 25.09.2010, 13:33
Re: Speed cap - Limit the vehicle maxspeed! - by playbox12 - 25.09.2010, 14:52
Re: Speed cap - Limit the vehicle maxspeed! - by Hiddos - 27.09.2010, 06:40
Re: Speed cap - Limit the vehicle maxspeed! - by vyper - 27.09.2010, 11:47
Re: Speed cap - Limit the vehicle maxspeed! - by sander1312 - 27.09.2010, 19:15
Re: Speed cap - Limit the vehicle maxspeed! - by royal_king - 20.10.2010, 15:37
Re: Speed cap - Limit the vehicle maxspeed! - by ••• ĤБĶБM ••• - 20.10.2010, 17:01
Re: Speed cap - Limit the vehicle maxspeed! - by Slice - 21.10.2010, 20:33
Re: Speed cap - Limit the vehicle maxspeed! - by Las Venturas CNR - 22.10.2010, 12:43
Re: Speed cap - Limit the vehicle maxspeed! - by DeadAhead - 09.12.2010, 14:33
Re: Speed cap - Limit the vehicle maxspeed! - by Biesmen - 09.12.2010, 14:43
Re: Speed cap - Limit the vehicle maxspeed! - by Slice - 09.12.2010, 14:52
Re: Speed cap - Limit the vehicle maxspeed! - by WillyP - 09.12.2010, 16:38
Re: Speed cap - Limit the vehicle maxspeed! - by diehard5225 - 09.12.2010, 16:50
Re: Speed cap - Limit the vehicle maxspeed! - by WillyP - 09.12.2010, 16:50
Re: Speed cap - Limit the vehicle maxspeed! - by Slice - 09.12.2010, 17:37
Re: Speed cap - Limit the vehicle maxspeed! - by WillyP - 09.12.2010, 18:31
Re: Speed cap - Limit the vehicle maxspeed! - by wups - 09.12.2010, 18:37
Re: Speed cap - Limit the vehicle maxspeed! - by Osviux - 01.01.2011, 20:46
AW: Speed cap - Limit the vehicle maxspeed! - by Extremo - 01.01.2011, 21:48
Re: Speed cap - Limit the vehicle maxspeed! - by Slice - 01.01.2011, 22:02
Re: Speed cap - Limit the vehicle maxspeed! - by ricardo178 - 05.02.2011, 21:23
Re: Speed cap - Limit the vehicle maxspeed! - by Slice - 06.02.2011, 15:05
Re: Speed cap - Limit the vehicle maxspeed! - by XpLoDD - 06.02.2011, 18:25
AW: Speed cap - Limit the vehicle maxspeed! - by Meta - 06.02.2011, 20:15
Re: Speed cap - Limit the vehicle maxspeed! - by Slice - 19.06.2011, 11:39
Re: Speed cap - Limit the vehicle maxspeed! - by Germanator - 20.06.2011, 04:42
Re: Speed cap - Limit the vehicle maxspeed! - by budelis - 28.06.2011, 18:37
Re: Speed cap - Limit the vehicle maxspeed! - by Generation-X - 02.09.2011, 12:32
Re: Speed cap - Limit the vehicle maxspeed! - by playstores - 12.11.2018, 19:04

Forum Jump:


Users browsing this thread: 4 Guest(s)