I'm in the process of making a little plugin, but for it to work (somewhat) how it should, I would need a way for people to receive something else when hitting a tree. So as well as receiving wood there would be a chance of receiving 1 x item, how would I go about adding this to the plugin?
Let's say I wanted a 5-10% chance to receive 1 x Coal when hitting a tree, would that be possible?
Thanks!
Chance of giving item when hitting a tree?
Discussion in 'Rust Development' started by ThatGuy 8, Feb 17, 2018.
-
Code:
switch (item.info.shortname) { case "sulfur.ore": ReplaceContents(-891243783, ref item); break; case "hq.metal.ore": ReplaceContents(374890416, ref item); break; case "metal.ore": ReplaceContents(688032252, ref item); break; case "wolfmeat.raw": ReplaceContents(-1691991080, ref item); break; case "meat.boar": ReplaceContents(991728250, ref item); break; case "fish.raw": ReplaceContents(-2078972355, ref item); break; case "chicken.raw": ReplaceContents(1734319168, ref item); break; case "bearmeat": ReplaceContents(-2043730634, ref item); break; case "wood": ReplaceContents(1436001773, ref item); break; }
-
Take a look on my AdvanceGather.
-
Code:
using Random = System.Random; private Random Rng = new Random();void OnDispenserGather(ResourceDispenser dispenser, BaseEntity entity, Item item) { BasePlayer player = entity?.ToPlayer(); if (dispenser.ToString().Contains("forest") && IsEmpty(dispenser)) { int random = Rng.Next(0, 100); if (random <= chanceToSpawn) { Item treeReward = ItemManager.CreateByName("coal", 1); if (treeReward != null) { player.inventory.GiveItem(treeReward, player.inventory.containerMain); } } } }
-