CanCraft
OxideCraftingobject CanCraft(ItemCrafter itemCrafter, ItemBlueprint bp, int amount, bool free)
object CanCraft(PlayerBlueprints playerBlueprints, ItemDefinition itemDefinition, int skinItemId)Works — the game method in this build is the one the hook was written for.
Parameters
- itemCrafter
- ItemCrafter
- bp
- ItemBlueprint
- amount
- int
- free
- bool
Return value
objectReturn a value of the method's result type and the game returns it immediately; null continues as usual.
Example
object — you can affect the game: return a value to change or cancel the action.
private object CanCraft(ItemCrafter itemCrafter, ItemBlueprint bp, int amount, bool free)
{
Puts("CanCraft");
// change nothing — the game continues as usual
return null;
// to affect the game:
// return null; // null — the game continues as usual
}Works in both Oxide and Carbon: Carbon loads Oxide plugins as is.
Injection point 1
Rust.opj (Oxide)
bool ItemCrafter.CanCraft(ItemBlueprint, int, bool)
Passes: ItemCrafter itemCrafter, ItemBlueprint bp, int amount, bool free
WorksReturnBehavior: ExitWhenValidTypeArgumentBehavior: AllAssembly-CSharp.dll
Where it is called (this branch's game code)
// …
{
num += (float)item.amount / (float)item.blueprint.targetItem.craftingStackable;
}
}
if (num > 8f)
{
return false;
}
object returnvar = Interface.CallHook("CanCraft", this, bp, amount, free);
if (returnvar is bool)
{
return (bool)returnvar;
}
if (amount < 1 || amount > bp.targetItem.craftingStackable)
{
return false;
}
// …Injection point 2
Rust.opj (Oxide)
bool PlayerBlueprints.CanCraft(int, int, BasePlayer)
Passes: PlayerBlueprints playerBlueprints, ItemDefinition itemDefinition, int skinItemId
WorksReturnBehavior: ExitWhenValidTypeArgumentBehavior: UseArgumentString (this, l0, a1)Assembly-CSharp.dll
Where it is called (this branch's game code)
public bool CanCraft(int itemid, int skinItemId, BasePlayer player)
{
ItemDefinition itemDefinition = ItemManager.FindItemDefinition(itemid);
if (itemDefinition == null)
{
return false;
}
object returnvar = Interface.CallHook("CanCraft", this, itemDefinition, skinItemId);
if (returnvar is bool)
{
return (bool)returnvar;
}
if (skinItemId != 0 && !CheckSkinOwnership(skinItemId, player))
{
return false;
}
// …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.