- 3
- 0
#define ABS_ENABLED 1
#define ABS_MIN_SPEED_ON_BRAKE 1.0
#define ABS_MAX_BRAKE_VELOCITY_DECREASE 0.1
public OnPlayerUpdate(playerid)
{
if (!IsPlayerInAnyVehicle(playerid)) return 1;
new vehicleid = GetPlayerVehicleID(playerid);
new keys, updown, leftright;
GetPlayerKeys(playerid, keys, updown, leftright);
if (keys & KEY_SPRINT || keys & KEY_FIRE)
{
new Float:current_velocity[3];
GetVehicleVelocity(vehicleid, current_velocity[0], current_velocity[1], current_velocity[2]);
new Float:speed = floatsqroot(current_velocity[0]*current_velocity[0] + current_velocity[1]*current_velocity[1] + current_velocity[2]*current_velocity[2]);
if (speed > ABS_MIN_SPEED_ON_BRAKE && ABS_ENABLED == 1)
{
new Float:new_speed_x = current_velocity[0] * (1.0 - ABS_MAX_BRAKE_VELOCITY_DECREASE);
new Float:new_speed_y = current_velocity[1] * (1.0 - ABS_MAX_BRAKE_VELOCITY_DECREASE);
new Float:new_speed_z = current_velocity[2] * (1.0 - ABS_MAX_BRAKE_VELOCITY_DECREASE);
if (floatsqroot(new_speed_x*new_speed_x + new_speed_y*new_speed_y + new_speed_z*new_speed_z) < ABS_MIN_SPEED_ON_BRAKE)
{
new Float:factor = ABS_MIN_SPEED_ON_BRAKE / speed;
new_speed_x = current_velocity[0] * factor;
new_speed_y = current_velocity[1] * factor;
new_speed_z = current_velocity[2] * factor;
}
SetVehicleVelocity(vehicleid, new_speed_x, new_speed_y, new_speed_z);
}
}
return 1;
}
#define ABS_MIN_SPEED_ON_BRAKE 1.0
#define ABS_MAX_BRAKE_VELOCITY_DECREASE 0.1
public OnPlayerUpdate(playerid)
{
if (!IsPlayerInAnyVehicle(playerid)) return 1;
new vehicleid = GetPlayerVehicleID(playerid);
new keys, updown, leftright;
GetPlayerKeys(playerid, keys, updown, leftright);
if (keys & KEY_SPRINT || keys & KEY_FIRE)
{
new Float:current_velocity[3];
GetVehicleVelocity(vehicleid, current_velocity[0], current_velocity[1], current_velocity[2]);
new Float:speed = floatsqroot(current_velocity[0]*current_velocity[0] + current_velocity[1]*current_velocity[1] + current_velocity[2]*current_velocity[2]);
if (speed > ABS_MIN_SPEED_ON_BRAKE && ABS_ENABLED == 1)
{
new Float:new_speed_x = current_velocity[0] * (1.0 - ABS_MAX_BRAKE_VELOCITY_DECREASE);
new Float:new_speed_y = current_velocity[1] * (1.0 - ABS_MAX_BRAKE_VELOCITY_DECREASE);
new Float:new_speed_z = current_velocity[2] * (1.0 - ABS_MAX_BRAKE_VELOCITY_DECREASE);
if (floatsqroot(new_speed_x*new_speed_x + new_speed_y*new_speed_y + new_speed_z*new_speed_z) < ABS_MIN_SPEED_ON_BRAKE)
{
new Float:factor = ABS_MIN_SPEED_ON_BRAKE / speed;
new_speed_x = current_velocity[0] * factor;
new_speed_y = current_velocity[1] * factor;
new_speed_z = current_velocity[2] * factor;
}
SetVehicleVelocity(vehicleid, new_speed_x, new_speed_y, new_speed_z);
}
}
return 1;
}