CanMountEntity
CanMountEntity is called in BaseMountable.MountPlayer before a player is seated, letting a plugin block the mount. Returning a non-null value cancels the mount.
object CanMountEntity(BasePlayer player, BaseMountable mountable)Parameters
| Parameter | Type | Description |
|---|---|---|
player | BasePlayer | The BasePlayer attempting to mount the seat or vehicle. Use this for permission checks, team checks, and cooldowns. |
mountable | BaseMountable | The BaseMountable entity being entered (vehicle seat, horse, minicopter, boat, etc.). Cast to specific types such as MiniCopter, ModularCar or BaseBoat when you need vehicle-specific logic. |
Return value
Returning null (or any null reference) lets the mount continue. Returning any non-null value stops MountPlayer before the player is seated: the player stays where they are and no dismount of the previous entity happens.
How it works
The hook fires inside BaseMountable.MountPlayer after the mountable has confirmed it is free (_mounted == null and an anchor exists) but before the player is dismounted from their current entity and assigned to _mounted. Every seating path that goes through MountPlayer will trigger it: entering a vehicle seat, mounting a horse, sitting on a chair, and similar. Because it fires on the server-side mount attempt, it runs before the player's position and parenting change.
player is the moving player; mountable is the target entity. The type check is useful here: if you declare mountable as BasePlayer instead of BaseMountable, the hook is never called, and declaring it as MiniCopter or ModularCar narrows it to those vehicles only, letting other mounts proceed untouched.
Blocking is cheap and reliable for restrictions like locked seats, driver-only rules, combat cooldowns or team ownership. Do not start long-running work here; keep the decision synchronous and return quickly.
Example plugin: Lock driver seats to vehicle owners
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("VehicleOwnerSeatLock", "RustPluginGenerator", "1.0.0")]
[Description("Prevents players from mounting a vehicle's driver seat when its owner is offline.")]
public class VehicleOwnerSeatLock : RustPlugin
{
private const string PermBypass = "vehicleownerseatlock.bypass";
private PluginConfig config;
private class PluginConfig
{
[JsonProperty("Block when owner is offline")]
public bool BlockWhenOffline = true;
[JsonProperty("Notify blocked player")]
public bool Notify = true;
}
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>
{
["OwnerOffline"] = "You cannot drive this vehicle while its owner is offline."
}, this);
}
private string Msg(string key, string userId = null) => string.Format(lang.GetMessage(key, this, userId));
private void Init()
{
permission.RegisterPermission(PermBypass, this);
}
private object CanMountEntity(BasePlayer player, BaseMountable mountable)
{
if (!config.BlockWhenOffline || player == null || mountable == null) return null;
if (mountable.OwnerID == 0UL) return null;
if (permission.UserHasPermission(player.UserIDString, PermBypass)) return null;
var owner = BasePlayer.FindAwakeOrSleeping(mountable.OwnerID.ToString());
if (owner != null && !owner.IsSleeping()) return null;
if (config.Notify)
player.ChatMessage(Msg("OwnerOffline", player.UserIDString));
return true;
}
}
}The plugin blocks anyone other than the vehicle owner from mounting a driver seat when the owner is offline. In CanMountEntity it checks the parameter is a BaseMountable with an OwnerID that has a real player, casts to BasePlayer, and compares it with the mounting player. If the owner is connected the mount is allowed; otherwise the player receives the localized message and the hook returns true, which cancels MountPlayer. A permission (vehicleownerseatlock.bypass) and a config toggle allow admins and server owners to tune or disable the behavior, and messages come from a language file so they can be translated.
Common use cases
Owner-only driver seats
Prevent strangers from driving a vehicle whose owner is offline while still letting passengers ride along.
Combat mount cooldown
Block mounting for a short window after the player takes damage or fires a weapon, using a stored timestamp map.
Team seat restrictions
Compare
player.currentTeamwith the vehicle owner's team to allow teammates but deny unrelated players.
Pitfalls
Over-specific parameter type
Declaring
mountableasMiniCoptermeans the hook is skipped for cars, boats and chairs; declareBaseMountableand cast inside when you want broad rules.Returning false
Any non-null value cancels the mount, including
false. Returnnullto allow it, never a boolean unless you intend to block.Network desync risk
MountPlayer runs on the server; if you block here the client usually re-syncs, but avoid blocking every mount in a loop of retries since players will keep pressing USE.
Plugin recipes that use CanMountEntity
Build a plugin with CanMountEntity
Describe what should happen and get a compiled plugin that uses this hook.
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 CanMountEntity
Generate