OnFrankensteinPetSleep
OnFrankensteinPetSleep is called when a player uses a Frankenstein Table to put their active Frankenstein pet to sleep, right before the pet's stored items are returned and the pet is destroyed.
object OnFrankensteinPetSleep(FrankensteinPet frankensteinPet, FrankensteinTable frankensteinTable, BasePlayer owner)Parameters
| Parameter | Type | Description |
|---|---|---|
frankensteinPet | FrankensteinPet | The FrankensteinPet entity owned by the player who is putting it to sleep. It is already known to be non-null and within range of the table when the hook runs. |
frankensteinTable | FrankensteinTable | The FrankensteinTable instance whose SleepFrankenstein method triggered the hook. Use its transform.position to compare locations or check inventory state. |
owner | BasePlayer | The BasePlayer who interacted with the table to put the pet to sleep. This is the table owner, matched to the pet via the game's PetEntity check. |
Return value
Returning null (or nothing) lets the original code run: items are returned from the pet, removals are processed, a network update is sent, and the pet is killed. Returning any non-null value stops the original code path entirely, so the pet stays awake, keeps its inventory, and no update or kill occurs.
How it works
The hook fires inside FrankensteinTable.SleepFrankenstein. The game only reaches it after confirming the table inventory is empty, the owner is valid and authorized to build (when the table requires privilege), the owner has a live PetEntity, that entity is a FrankensteinPet, and the pet is within 5 meters of the table. Every one of those checks has already passed when your method runs.
The parameters give you the pet entity, the table being used and the owning player. The pet is useful for reading its health, held items or position; the table for its location and upgrade level; the owner for permissions, team checks or notifications.
Declaring owner as BasePlayer rather than a base type is fine because the game always passes a connected player here, though Oxide's dispatch will skip the call if the argument is ever something else. Returning a non-null value cancels the sleep action; returning null lets vanilla behavior continue. This is the natural place to require a permission before stashing a pet, to charge a fee, or to refuse sleep while the pet still carries valuable loot.
Example plugin: Require permission and a cooldown before sleeping a pet
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("Pet Sleep Guard", "RustPluginGenerator", "1.0.0")]
[Description("Requires a permission and a cooldown before a Frankenstein pet can be put to sleep")]
public class PetSleepGuard : RustPlugin
{
private const string PermUse = "petsleepguard.use";
private PluginConfig config;
private readonly Dictionary<ulong, DateTime> lastSleep = new Dictionary<ulong, DateTime>();
private class PluginConfig
{
[JsonProperty("Require permission")]
public bool RequirePermission = true;
[JsonProperty("Cooldown seconds between sleeps")]
public int CooldownSeconds = 120;
}
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 put your pet to sleep.",
["Cooldown"] = "You cannot sleep your pet for another {0} seconds."
}, 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(PermUse, this);
}
private object OnFrankensteinPetSleep(FrankensteinPet frankensteinPet, FrankensteinTable frankensteinTable, BasePlayer owner)
{
if (owner == null || frankensteinPet == null || frankensteinTable == null || owner.IsNpc)
return null;
if (config.RequirePermission && !permission.UserHasPermission(owner.UserIDString, PermUse))
{
owner.ChatMessage(Msg("NoPermission", owner.UserIDString));
return true;
}
if (config.CooldownSeconds > 0)
{
DateTime last;
if (lastSleep.TryGetValue(owner.userID, out last))
{
double remaining = config.CooldownSeconds - (DateTime.UtcNow - last).TotalSeconds;
if (remaining > 0)
{
owner.ChatMessage(Msg("Cooldown", owner.UserIDString, Math.Ceiling(remaining)));
return true;
}
}
lastSleep[owner.userID] = DateTime.UtcNow;
}
return null;
}
private void Unload()
{
lastSleep.Clear();
}
}
}The plugin listens on OnFrankensteinPetSleep and blocks the sleep action unless the owner has the petsleepguard.use permission. It also tracks a per-player cooldown in a dictionary keyed by user id, so players cannot rapidly stash and re-summon pets to dodge combat.
When the hook fires, it checks the permission first and sends a localized message if it is missing, then checks DateTime.UtcNow against the last sleep time stored for that player. If the cooldown is still active it replies with the remaining seconds and returns true to cancel. On success it records the timestamp and returns null so the game returns the items and destroys the pet as normal. The cooldown map is simple in-memory state; the example is focused on the hook, so it is not persisted to data files.
Common use cases
Gate pet sleeping behind a permission
Use
permission.UserHasPermissioninside the hook to restrict the table based on VIP status or a purchased unlock, telling the player why the action failed.Charge a fee to stash a pet
Call into an economy plugin from the hook, deduct a configurable amount from the owner, and return a non-null value if the balance is insufficient so the pet stays out.
Prevent sleeping while hostile players are nearby
Scan
BasePlayer.activePlayerListfor non-team members within a radius of the table and cancel the sleep so players cannot vanish pets mid-fight.
Pitfalls
Do not return false to block
The game only treats
nullas approval. Returningfalseis still a non-null value and will cancel the sleep just liketrue, but it is misleading; returntrueto block andnullto allow.The pet has already been validated
Distance, inventory and ownership checks happen before the hook runs, so you cannot use it to reject a pet that is 10 meters away; the game never calls the hook in that case.
Cooldowns are not persisted automatically
If you want cooldowns to survive restarts, store them with
Interface.Oxide.DataFileSystem; a plain dictionary resets on reload and on server restart.
Build a plugin with OnFrankensteinPetSleep
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 OnFrankensteinPetSleep
Generate