OnRandomItemAward
OxideCarbonResourceCalled when random item award occurs.
object OnRandomItemAward(RandomItemDispenser randomItemDispenser, RandomItemDispenser.RandomItemChance itemChance, BasePlayer forPlayer, Vector3 distributorPosition)Works — the game method in this build is the one the hook was written for.
Parameters
- randomItemDispenser
- RandomItemDispenser
- itemChance
- RandomItemDispenser.RandomItemChance
- forPlayer
- BasePlayer
- distributorPosition
- Vector3
Return value
objectReturn non-null to stop the game method.
Example
object — you can affect the game: return a value to change or cancel the action.
private object OnRandomItemAward(RandomItemDispenser randomItemDispenser, RandomItemDispenser.RandomItemChance itemChance, BasePlayer forPlayer, Vector3 distributorPosition)
{
Puts("OnRandomItemAward");
// change nothing — the game continues as usual
return null;
// to affect the game:
// return false; // non-null cancels the game action
}Works in both Oxide and Carbon: Carbon loads Oxide plugins as is.
Injection point
Rust.opj (Oxide)
bool RandomItemDispenser.TryAward(RandomItemDispenser.RandomItemChance, BasePlayer, Vector3)
Passes: RandomItemDispenser randomItemDispenser, RandomItemDispenser.RandomItemChance itemChance, BasePlayer forPlayer, Vector3 distributorPosition
WorksReturnBehavior: ExitWhenNonNullAssembly-CSharp.dll
Where it is called (this branch's game code)
private bool TryAward(RandomItemChance itemChance, BasePlayer forPlayer, Vector3 distributorPosition)
{
if (Interface.CallHook("OnRandomItemAward", this, itemChance, forPlayer, distributorPosition) != null)
{
return false;
}
float num = Random.Range(0f, 1f);
if (itemChance.Chance >= num)
{
Item item = ItemManager.Create(itemChance.Item, itemChance.Amount, 0uL, isServerSide: true, 0uL);
if (item != null)
// …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.