Skip to content
RustPluginGenerator

OnElevatorMove

OnElevatorMove is called when an elevator's RequestMoveLiftTo runs, before the lift checks whether it is busy or starts travelling. Returning a non-null value cancels the move.

Signature
object OnElevatorMove(Elevator elevator, int targetFloor)

Parameters

Hook parameters
ParameterTypeDescription
elevatorElevatorThe Elevator entity whose RequestMoveLiftTo was called. Use it to read the cab position, net.ID, OwnerID or to check its state before deciding whether to allow the move.
targetFloorintThe floor index the lift was asked to travel to. Compare it with the elevator's current floor or use it to enforce a floor whitelist.

Return value

Return null (or nothing) to let the move proceed; the game then performs its own busy check and travel-time calculation. Return any non-null value, including false, to make RequestMoveLiftTo return false immediately, so the lift stays where it is and the request is dropped.

How it works

The hook fires inside Elevator.RequestMoveLiftTo(int targetFloor, out float timeToTravel, Elevator fromElevator), before the busy check and before any travel time is computed. It triggers whenever a caller requests a move: a player pressing a floor button, a player calling the lift from another floor, or a plugin invoking the controller. The parameters give you the Elevator instance being commanded and the requested targetFloor.

Declaring elevator as Elevator is required because the game passes the concrete type. You can read elevator.transform.position, net.ID.Value, OwnerID or ShortPrefabName to identify which lift is involved, and compare targetFloor against the current floor if you track it.

Because the hook runs on every request, keep bodies short: no Puts logging, no per-call config reloads. Cache expensive lookups in OnServerInitialized or Loaded. Use this to block certain floors, restrict lifts to authorised players, or stop lifts inside raid-time zones from moving.

Example plugin: Restrict elevators to a floor whitelist

ElevatorFloorGuard.cs
using System.Linq;
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
using UnityEngine;

namespace Oxide.Plugins
{
    [Info("Elevator Floor Guard", "RustPluginGenerator", "1.0.0")]
    [Description("Blocks elevator moves to floors that are not on the configured whitelist.")]
    public class ElevatorFloorGuard : RustPlugin
    {
        private const string PermBypass = "elevatorfloorguard.bypass";

        private PluginConfig config;
        private HashSet<int> allowedFloors = new HashSet<int>();

        private class PluginConfig
        {
            [JsonProperty("Allowed floor indices")]
            public List<int> AllowedFloors = new List<int> { 0, 1 };

            [JsonProperty("Notify player on blocked move")]
            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>
            {
                ["Blocked"] = "You cannot send this lift to floor {0}.",
                ["InvalidFloor"] = "That floor is not a valid target."
            }, 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 void OnServerInitialized()
        {
            allowedFloors.Clear();
            if (config.AllowedFloors == null) return;

            for (int i = 0; i < config.AllowedFloors.Count; i++)
            {
                int floor = config.AllowedFloors[i];
                if (floor < 0) continue;
                allowedFloors.Add(floor);
            }
        }

        private object OnElevatorMove(Elevator elevator, int targetFloor)
        {
            if (elevator == null) return null;

            if (targetFloor < 0)
            {
                if (config.Notify)
                {
                    BasePlayer owner = BasePlayer.FindByID(elevator.OwnerID);
                    if (owner != null && owner.IsConnected)
                        owner.ChatMessage(Msg("InvalidFloor", owner.UserIDString));
                }
                return false;
            }

            if (allowedFloors.Contains(targetFloor)) return null;

            if (config.Notify)
            {
                BasePlayer owner = BasePlayer.FindByID(elevator.OwnerID);
                if (owner != null && owner.IsConnected && !permission.UserHasPermission(owner.UserIDString, PermBypass))
                    owner.ChatMessage(Msg("Blocked", owner.UserIDString, targetFloor));
            }

            return false;
        }
    }
}

The plugin reads a list of allowed floor indices from its config and caches the parsed values in a HashSet<int> at load. OnElevatorMove checks whether the requested targetFloor is on the list; if it is not, the hook returns false, which makes the game's RequestMoveLiftTo return early without moving the lift. Owners in the configured bypass permission are exempt. Each blocked move sends the player a short chat line pulled from the language file, so admins can translate the text. The design keeps the hook body to a hash lookup so it stays cheap even on busy servers, and only null-checks the elevator parameter.

Common use cases

  • Floor whitelisting

    Allow only a set of permitted floor indices to be requested, blocking players from calling the lift to floors you want to keep off-limits.

  • Raid-time freeze

    Toggle a flag when raid windows are active and return a non-null value so lifts inside affected areas cannot move until the window ends.

  • Owner gating

    Compare elevator.OwnerID with the requesting player and block moves when the lift belongs to another group, using your own auth table or building privilege check.

Pitfalls

  • Returning false still returns non-null

    Any non-null return, including false, cancels the move. If you want the lift to keep moving, return null.

  • No player argument

    The hook never hands you the requesting player. If you need identity, check elevator.OwnerID or track the last caller through other hooks such as OnElevatorButtonPress.

  • Runs on every request

    Avoid heavy work such as config reloads, data-file writes or chat broadcasts inside the hook body; do them on a cooldown or in OnServerInitialized.

Build a plugin with OnElevatorMove

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

Prompt: Floor whitelisting using the OnElevatorMove 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 OnElevatorMove

Generate