Hi, im trying to spawn items inside a chest as soon as a player loots it.
I tried this, and can't see why it wont work.. Thanks!Code:void OnPlayerLoot(PlayerLoot inventory, BaseEntity target) { var definition = ItemManager.FindItemDefinition("stones"); StorageContainer box = inventory.GetComponent("StorageContainer") as StorageContainer; Item stenitem = ItemManager.CreateByItemID((int)definition.itemid, 500, false); stenitem.MoveToContainer(inventory.containers[0], 1, true); }
Spawn items inside chest?
Discussion in 'Rust Development' started by Hovmodet, Dec 21, 2015.
-
Here you go:
Code:void OnPlayerLoot(PlayerLoot inventory, BaseEntity target) { StorageContainer container = target.GetComponent<StorageContainer>(); Item item = ItemManager.CreateByName("stones", 500); item.MoveToContainer(container.inventory, 0, true); } -
Thanks sir.. Any idea how add a codelock to any chest deployed into the game?
-
This only works if you have at least one free slot:
It's by no means perfect, but it's a start.Code:void OnItemDeployed(Deployer deployer, BaseEntity entity) { StorageContainer container = deployer.GetDeployable()?.GetComponent<StorageContainer>(); if (container == null || !container.isLockable) return; Item item = ItemManager.CreateByName("lock.code", 1); item.MoveToContainer(deployer.ownerPlayer.inventory.containerMain); Deployer toDeploy = item.GetHeldEntity() as Deployer; toDeploy.DoDeploy_Slot(toDeploy.GetDeployable(), deployer.ownerPlayer.eyes.BodyRay(), entity.net.ID); } -
Thank you so much
