create oxide rust plugin which ban player for invalid rotation in javascript

To create a plugin that bans a player for abnormal rotation, you can use the Oxide API and add a hook for the OnPlayerTick event to get the player's current rotation every frame.

Then, you can compare the player's current rotation to their previous rotation (which you can store in a dictionary or an array) and check if the change in rotation is too rapid or too large.

Here is an example implementation of this idea:

index.tsx
const { Data, Network } = Rust;

const MAX_ROTATION_CHANGE = 20; // Maximum allowed rotation change in degrees per frame.

var previousRotations = {}; // Dictionary to store previous rotations for each player.

function OnPlayerTick(player, deltaTime) {
    const steamId = player.userID;

    // Get the player's current rotation.
    const currentRotation = player.transform.rotation.eulerAngles;

    // Get the player's previous rotation (if it exists).
    const previousRotation = previousRotations[steamId];

    // If the player is moving, and we have a stored previous rotation, check if their rotation has changed too much.
    if (previousRotation && player.IsMoving()) {
        const rotationChange = Quaternion.Angle(Quaternion.Euler(previousRotation), Quaternion.Euler(currentRotation));

        if (rotationChange > MAX_ROTATION_CHANGE) {
            // Ban the player for excessive rotation change.
            player.Kick("Invalid Rotation Detected", Network.SendInfo());

            // Log the ban to server console.
            Rust.Server.Broadcast(`${player.displayName} was banned for invalid rotation.`);

            // Clear the player's previous rotation from our dictionary.
            delete previousRotations[steamId];

            // Save our dictionary of previous rotations to persistent data file.
            DataFileSystem.SaveData("invalid_rotation_plugin", previousRotations);
        }
    }

    // Store the player's current rotation as their previous rotation.
    previousRotations[steamId] = currentRotation;
}

// Add a hook for OnPlayerTick event to check player's rotation each frame.
plugin.OnPlayerTick = OnPlayerTick;

// Load previous rotation data from file (if it exists).
previousRotations = DataFileSystem.GetData("invalid_rotation_plugin") || {};
1806 chars
44 lines

This plugin will store each player's previous rotation every frame and ban them if their rotation changes too much. You can modify the MAX_ROTATION_CHANGE constant to adjust the maximum allowed rotation change.

Don't forget to add your plugin to your Rust server's oxide/plugins directory and add a reference to it in your oxide/config/plugins.json file.

gistlibby LogSnag