OnPlayerConnected
OnPlayerConnected is called once by Oxide itself after a client has fully connected and the server has set up its language, CUI snapshot and Covalence player record. It is the first player-scoped hook where the player object is safe to use.
void OnPlayerConnected(BasePlayer player)Parameters
| Parameter | Type | Description |
|---|---|---|
player | BasePlayer | The BasePlayer that has just finished connecting. It is a live, connected player object, so you can read net.connection, UserIDString, displayName and send UI or chat to it immediately. |
Return value
The return value is ignored. OnPlayerConnected returns void in the game/extension code and Oxide calls it purely for notification, so returning anything has no effect on the connection or on later code.
How it works
This hook is invoked from Oxide's RustCore.IOnPlayerConnected, which runs after the player's language is set from their Steam connection info, a CUI snapshot is sent to the client, and the Covalence player record is attached. It fires exactly once per connection and does not fire on respawn, disconnect or reconnect within the same session, so it is the natural place for per-session setup.
The only argument is the BasePlayer. Use it to read UserIDString, displayName, net.connection.ping or the language string, send a welcome message, open CUI, or apply saved state from your data files. Because Oxide has already configured language before this hook runs, lang.GetMessage with the player's ID returns the correct localized string.
There is no narrowing to do here: the parameter is already the concrete BasePlayer type, and Oxide only calls your method when the argument is an instance of it. Keep the handler fast — it runs on the main thread during the connect flow, and anything slow delays that player's load.
Do not confuse it with OnUserConnected, which fires earlier with the Covalence IPlayer wrapper.
Example plugin: Welcome returning players with a stored playtime greeting
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("Connection Welcome", "RustPluginGenerator", "1.0.0")]
[Description("Greets players when they connect and records their first-seen date.")]
public class ConnectionWelcome : RustPlugin
{
private const string PermExempt = "connectionwelcome.exempt";
private PluginConfig config;
private Dictionary<string, string> firstSeen;
private Timer saveTimer;
private class PluginConfig
{
[JsonProperty("Enable welcome message")]
public bool Enabled = true;
[JsonProperty("First visit message cooldown in seconds")]
public float FirstVisitCooldown = 30f;
}
private class StoredData
{
public Dictionary<string, string> FirstSeen = new Dictionary<string, string>();
}
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>
{
["Welcome"] = "Welcome back, {0}! Have fun on the server.",
["FirstVisit"] = "Welcome to the server, {0}! Type /help to see available commands."
}, 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(PermExempt, this);
LoadData();
saveTimer = timer.Every(300f, SaveData);
}
private void LoadData()
{
var data = Interface.Oxide.DataFileSystem.ReadObject<StoredData>(Name);
firstSeen = data?.FirstSeen ?? new Dictionary<string, string>();
}
private void SaveData()
{
Interface.Oxide.DataFileSystem.WriteObject(Name, new StoredData { FirstSeen = firstSeen });
}
private void OnPlayerConnected(BasePlayer player)
{
if (player == null || player.net == null || !config.Enabled) return;
string userId = player.UserIDString;
if (permission.UserHasPermission(userId, PermExempt)) return;
string displayName = player.displayName ?? "survivor";
if (firstSeen.ContainsKey(userId))
{
player.ChatMessage(Msg("Welcome", userId, displayName));
return;
}
firstSeen[userId] = DateTime.UtcNow.ToString("yyyy-MM-dd");
player.ChatMessage(Msg("FirstVisit", userId, displayName));
SaveData();
}
private void Unload()
{
saveTimer?.Destroy();
saveTimer = null;
SaveData();
}
}
}The plugin keeps a small data file mapping Steam IDs to first-seen timestamps and a stored welcome message flag. In OnPlayerConnected it looks up the player, builds a greeting from the language messages, and sends it with ChatMessage. If the ID is new it records the timestamp and sends the first-visit message instead. The config controls whether the greeting is enabled and the exemption permission lets staff suppress it. Data is written in Unload and on a periodic timer, and the timer reference is destroyed on unload so nothing leaks.
Common use cases
Welcome messages and rules broadcast
Send a localized welcome line, link to your rules, or a short server advertisement to the connecting player. Because the language is already set,
lang.GetMessagereturns the correct translation.Restore saved player state
Load a stored balance, rank, kit cooldown or last-known location from
oxide/dataand apply it to the player as soon as they connect, before they interact with the world.Open an info panel
Push a CUI panel with server info, vote links or a first-join tutorial. The player's CUI is ready to receive elements by the time this hook fires.
Pitfalls
Not the same as OnPlayerSpawn or OnPlayerSleepEnded
OnPlayerConnected fires once per session, not on respawn. If you need to run code every time a player wakes up or spawns, hook
OnPlayerSpawnorOnPlayerSleepEndedinstead.Player may still be loading
The player is connected but may not be fully spawned into the world. Reading
transform.positionor inventory is generally safe, but avoid teleporting or giving items here if you care about spawn logic — do that onOnPlayerSpawn.Keep it fast
This runs on the main thread during connect. Long loops, repeated file reads or a slow CUI build delay that player's join. Cache data at
OnServerInitializedand only apply it here.
Plugin recipes that use OnPlayerConnected
- How to make a Rust AFK kick plugin (idle timer with warning)Tracks each connected player's movement and look direction with a repeating timer and kicks anyone who stays idle past a configured limit after a chat warning. Exempt permission and a minimum player-count gate are built in.
- How to make a Rust announcement banner plugin (CUI top-screen messages)Adds an /announce chat command that draws a CUI banner at the top of every connected player's screen for a configurable duration, plus timed scheduled banners read from the config. Uses OnPlayerConnected and OnServerInitialized to re-show or start banners.
- How to make a Rust join and leave messages plugin (Oxide/Carbon)Broadcasts a configurable chat message when a player connects to the server and when a player disconnects, including the disconnect reason. Uses the OnPlayerConnected and OnPlayerDisconnected hooks and hides players with a permission from announcements.
- How to make a Rust last seen plugin (Oxide /seen command)Records a timestamp for every player on disconnect and answers /seen <name> with a relative time such as '2 hours ago' or 'online now'. Uses OnPlayerDisconnected, OnPlayerConnected and a data file in oxide/data.
- How to make a Rust map grid location plugin (chat /grid command)A /grid chat command that converts a player's world position into a Rust map grid cell (like G12) using the server's world size, with exact coordinates shown only to admins. It uses OnServerInitialized to cache the world size and OnPlayerConnected to announce the player's grid on join.
- How to make a Rust name filter plugin (kick on join)Blocks connections when a player's display name contains a blocked word, looks like advertising, or is shorter than a minimum length. Uses the OnPlayerConnected hook to kick the player with a configurable message.
- How to make a Rust playtime group promotion plugin (Oxide/Carbon)Tracks each player's connected playtime in oxide/data and moves them into stacked Oxide groups when they cross configured hour thresholds. Uses OnPlayerConnected and OnPlayerDisconnected to start and stop counting.
- How to make a Rust playtime rewards plugin (AFK-safe, Oxide)Pays players configured items every N minutes of active play, skips anyone who has not moved during the interval, and applies a permission-based multiplier for VIPs. Built on OnPlayerConnected, OnPlayerDisconnected and a repeating Oxide timer.
- How to make a Rust playtime tracker plugin (total and wipe time)Records session start time on connect and adds elapsed connected time on disconnect, persisted per player ID in oxide/data, with a /playtime command that reports hours and minutes. Uses OnPlayerConnected, OnPlayerDisconnected and OnNewSave.
- How to make a Rust scheduled restarts plugin (daily countdown warnings)Runs the configured server restart command at fixed daily times, broadcasts chat warnings at 15, 10, 5 and 1 minutes, and saves the server right before restarting. Uses timers plus the OnPlayerConnected and OnServerSave hooks.
- How to make a Rust server currency plugin (Oxide balances + /pay)A wallet plugin that stores per-player balances in a data file, exposes /balance, /pay and admin give/take console commands, saves on OnServerSave, and publishes GetBalance/Deposit/Withdraw for other plugins.
- How to make a Rust server HUD plugin (CUI)Builds a small persistent CUI panel with the server name, online player count and in-game clock, updated from an Oxide timer for every connected player. Visibility is saved per Steam ID with OnPlayerConnected and OnPlayerDisconnected plus the /hud toggle.
- How to make a Rust server info panel plugin (CUI tabs)Builds a tabbed CUI window opened with /info that shows rules, commands and wipe information sourced from the config, with an optional one-time auto-open when a player first connects. Uses OnPlayerConnected plus a chat command and console commands for tab switching.
- How to make a Rust welcome messages plugin (first-join aware)Sends a configurable multi-line private welcome message when a player fully wakes up, with a separate message for players who have never joined the server before. Uses OnPlayerConnected to mark new players and OnPlayerSleepEnded to deliver the text.
Build a plugin with OnPlayerConnected
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 OnPlayerConnected
Generate