Zum Hauptinhalt springen

πŸš— Anti Airtime

The FiveM Anti Airtime script is designed to prevent players from exploiting airtime with their vehicles. This script ensures a fair and realistic driving experience on your server by stopping vehicles from staying airborne.

Features​

  • Prevents Airtime Exploits: Automatically detects when a vehicle is airborne and brings it back to the ground safely.
  • Supports Various Vehicle Types: Works with bicycles, bikes, and cars.
  • Driver-Only Check: Only the driver is subject to the airtime restrictions, ensuring passengers are not affected.

How It Works​

The script continuously checks if the player's vehicle is in the air. If the vehicle is detected to be airborne, the following actions are taken:

  1. The vehicle's speed is set to 0 to halt any forward movement.
  2. The vehicle's position is adjusted to bring it back to the ground.
  3. A chat message is triggered, notifying the player that airtime is not allowed on the server.

Chat Message​

The following message is displayed in the chat when a player attempts to exploit airtime:

{
"color": [255, 0, 0],
"args": ["Hey! I don't know if you knew, but airtime is not allowed on this server!"]
}

This message can be easily customized to fit the server's needs.

Code Explanation​

View Antiairtime.cs
namespace AntiAirtime
{
public class AntiAirtime : BaseScript
{
public AntiAirtime()
{
EventHandlers["onClientResourceStart"] += new Action<string>(OnClientResourceStart);
}

private async void OnClientResourceStart(string obj)
{
if (obj != GetCurrentResourceName())
return;
while (true)
{
if (Game.PlayerPed.IsInVehicle())
{
if (Game.PlayerPed.CurrentVehicle.Model.IsBicycle || Game.PlayerPed.CurrentVehicle.Model.IsBike ||
Game.PlayerPed.CurrentVehicle.Model.IsCar)
{
if (Game.PlayerPed.SeatIndex == VehicleSeat.Driver)
{
if (Game.PlayerPed.CurrentVehicle.IsInAir)
{
Game.PlayerPed.CurrentVehicle.Speed = 0f;
Vector3 position = Game.PlayerPed.CurrentVehicle.Position;
position.Z = position.Z - Game.PlayerPed.CurrentVehicle.HeightAboveGround;
Game.PlayerPed.CurrentVehicle.Position = position;
TriggerEvent("chat:addMessage", new
{
color = new[] { 255, 0, 0 },
args = new[] { "Hey! I don't know if you knew, but airtime is not allowed on this server!" }
});
}
await Delay(7);
}
}
}
await Delay(5000);
}
}
}
}

This code sets up an event handler that starts checking for airtime when the client resource starts. If the player is in a vehicle and is the driver, and if the vehicle is airborne, it stops the vehicle and resets its position. A chat message is then sent to the player informing them that airtime is not allowed.

Customization​

Server administrators can customize the chat message to fit their server's theme or rules. Additionally, the delay intervals can be adjusted to change how frequently the script checks for airtime.

Installation​

To install the Anti Airtime script, follow these steps:

  1. Download the script and add it to your server's resources folder.
  2. Ensure the script is started in your server configuration file (server.cfg).

Conclusion​

The FiveM Anti Airtime script is an essential tool for server administrators who want to maintain a fair and realistic driving experience. By preventing vehicles from exploiting airtime, it helps keep gameplay balanced and enjoyable for all players.