OnTurretAssign
OnTurretAssign is called when a player tries to add a Steam ID to an AutoTurret's authorized list through the turret UI. Returning a non-null value cancels the authorization.
object OnTurretAssign(AutoTurret autoTurret, ulong userId, BasePlayer player)Parameters
| Parameter | Type | Description |
|---|---|---|
autoTurret | AutoTurret | The AutoTurret the player is trying to add to its authorized list. Null-check it even though the game normally passes a live turret. |
userId | ulong | The Steam ID being authorized, read from the client RPC payload. This is the ID that would be written into authorizedPlayers. |
player | BasePlayer | The BasePlayer who sent the authorization request. This is the player operating the turret, not necessarily the target of the authorization. |
Return value
Returning null lets the game add the ID to authorizedPlayers as normal. Returning any non-null object (for example false) stops the authorization: the ID is not added, capacity is not recalculated and no network update is sent. The value itself is not used; only whether it is null matters.
How it works
The hook fires inside AutoTurret.AssignToFriend, after the game has validated the turret is not at its auth capacity, the sender can interact, and the sender is allowed to change settings. The target ID is already known but not yet in authorizedPlayers. If the hook returns null, the game records the analytics event, appends the ID to the authorized list, recalculates auth capacity and sends a network update. Both player and msg.player are the same object at this point, so player is the operating player, not the player being added. autoTurret.authorizedPlayers gives you the current list if you want to check how many entries exist. Declaring the first parameter as AutoTurret already narrows the hook to turrets only; using a broader type such as BaseEntity would make Oxide call it for other entities too, which only matters if you register the same method elsewhere. Use this hook for group restrictions, per-turret allow lists, VIP limits or audit logging of who handed out authorization.
Example plugin: Restrict turret authorization to teammates
using System.Linq;
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("TurretTeamAuth", "RustPluginGenerator", "1.0.0")]
[Description("Restricts who can be authorized on auto turrets to members of the operator's team")]
public class TurretTeamAuth : RustPlugin
{
private const string PermUse = "turretteamauth.use";
private PluginConfig config;
private class PluginConfig
{
[JsonProperty("Only allow team members to be authorized")]
public bool TeamOnly { 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>
{
["NotTeamMember"] = "You can only authorize your own teammates on this turret."
}, this);
}
private string Msg(string key, string userId = null) => lang.GetMessage(key, this, userId);
private void Init()
{
permission.RegisterPermission(PermUse, this);
}
private object OnTurretAssign(AutoTurret autoTurret, ulong userId, BasePlayer player)
{
if (autoTurret == null || player == null) return null;
if (!config.TeamOnly) return null;
if (!permission.UserHasPermission(player.UserIDString, PermUse)) return null;
// Operators without a team may only authorize themselves.
if (player.currentTeam == 0)
{
if (userId == player.userID.Get()) return null;
player.ChatMessage(Msg("NotTeamMember", player.UserIDString));
return false;
}
var team = RelationshipManager.ServerInstance.FindTeam(player.currentTeam);
if (team == null || !team.members.Contains(userId))
{
player.ChatMessage(Msg("NotTeamMember", player.UserIDString));
return false;
}
return null;
}
}
}The plugin adds a config toggle and a turretteamauth.use permission. In OnTurretAssign it first checks that the plugin is enabled and the operating player has the permission; if not, it returns null so the default authorization applies. When enabled, it resolves the actor's team via RelationshipManager.ServerInstance.FindTeam and allows the assignment only if the target Steam ID is in that team's member list. Turret owners acting alone (no team) are also allowed to authorize themselves. On a blocked attempt the player receives a language message and the hook returns false, which prevents the ID from being written to authorizedPlayers. Config and language messages are loaded at startup, and the permission is registered in Init.
Common use cases
Team-only authorization
Stop players from adding outsiders to a base turret by comparing the target ID against the operator's team member list.
Owner-only handing out
Allow only the turret owner or a building privilege holder to authorize, useful when a turret was shared with a teammate who should not pass access on.
Authorization audit log
Write each accepted assignment with the operator's and target's Steam IDs to a data file so admins can trace who granted access to a base.
Pitfalls
player is the operator
playeris the person clicking in the turret UI. The Steam ID being added is theuserIdargument, which can be a different person entirely.Skipped checks mean no hook
The game only calls the hook after its own capacity and settings checks pass, so you cannot use it to observe failed attempts or blocked senders.
Do not call SendNetworkUpdate here
The game sends the update itself when authorization succeeds. Killing the turret or mutating its auth list from inside the hook can desync the client UI.
Build a plugin with OnTurretAssign
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 OnTurretAssign
Generate