Oxide.Rust icon indicating copy to clipboard operation
Oxide.Rust copied to clipboard

Added Hook "CanDropBackpack"

Open TurEduard opened this issue 1 year ago • 1 comments

The hook prevents the backpack from falling out in the Wounded, Crawling, or Dead states.

Upon death, it will still drop if the backpack is not empty, due to the CanAcceptItem check. By changing containerVolumeWhenFilled to zero for ItemModBackpack, you can allow the backpack to move through containers, even if it is not empty.

The hook is also needed to access the backpack when dying, as the backpack will fall out before the OnPlayerDeath hook is triggered.

TurEduard avatar Feb 04 '24 01:02 TurEduard

This is a quick crutch that will prevent a backpack from falling out of a corpse if it has resources. And after that it can only be stuffed into a backpack slot

private bool CanDropBackpack(Item backpack, PlayerInventory inventory) { ItemModBackpack component = backpack.info.GetComponent<ItemModBackpack>(); if (component != null) { component.containerVolumeWhenFilled = 0; NextTick(() => { component.containerVolumeWhenFilled = 1; }); } return false; }

TurEduard avatar Feb 04 '24 01:02 TurEduard

Merged with changes, thanks!

object OnBackpackDrop(Item backpack, PlayerInventory inventory)

MrBlue avatar Mar 05 '24 06:03 MrBlue