RustTip

CanCreateWorldProjectile

OxideCarbonWeapon

Called to determine whether to create world projectile.

Return true to allow the action and false to block it.

object CanCreateWorldProjectile(HitInfo info, ItemDefinition itemDef)
Works — the game method in this build is the one the hook was written for.

Parameters

info
HitInfo
itemDef
ItemDefinition

Return value

objectReturn non-null to cancel the game action.

Example

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

private object CanCreateWorldProjectile(HitInfo info, ItemDefinition itemDef)
{
    Puts("CanCreateWorldProjectile");

    // 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)
void BasePlayer.CreateWorldProjectile(HitInfo, ItemDefinition, ItemModProjectile, Projectile, Item)

Passes: HitInfo info, ItemDefinition itemDef

WorksReturnBehavior: ExitWhenValidTypeArgumentBehavior: UseArgumentString (a0, a1)Assembly-CSharp.dll

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

protected virtual void CreateWorldProjectile(HitInfo info, ItemDefinition itemDef, ItemModProjectile itemMod, Projectile projectilePrefab, Item recycleItem)
{
	if (Interface.CallHook("CanCreateWorldProjectile", info, itemDef) != null)
	{
		return;
	}
	Vector3 projectileVelocity = info.ProjectileVelocity;
	Item item = ((recycleItem != null) ? recycleItem : ItemManager.Create(itemDef, 1, 0uL, isServerSide: true, 0uL));
	BaseEntity baseEntity = null;
	if (!info.DidHit)
	{
// …

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.