Skip to content
RustPluginGenerator

OnPlayerWantsMount

OnPlayerWantsMount is called when a player attempts to mount a BaseMountable, before the game runs its own seat checks. Returning any non-null value cancels the mount attempt.

Signature
object OnPlayerWantsMount(BasePlayer player, BaseMountable mountable)

Parameters

Hook parameters
ParameterTypeDescription
playerBasePlayerThe BasePlayer who is trying to seat themselves on the mountable. Already validated as connected, valid and able to interact when the hook fires.
mountableBaseMountableThe BaseMountable (chair, car seat, boat seat, saddle, minicopter seat, etc.) the player wants to mount.

Return value

Return null to let the game continue with its normal mount logic. Return anything non-null to stop WantsMount immediately, so the player never mounts the entity and receives no further seat validation or effects.

How it works

The hook fires inside BaseMountable.WantsMount, which the game calls when a player tries to sit on a mountable entity: pressing use on a chair, horse, boat seat or vehicle seat, or when a vehicle seat is chosen by the game. By the time your hook runs the game has already confirmed the player is valid, connected and able to interact, so you do not need to repeat those checks.

The player argument is the would-be rider and mountable is the seat or saddle being targeted. Use mountable.ShortPrefabName, its parent entity, mountable.OwnerID or its position to decide whether this particular player should be allowed to sit. Because the hook runs before DirectlyMountable() and per-seat checks, it is the earliest common entry point for every mount action, not only manual use presses.

The hook also fires for NPC and AI-driven mounts if a BasePlayer is passed, but parameters arrive as BasePlayer and BaseMountable only; there is no narrower type to declare that would change dispatch, so declare the types exactly as shown.

Example plugin: Block mounting of other players' vehicles unless permitted

MountGuard.cs
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;

namespace Oxide.Plugins
{
    [Info("Mount Guard", "RustPluginGenerator", "1.0.0")]
    [Description("Restricts mounting of vehicles to owners, authorised players and permission holders")]
    public class MountGuard : RustPlugin
    {
        private const string PermBypass = "mountguard.bypass";

        private PluginConfig config;

        private class PluginConfig
        {
            [JsonProperty("Protect cars and boats only")]
            public bool VehiclesOnly { get; set; } = true;

            [JsonProperty("Block when owner is offline")]
            public bool RequireOwnerOnline { get; set; } = false;
        }

        protected override void LoadDefaultConfig() => config = new PluginConfig();

        protected override void LoadConfig()
        {
            base.LoadConfig();
            try
            {
                config = Config.ReadObject<PluginConfig>();
                if (config == null) throw new Exception();
            }
            catch
            {
                PrintWarning("Configuration file is invalid, using defaults");
                LoadDefaultConfig();
            }
            SaveConfig();
        }

        protected override void SaveConfig() => Config.WriteObject(config);

        protected override void LoadDefaultMessages()
        {
            lang.RegisterMessages(new Dictionary<string, string>
            {
                ["NotOwner"] = "This vehicle does not belong to you.",
                ["OwnerOffline"] = "The owner must be online to use this vehicle."
            }, this);
        }

        private string Msg(string key, string userId = null, params object[] args) =>
            string.Format(lang.GetMessage(key, this, userId), args);

        private void Init()
        {
            permission.RegisterPermission(PermBypass, this);
        }

        private object OnPlayerWantsMount(BasePlayer player, BaseMountable mountable)
        {
            if (player == null || mountable == null) return null;
            if (player.IsAdmin) return null;

            var vehicle = mountable.GetParentEntity() ?? mountable;
            if (vehicle == null || vehicle.OwnerID == 0) return null;

            if (config.VehiclesOnly && !(vehicle is ModularCar) && !(vehicle is BaseBoat) && !(vehicle is BaseHelicopter))
                return null;

            ulong ownerId = vehicle.OwnerID;
            if (player.userID.Get() == ownerId) return null;
            if (permission.UserHasPermission(player.UserIDString, PermBypass)) return null;

            if (vehicle is BuildingPrivlidge == false)
            {
                var auth = vehicle.GetBuildingPrivilege();
                if (auth != null && auth.IsAuthed(player)) return null;
            }

            if (config.RequireOwnerOnline && !IsOwnerOnline(ownerId))
            {
                player.ChatMessage(Msg("OwnerOffline", player.UserIDString));
                return true;
            }

            player.ChatMessage(Msg("NotOwner", player.UserIDString));
            return true;
        }

        private bool IsOwnerOnline(ulong ownerId)
        {
            var player = BasePlayer.FindByID(ownerId);
            return player != null && player.IsConnected;
        }
    }
}

The plugin restricts who can mount vehicles based on ownership, authorisation and a bypass permission. In OnPlayerWantsMount it resolves the mountable's parent entity so a seat on a car or boat is checked against the vehicle owner, ignoring the seat itself. The check is skipped when the player is an admin, the vehicle has no owner (OwnerID == 0), or the Protect cars and boats only config is enabled and the entity is not a ModularCar, BaseBoat or BaseHelicopter. Players with the mountguard.bypass permission or whose user ID matches the owner ID are allowed through by returning null, as is an authorised player on a vehicle that is not a BuildingPrivlidge and has a building privilege they are authorised on. With Block when owner is offline enabled, an offline owner sends the OwnerOffline message; everyone else who fails the checks gets the NotOwner message and a non-null return, which cancels the mount.

Common use cases

  • Spawn protection on vehicles

    Deny mounting owned cars, boats and helicopters while the owner is offline or within a protection window, returning a non-null value to block the attempt.

  • Team-only saddles

    Require that the rider be on the same team as the mountable's OwnerID, preventing strangers from stealing horses on roleplay servers.

  • Event seating

    Only permit mounting event vehicles during an active round by checking a flag in plugin data before returning null.

Pitfalls

  • OwnerID is often zero

    Chairs placed by players and NPC-driven mounts can have OwnerID == 0, so always treat zero as unowned and let the mount continue.

  • Seats belong to a parent

    Seats on modular cars, boats and minicopters are child entities; read the parent through GetParentEntity() before comparing ownership.

  • Anything non-null blocks

    Even returning false or 0 cancels the mount because Oxide only checks for null. Return null to allow.

Build a plugin with OnPlayerWantsMount

Describe what should happen and get a compiled plugin that uses this hook.

Prompt: Spawn protection on vehicles using the OnPlayerWantsMount hook, with a config file and a permission
Generate this plugin

Edit the prompt on the next screen. 2 free plugins a month, no card.

Last updated Oct 26, 2026. Found a mistake? Email support@rustplugingenerator.com.

Build a plugin with OnPlayerWantsMount

Generate