OnResourceDepositCreated
OnResourceDepositCreated is called after the server builds a new underground resource deposit and registers it in the deposit manager. It fires once per generated patch during map setup or when a deposit is created from a position.
void OnResourceDepositCreated(ResourceDepositManager.ResourceDeposit resourceDeposit)Parameters
| Parameter | Type | Description |
|---|---|---|
resourceDeposit | ResourceDepositManager.ResourceDeposit | The ResourceDeposit object the server just finished building and added to the deposit list. Use its position and resources to inspect or rewrite what the patch contains. |
Return value
The hook's return value is ignored; whatever you return does not change the created deposit or the return of CreateFromPosition. To change a patch you must mutate the ResourceDeposit object itself.
How it works
Fires inside ResourceDepositManager.CreateFromPosition, immediately after the new patch is added to the manager's deposit list and right before the method restores the random state and returns it. This is the map-generation path that places the ore and hqm patches mined by survey charges and the mining quarry, so the hook runs for every patch generated, typically in bulk at server startup (and on OnNewSave map wipes). The single argument is the finished ResourceDeposit: it exposes the patch position, the resources it contains, and their amounts and radii, which you can read to build your own map of deposits or adjust before players ever survey them. Narrowing by parameter type is not useful here since the only argument is always the concrete ResourceDeposit type. Because the call happens during generation, avoid heavy work or chat/console output; store data and act on it later (for example after OnServerInitialized). Note that CreateFromPosition may be invoked for individual deposits too, not only as part of a full map build.
Example plugin: Audit and cap high-yield HQM deposits at map start
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
namespace Oxide.Plugins
{
[Info("Deposit Auditor", "RustPluginGenerator", "1.0.0")]
[Description("Audits generated resource deposits and optionally caps high-value patch amounts.")]
public class DepositAuditor : RustPlugin
{
private class PluginConfig
{
[JsonProperty("Cap hq.metal.ore per deposit")]
public bool CapHqm = true;
[JsonProperty("Maximum hq.metal.ore amount per resource entry")]
public float MaxHqmAmount = 8000f;
}
private PluginConfig config;
private readonly Dictionary<string, int> depositCounts = new Dictionary<string, int>();
private readonly Dictionary<string, float> amountTotals = new Dictionary<string, float>();
private int patchCount;
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);
private void OnResourceDepositCreated(ResourceDepositManager.ResourceDeposit resourceDeposit)
{
if (resourceDeposit == null) return;
patchCount++;
var entries = resourceDeposit._resources;
if (entries == null) return;
foreach (var resource in entries)
{
if (resource == null || resource.type == null) continue;
string shortname = resource.type.shortname;
if (string.IsNullOrEmpty(shortname)) continue;
if (shortname == "hq.metal.ore" && config.CapHqm && resource.amount > config.MaxHqmAmount)
{
resource.amount = (int)config.MaxHqmAmount;
}
if (!depositCounts.ContainsKey(shortname)) depositCounts[shortname] = 0;
depositCounts[shortname]++;
if (!amountTotals.ContainsKey(shortname)) amountTotals[shortname] = 0f;
amountTotals[shortname] += resource.amount;
}
}
private void OnServerInitialized()
{
if (patchCount == 0)
{
Puts("No resource deposits were generated yet; the audit will stay empty until the next wipe.");
return;
}
Puts($"Resource deposits generated: {patchCount}");
foreach (var entry in depositCounts)
{
amountTotals.TryGetValue(entry.Key, out float total);
Puts($" {entry.Key}: {entry.Value} entries, total amount {total:0}");
}
}
}
}The plugin listens for OnResourceDepositCreated and, for each generated deposit, iterates its resource entries. For each entry with a non-empty shortname it increments a running count and adds to a total amount keyed by shortname. When the shortname is hq.metal.ore and CapHqm is enabled, any entry whose amount exceeds MaxHqmAmount is reduced to that value. All data stays in memory. After server initialization (OnServerInitialized), if at least one deposit was seen it prints the deposit count followed by one line per resource with its entry count and total amount; otherwise it warns that no deposits were generated yet and the audit will remain empty until the next wipe. Configuration exposes CapHqm (bool) and MaxHqmAmount (float). Changing the deposit object during the hook is the only way to affect generation, since the hook's return value is ignored.
Common use cases
Map generation audit
Count deposits and total ore per type after every wipe to compare map seeds or spot patched resource settings.
Clamp oversized patches
Cap the amount of a high-value resource in each generated deposit to keep quarry yields balanced on your server.
Custom surface markers
Store each patch position and resource list to draw survey-style markers or hints for players later.
Pitfalls
Randomness is already fixed
The hook fires after the deposit contents are generated and the RNG state is restored, so you can only edit the object's existing values, not reroll the patch.
Fires in bulk at startup
Full map generation creates many deposits in a tight loop; avoid per-call logging, chat messages, or expensive lookups and defer reporting to OnServerInitialized.
Resource API varies
ResourceDeposit exposes its resources as a list with per-entry amount and radius; check the field names against your server build before relying on them in production code.
Build a plugin with OnResourceDepositCreated
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 OnResourceDepositCreated
Generate