OnCowMilk
OxideCarbonAnimalobject OnCowMilk()
object OnCowMilk(Rust.Ai.Gen2.Cow cow, BasePlayer player, object l1)
object OnCowMilk(object arg0)Works — the game method in this build is the one the hook was written for.
Parameters
No parameters.
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 OnCowMilk()
{
Puts("OnCowMilk");
// change nothing — the game continues as usual
return null;
// to affect the game:
// return false; // 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)
bool Rust.Ai.Gen2.Cow.TryMilk(BasePlayer)
Passes: —
WorksReturnBehavior: CustomAssembly-CSharp.dll
Where it is called (this branch's game code)
// …
if (!TrustsToHandle(player))
{
OnGrabbedBy(player);
return false;
}
if (MilkDef != null)
{
int num = MilkedAmount();
object result = Interface.CallHook("OnCowMilk");
// … проверка результата (Modify-хук, см. Rust.opj)
player.GiveItem(ItemManager.Create(MilkDef, num, 0uL, isServerSide: true, 0uL));
if (MilkEffect != null && MilkEffect.isValid)
{
Effect.server.Run(MilkEffect.resourcePath, this, 0u, Vector3.zero, Vector3.zero);
}
Analytics.Azure.OnLivestockCowMilked(player, this, num);
}
// …Injection point 2
Rust.opj (Oxide)
bool Rust.Ai.Gen2.Cow.TryMilk(BasePlayer)
Passes: Rust.Ai.Gen2.Cow cow, BasePlayer player, object l1
WorksReturnBehavior: ExitWhenNonNullArgumentBehavior: UseArgumentString (this, a0, l1)Assembly-CSharp.dll
Where it is called (this branch's game code)
// …
if (!TrustsToHandle(player))
{
OnGrabbedBy(player);
return false;
}
if (MilkDef != null)
{
int num = MilkedAmount();
object returnvar = Interface.CallHook("OnCowMilk", this, player, local1);
if (returnvar != null)
{
return returnvar is bool && (bool)returnvar;
}
player.GiveItem(ItemManager.Create(MilkDef, num, 0uL, isServerSide: true, 0uL));
if (MilkEffect != null && MilkEffect.isValid)
{
Effect.server.Run(MilkEffect.resourcePath, this, 0u, Vector3.zero, Vector3.zero);
// …Injection point 3
Rust.opj (Oxide)
bool Rust.Ai.Gen2.Cow.TryMilk(BasePlayer)
Passes: object arg0
WorksReturnBehavior: ContinueAssembly-CSharp.dll
Where it is called (this branch's game code)
// …
return false;
}
if (MilkDef != null)
{
int num = MilkedAmount();
player.GiveItem(ItemManager.Create(MilkDef, num, 0uL, isServerSide: true, 0uL));
if (MilkEffect != null && MilkEffect.isValid)
{
Interface.CallHook("OnCowMilk", local1.Remove(0f));
Effect.server.Run(MilkEffect.resourcePath, this, 0u, Vector3.zero, Vector3.zero);
}
Analytics.Azure.OnLivestockCowMilked(player, this, num);
}
milkTimer.Start(MilkCooldown / GeneScale(LivestockGene.Yield));
return true;
}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.