RustTip

OnCorpsePopulate

OxideCarbonNPC

Called when corpse populate occurs.

object OnCorpsePopulate(NPCPlayer nPCPlayer, NPCPlayerCorpse local1)
object OnCorpsePopulate(object Owner, LootableCorpse lootableCorpse)
object OnCorpsePopulate()
Works — the game method in this build is the one the hook was written for.

Parameters

nPCPlayer
NPCPlayer
local1
NPCPlayerCorpse

Return value

objectThe returned value replaces the game result; null lets the game decide.

Example

object — you can affect the game: return a value to change or cancel the action.

private object OnCorpsePopulate(NPCPlayer nPCPlayer, NPCPlayerCorpse local1)
{
    Puts("OnCorpsePopulate");

    // change nothing — the game continues as usual
    return null;

    // to affect the game:
    // return default(BaseCorpse); // your value instead of the game result
}

Works in both Oxide and Carbon: Carbon loads Oxide plugins as is.

Injection point 1

Rust.opj (Oxide)
BaseCorpse NPCPlayer.CreateCorpse(BasePlayer.PlayerFlags, Vector3, Quaternion, List<TriggerBase>, bool)

Passes: NPCPlayer nPCPlayer, NPCPlayerCorpse local1

WorksReturnBehavior: ExitWhenValidTypeArgumentBehavior: UseArgumentString (this, l1)Assembly-CSharp.dll

Where it is called (this branch's game code)

// …
		for (int i = 0; i < nPCPlayerCorpse.containers.Length; i++)
		{
			ItemContainer itemContainer = nPCPlayerCorpse.containers[i];
			if (!KeepCorpseClothingIntact || i != 1)
			{
				itemContainer.Clear();
			}
		}
		object returnvar = Interface.CallHook("OnCorpsePopulate", this, nPCPlayerCorpse);
		if (returnvar is BaseCorpse)
		{
			return (BaseCorpse)returnvar;
		}
		ApplyLoot(nPCPlayerCorpse);
	}
	return nPCPlayerCorpse;
}
// …

Injection point 2

Rust.opj (Oxide)
void Rust.Ai.Gen2.State_Dead.StartRagdoll()

Passes: object Owner, LootableCorpse lootableCorpse

WorksReturnBehavior: ExitWhenNonNullArgumentBehavior: UseArgumentString (this.Owner, l1)Assembly-CSharp.dll

Where it is called (this branch's game code)

// …
	castedUnityObject.playerName = prefabInformation.title.translated;
}
else
{
	castedUnityObject.playerName = Owner.GetType().Name;
}
castedUnityObject.Spawn();
baseCorpse.TakeChildren(Owner);
if (Interface.CallHook("OnCorpsePopulate", this.Owner, castedUnityObject) != null)
{
	return;
}
if (LootSpawnSlots.Length != 0)
{
	LootContainer.LootSpawnSlot[] lootSpawnSlots = LootSpawnSlots;
	for (int i = 0; i < lootSpawnSlots.Length; i++)
	{
// …

Injection point 3

Rust.opj (Oxide)
void Rust.Ai.Gen2.State_Dead.StartRagdoll()

Passes: —

WorksReturnBehavior: CustomAssembly-CSharp.dll

Where it is called (this branch's game code)

// …
else
{
	castedUnityObject.playerName = Owner.GetType().Name;
}
castedUnityObject.Spawn();
baseCorpse.TakeChildren(Owner);
if (LootSpawnSlots.Length != 0)
{
	object result = Interface.CallHook("OnCorpsePopulate");
	// … проверка результата (Modify-хук, см. Rust.opj)
	LootContainer.LootSpawnSlot[] lootSpawnSlots = LootSpawnSlots;
	for (int i = 0; i < lootSpawnSlots.Length; i++)
	{
		LootContainer.LootSpawnSlot lootSpawnSlot = lootSpawnSlots[i];
		for (int j = 0; j < lootSpawnSlot.numberToSpawn; j++)
		{
			if (Random.Range(0f, 1f) <= lootSpawnSlot.probability)
// …

Sources: Rust.opj from OxideMod/Oxide.Rust (MIT) and hook metadata of the Carbon documentation (MIT). Method code is decompiled from this branch's server.