Hi,
I'm trying to create a weapon, like an ak-47, or a shotgun, but only with one or two bullet in the magazine.
I create the item via "ItemManager.CreateByName...".
I know that there is a BaseProjectile entity created for that item with a related Magazine that I could manipulate, but how can I retrieve the BaseProjectile from the newly created Item ?
Thanks for your help
[DOUBLEPOST=1435959566][/DOUBLEPOST]I've managed to do something that might work, but I'm not sure what would occur if a "rifle_ak" was crafted.
Here is what I've done so far:
In case AddRandomItemToContainer is called, an ak-47 with only 2 bullets is added to the container
[DOUBLEPOST=1435959720][/DOUBLEPOST]Obviously, the switch in the last "if" block is totaly useless. Just some testing code not really ended...Code:private void AddRandomItemToContainer(BasePlayer player, ItemContainer container) { // ... Removed code, to randomize the item to put in container string currentItemName = "rifle_ak"; // .... validateNewItemConfig = true; Item item = ItemManager.CreateByName(currentItemName); validateNewItemConfig = false; item.MoveToContainer(container); } bool validateNewItemConfig = false; void OnEntitySpawned(BaseNetworkable entity) { BaseProjectile projectile = entity.GetComponent<BaseProjectile>(); if (projectile == null) return; if(projectile.name == "weapons/rifle/ak47u.weapon" && validateNewItemConfig) { switch(projectile.name) { case "weapons/rifle/ak47u.weapon": projectile.primaryMagazine.contents = 2; break; } } }
Create a weapon with only one bullet
Discussion in 'Rust Development' started by Rouss, Jul 3, 2015.
