OnNpcConversationStart
OnNpcConversationStart is called when a player begins talking to an NPC (NPCTalking.Server_BeginTalking) and before the player is registered as conversing with that NPC. Returning a non-null value cancels the conversation.
object OnNpcConversationStart(NPCTalking nPCTalking, BasePlayer player, ConversationData conversation)Parameters
| Parameter | Type | Description |
|---|---|---|
nPCTalking | NPCTalking | The NPC entity the player is interacting with (an NPCTalking instance, typically a scientist or vendor NPC). Use it to compare against a configured entity or to read its position. |
player | BasePlayer | The BasePlayer who is starting the conversation. Check IsAdmin, permissions, team, or building status to decide whether to block the conversation. |
conversation | ConversationData | The ConversationData describing the dialogue that is about to begin. Useful for identifying which NPC or conversation type is starting. |
Return value
Returning null (or having no hook) lets the conversation proceed normally. Returning any non-null value stops Server_BeginTalking immediately: the player is not added to the conversing list and SetActiveTalkingToNpc is never called, so the dialogue never opens. Since the method returns void, the actual return value is ignored beyond being non-null.
How it works
The hook fires inside NPCTalking.Server_BeginTalking, before the player is added to the NPC's conversing players list and before SetActiveTalkingToNpc is called. If the player was already in a conversation with this NPC, the game first ends the old conversation and then calls the hook for the new one. Because it fires on the server side of NPCTalking, it covers NPCs derived from that class - vendors and similar interactive NPCs - but not every entity type in the game.
nPCTalking identifies the NPC, so you can whitelist specific entities or read their position. player is the player opening the dialogue and is the natural place to check permissions, admin status or location. conversation describes the dialogue about to start; you can use it to distinguish NPC types or conversation groups.
Declaring nPCTalking as a more specific type only works if the runtime object actually is that type - otherwise Oxide skips the call. In practice keep the parameter as NPCTalking. This hook is one of the few in the NPCTalking family that can cancel a game action, so use it for access control rather than logging.
Example plugin: Restrict NPC conversations to permitted players
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
namespace Oxide.Plugins
{
[Info("Npc Conversation Guard", "RustPluginGenerator", "1.0.0")]
[Description("Restricts starting an NPC conversation to players with a permission")]
public class NpcConversationGuard : RustPlugin
{
private const string PermUse = "npcconversationguard.use";
private PluginConfig config;
public class PluginConfig
{
[JsonProperty("Notify blocked players")]
public bool NotifyBlocked { get; set; } = true;
[JsonProperty("Admins bypass permission")]
public bool AdminBypass { get; set; } = 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>
{
["NoPermission"] = "You do not have permission to talk to this NPC."
}, this);
}
private string Msg(string key, string userId = null) => lang.GetMessage(key, this, userId);
private void Init()
{
permission.RegisterPermission(PermUse, this);
}
private object OnNpcConversationStart(NPCTalking nPCTalking, BasePlayer player, ConversationData conversation)
{
if (nPCTalking == null || player == null) return null;
if (config.AdminBypass && player.IsAdmin) return null;
if (permission.UserHasPermission(player.UserIDString, PermUse)) return null;
if (config.NotifyBlocked && player.IsConnected)
{
player.ChatMessage(Msg("NoPermission", player.UserIDString));
}
// Any non-null return cancels Server_BeginTalking.
return false;
}
}
}The plugin registers a permission and blocks OnNpcConversationStart unless the player holds npcconversationguard.use or is an admin. A config flag lets each blocked player be notified through the language file. The hook compares the returning value: it returns a non-null object to cancel, which prevents SetActiveTalkingToNpc from running, so the player simply never enters the conversation UI. The permission default is granted to no one, so admins configure it with oxide.grant group default npcconversationguard.use or per-user grants. Everything runs server-side, no timers or UI are needed, and the plugin cleans up nothing because it holds no state.
Common use cases
Gate vendor NPCs behind a permission
Only players with a specific permission can open a given NPC's dialogue, so you can sell access to vendors or restrict them to a rank.
Block conversations during events
Cancel NPC dialogue while a custom event is running by tracking event state in your plugin and returning non-null from the hook.
Deny NPCs in restricted zones
Compare the NPC's transform position against a configured list of coordinates and cancel the conversation if it is inside a no-talk zone.
Pitfalls
Returning true cancels the conversation
A non-null return - even
trueorfalse- stopsServer_BeginTalking. Returnnullwhen you want the dialogue to proceed.Not every NPC uses NPCTalking
The hook only fires for entities whose server side is
NPCTalking. Other animals or custom NPCs that do not derive from it will never trigger it.Ending an existing conversation first
If the player was already talking to the same NPC, the game ends that conversation before the hook runs. Blocking here does not necessarily restore the previous state.
Build a plugin with OnNpcConversationStart
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 OnNpcConversationStart
Generate