Skip to content
RustPluginGenerator

OnVehicleModuleSelected

OnVehicleModuleSelected is called when a player selects an item inside a modular car garage's loot UI, after the game has processed the click. It fires from ModularCarGarage.RPC_SelectedLootItem and is informational only.

Signature
void OnVehicleModuleSelected(Item vehicleItem, ModularCarGarage modularCarGarage, BasePlayer player)

Parameters

Hook parameters
ParameterTypeDescription
vehicleItemItemThe Item representing the modular car whose garage UI is open. Useful for checking the car's owner, skin, or condition before reacting to the selection.
modularCarGarageModularCarGarageThe ModularCarGarage storage entity the player is interacting with. Use it to read its inventory or position when you need to tie the selection to a specific garage.
playerBasePlayerThe BasePlayer who clicked a module in the garage loot UI. Always null-check it before reading inventory or sending chat messages.

Return value

The hook is inserted with a plain call and the method returns void, so any value you return is ignored. There is no way to cancel or alter the selection from this hook.

How it works

This hook fires at the end of ModularCarGarage.RPC_SelectedLootItem, which runs when a player clicks an entry in the loot panel that belongs to a modular car garage. The game has already handled the selection (including sending an immediate inventory update to the player) before Oxide calls the hook, so it is a notification of what happened rather than a point to alter the outcome.

vehicleItem is the car item being edited, modularCarGarage is the garage entity the player is using, and player is the person doing the selecting. All three are passed straight through from the RPC, so check each for null before touching members like player.inventory or modularCarGarage.inventory.

Because the call happens after the game's own logic, you cannot block or cancel a selection here. Declaring a more specific parameter type such as ModularCarGarage (already the declared type) does not change dispatch; the hook simply receives whatever entity is involved. Use it to log module swaps, grant permissions based on what was selected, or trigger UI. Keep the body cheap since garage clicks can happen repeatedly.

Example plugin: Notify admins when a car module is selected

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

namespace Oxide.Plugins
{
    [Info("Vehicle Module Audit", "RustPluginGenerator", "1.0.0")]
    [Description("Notifies authorised admins when a player selects a module in a modular car garage.")]
    public class VehicleModuleAudit : RustPlugin
    {
        private const string PermAdmin = "vehiclemoduleaudit.admin";

        private PluginConfig config;

        private class PluginConfig
        {
            [JsonProperty("Send report to console")]
            public bool LogToConsole { 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>
            {
                ["Report"] = "{0} selected a module on {1} (garage {2})",
                ["Denied"] = "You do not have permission to review vehicle module edits."
            }, 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(PermAdmin, this);
        }

        private void OnVehicleModuleSelected(Item vehicleItem, ModularCarGarage modularCarGarage, BasePlayer player)
        {
            if (player == null || vehicleItem == null || modularCarGarage == null) return;

            if (!permission.UserHasPermission(player.UserIDString, PermAdmin)) return;

            string carName = vehicleItem.info != null ? vehicleItem.info.displayName.english : "unknown car";
            string message = Msg("Report", player.UserIDString, player.displayName, carName, modularCarGarage.net.ID.Value);
            player.ChatMessage(message);

            if (config.LogToConsole)
                Puts($"{player.displayName} ({player.UserIDString}) selected a module on {carName}");
        }
    }
}

The plugin listens for module selections and reports them to players holding the vehiclemoduleaudit.admin permission. On each call it null-checks the player and vehicle item, then checks the permission before doing anything else, so normal players cost almost nothing. Authorized admins receive a formatted chat message naming the player, the car item and the garage entity ID, using the language file for text. This is a lightweight audit trail that helps staff see who is editing which modular cars without spamming regular players or the server log.

Common use cases

  • Admin audit trail

    Record which players touch modular car garages so staff can investigate griefing or stolen cars. The hook already gives you the player, car item and garage.

  • VIP module editing gate

    Because the selection is already final, use the hook to detect when a non-permitted player edited a car and follow up with a warning or a separate restriction hook.

  • Custom UI feedback

    Show a CUI toast naming the currently selected module when a player clicks a garage entry, giving extra context the vanilla UI lacks.

Pitfalls

  • Fires after the fact

    The RPC already processed the click and sent the inventory update before Oxide runs this hook. You cannot reject the selection here; combine it with the earlier vehicle hooks if you need to block anything.

  • Null parameters

    The player can disconnect mid-interaction and the item or garage can be destroyed. Always null-check player and vehicleItem before reading inventory or sending chat.

  • Chat spam risk

    Frequent garage clicks will call this hook every time. Avoid Puts or PrintWarning in the body and gate any messages behind permissions or cooldowns.

Build a plugin with OnVehicleModuleSelected

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

Prompt: Admin audit trail using the OnVehicleModuleSelected 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 OnVehicleModuleSelected

Generate