Skip to content
RustPluginGenerator

OnTeamAcceptInvite

OnTeamAcceptInvite is called when a player accepts an outstanding team invite, right before the game adds them to the team. The invite only reaches this point if the team still exists.

Signature
object OnTeamAcceptInvite(RelationshipManager.PlayerTeam playerTeam, BasePlayer player)

Parameters

Hook parameters
ParameterTypeDescription
playerTeamRelationshipManager.PlayerTeamThe RelationshipManager.PlayerTeam the player is joining. Its members list and teamLeader reflect the state before the invite is accepted.
playerBasePlayerThe BasePlayer who accepted the pending invite and would become a team member.

Return value

Returning null lets the game continue and the player is added to the team. Returning any non-null value (e.g. true) stops the original accept path, so the player is not added; the pending invite is not cleared by this method when the hook blocks it.

How it works

The hook fires inside RelationshipManager.acceptinvite, after the server has resolved the pending invite target ID into a team. If no team is found the player's pending invite is simply cleared and the hook never runs, so playerTeam is always a live team object here.

Use playerTeam to inspect who is already on the team (members, teamLeader) and player to check the joining player's state — team size limits, whether they have a permission, their current team (currentTeam), or whether the team is approved. This is the last point where you can stop a join without rolling anything back.

Narrowing the parameter types is possible in principle (for example declaring the team parameter as RelationshipManager.PlayerTeam, which is already exact), but since both arguments always match their declared types, a subtype substitution offers no practical filtering here. Reject based on state, not on type.

Because the hook runs synchronously during the accept call, keep the body cheap: a few permission lookups and list counts are fine, heavy data writes are not.

Example plugin: Cap team size on invite accept

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

namespace Oxide.Plugins
{
    [Info("Team Size Cap", "RustPluginGenerator", "1.0.0")]
    [Description("Limits the number of members a team can have when an invite is accepted")]
    public class TeamSizeCap : RustPlugin
    {
        private PluginConfig config;

        private class PluginConfig
        {
            [JsonProperty("Maximum team members")]
            public int MaxTeamMembers { get; set; } = 4;

            [JsonProperty("Notify team leader on blocked join")]
            public bool NotifyLeader { 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>
            {
                ["JoinBlocked"] = "You cannot join this team: it already has {0} members.",
                ["LeaderNotice"] = "{0} was blocked from joining your team because it is full ({1} members)."
            }, this);
        }

        private string Msg(string key, string userId = null, params object[] args) =>
            string.Format(lang.GetMessage(key, this, userId), args);

        private object OnTeamAcceptInvite(RelationshipManager.PlayerTeam playerTeam, BasePlayer player)
        {
            if (playerTeam == null || player == null)
                return null;

            int max = Mathf.Max(1, config.MaxTeamMembers);
            if (playerTeam.members == null || playerTeam.members.Count < max)
                return null;

            if (player.IsConnected)
                player.ChatMessage(Msg("JoinBlocked", player.UserIDString, playerTeam.members.Count));

            if (config.NotifyLeader && playerTeam.teamLeader != 0UL)
            {
                BasePlayer leader = BasePlayer.FindByID(playerTeam.teamLeader);
                if (leader != null && leader.IsConnected)
                    leader.ChatMessage(Msg("LeaderNotice", leader.UserIDString, player.displayName, playerTeam.members.Count));
            }

            player.ClearPendingInvite();
            return true;
        }
    }
}

The plugin enforces a configurable maximum number of members per team at the moment an invite is accepted, which is the only point that cannot be bypassed by sending invites before the team was full. OnTeamAcceptInvite compares playerTeam.members.Count against MaxTeamMembers and, when the team is already at the limit, sends both the joining player and the team leader a localized chat message before returning true to block the join. Members count excludes the joining player, since the accept has not happened yet. Config holds the cap, and LoadDefaultMessages registers the messages so the text is editable through Oxide lang files.

Common use cases

  • Enforce a maximum team size

    Block the accept when the team is already full so invites sent earlier cannot push a team past your configured limit.

  • Restrict team joins by permission

    Check permission.UserHasPermission(player.UserIDString, ...) and reject the accept for players who have no right to join teams on a whitelisted server.

  • Notify the team leader of blocked joins

    When you reject an accept, message playerTeam.teamLeader so they know the invite failed and can adjust their roster.

Pitfalls

  • Returning non-null leaves the invite pending

    Blocking the accept by returning a value prevents the join but does not clear the player's invite through this method. If you want it gone, call player.ClearPendingInvite() in your hook before returning.

  • Members count excludes the joining player

    At hook time the player is not yet in playerTeam.members, so compare against members.Count and decide whether the new member counts toward your limit.

  • Fires only when the team still exists

    If the team was disbanded between the invite and the accept, the hook never runs. Do not rely on it to clean up state tied to dead invites.

Plugin recipes that use OnTeamAcceptInvite

Build a plugin with OnTeamAcceptInvite

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

Prompt: Enforce a maximum team size using the OnTeamAcceptInvite 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 OnTeamAcceptInvite

Generate