[FilterScript] speedup.pwn - Increase vehicle maxspeed!
#1

This is a simple filterscript that increases the maxspeed of all vehicles. It doesn't noticeably affect acceleration, and steering works alright.

The FS:
pawn Код:
// speedup.pwn by Slice

#include <a_samp>

// The speed will be multiplied by this value
#define SPEED_MULTIPLIER 1.025

// The speed will only be increased if velocity is larger than this value
#define SPEED_THRESHOLD  0.4

new
          g_SpeedUpTimer = -1,
    Float:g_SpeedThreshold,
          PLAYER_SLOTS
;

new const
          KEY_VEHICLE_FORWARD  = 0b001000,
          KEY_VEHICLE_BACKWARD = 0b100000
;

public OnFilterScriptInit() {
    PLAYER_SLOTS = GetMaxPlayers();
   
    g_SpeedUpTimer = SetTimer("SpeedUp", 220, true);
   
    // Cache this value for speed
    // This can not be done during compilation because of a limitation with float values
    g_SpeedThreshold = SPEED_THRESHOLD * SPEED_THRESHOLD;
}

public OnFilterScriptExit() {
    KillTimer(g_SpeedUpTimer);
}

forward SpeedUp();
public SpeedUp() {
    new
        vehicleid,
        keys,
        Float:vx,
        Float:vy,
        Float:vz
    ;
   
    // Loop all players
    for (new playerid = 0; playerid < PLAYER_SLOTS; playerid++) {
        if (!IsPlayerConnected(playerid))
            continue;
       
        // Store the value from GetPlayerVehicleID and continue if it's not 0
        if ((vehicleid = GetPlayerVehicleID(playerid))) {
            // Get the player keys (vx is used here because we don't need updown/leftright)
            GetPlayerKeys(playerid, keys, _:vx, _:vx);
           
            // If KEY_VEHICLE_FORWARD is pressed, but not KEY_VEHICLE_BACKWARD or KEY_HANDBRAKE.
            if ((keys & (KEY_VEHICLE_FORWARD | KEY_VEHICLE_BACKWARD | KEY_HANDBRAKE)) == KEY_VEHICLE_FORWARD) {
                // Get the velocity
                GetVehicleVelocity(vehicleid, vx, vy, vz);
               
                // Don't do anything if the vehicle is going slowly
                if (vx * vx + vy * vy < g_SpeedThreshold)
                    continue;
               
                // Increase the X and Y velocity
                vx *= SPEED_MULTIPLIER;
                vy *= SPEED_MULTIPLIER;
               
                // Increase the Z velocity to make up for lost gravity, if needed.
                if (vz > 0.04 || vz < -0.04)
                    vz -= 0.020;
               
                // Now set it
                SetVehicleVelocity(vehicleid, vx, vy, vz);
            }
        }
    }
}
Reply
#2

Good but if you will explain it a little it will be helpful for the newbies.
Reply
#3

niceeee !!!!
Reply
#4

Thanks, going to test this out. Really needed something similiar to this for TM. Maybe ways to improve steering could be added in the future

Edit: works great!
Reply
#5

Nice. Today i had an idea about script like this.
Reply
#6

Looks nice.
Reply
#7

I was try to make a script, like this, but I was use 1.1 to boost the speed, and.. its so high amount.
with 1.025, its nice
Good script.
Reply
#8

Awesome, thanks!
Edit:
The variable g_SpeedThreshold defines the speed right? Does it work on the same way as your speedcap?
Reply
#9

g_SpeedThreshold is just (SPEED_THRESHOLD ^ 2), so you shouldn't modify that. The only things you should change are SPEED_MULTIPLIER and SPEED_THRESHOLD.

SPEED_MULTIPLIER is the one that changes how much faster vehicles will travel, and SPEED_THRESHOLD just defines when it should start increasing the speed.

For example, you could set SPEED_THRESHOLD to 1.0 and the speed would increase only when you've been going fast for a while.
Reply
#10

Ah okay, thank you
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)