Hello people,
I am relatively new to creating mods and even to C#, started from scratch this year so excuse me if the things I ask are very common or easy to fix. I would never have ended here if I didn't search for a solution for hours (days in this case) already.
What I am trying to achieve is making weapon containers to accept other items (lowgrade fuel, tools) than weapon mods (silencers, scopes). I tried multiple ways, probably also some that don't even make sense. The method I have the most hope on is the following code:
Another approach was to use weapon mods and just style/rename them, but this would mean one type of item (i.e. a silencer acting as Low Grade Fuel) can only be added once. Is there a way to bypass this limit? I tried playing with the availableSlots, but without success:
This leaves untouched, the itemList. I think this is what I am (also) looking for, but I could not make this work either. What I tried is creating an item i wanted to add to the gun and then add it to the itemList:
(2) So, does anyone know if this is possible? And if so, how to realize this?
Another question about the same topic: I found out, the capacity field (item.contents.capacity) lets me change the amount of slots for a gun. This works perfect, however the interface still shows the 4 original slots. I don't expect this to be able to changed, but you never know.
(3) Is it possible to change the UI of a gun, so it shows more than 4 weapon mod slots?
(4) Since we're here anyway: Is it possible to add new slots to weapons and tools that don't have slots by default? For example a hammer or wooden spear.
I know there are other ways around to make above possible. An alternative would be creating a storage container on the fly when people 'open' the gun. Maybe fake the slots UI and manage everything with a DataFile, but I just like the fact that a gun is really 'carrying' an item, uses slots and maybe even can use the durability system.
Thanks to whoever took the time!
I am relatively new to creating mods and even to C#, started from scratch this year so excuse me if the things I ask are very common or easy to fix. I would never have ended here if I didn't search for a solution for hours (days in this case) already.
What I am trying to achieve is making weapon containers to accept other items (lowgrade fuel, tools) than weapon mods (silencers, scopes). I tried multiple ways, probably also some that don't even make sense. The method I have the most hope on is the following code:
ItemContainer.CanAcceptResult? CanAcceptItem(ItemContainer container, Item item, int targetPos)
{
// ... removed some checks to see if the item should be able to be placed on the weapon
BaseProjectile weapon = container.parent?.GetHeldEntity() as BaseProjectile;
if (weapon == null)
{
return null;
}
string itemID = item.info.GetInstanceID().ToString();
if (data.allowedItems.ContainsKey(itemID))
{
Puts("Accept item in gun");
return ItemContainer.CanAcceptResult.CanAccept;
}
return null;
}This actually works for normal storage containers and player's inventory, but not for the weapon slots. So it looks like the slots still don't accept the items. What i think is that this has something to do with the container type. So I tried some other things too, where item is the weapon to add the items to:item.contents.allowedContents = ItemContainer.ContentsType.Generic;(1) Am I right that the above code is only to set the container type to All items / Liquid?
item.contents.onlyAllowedItem = itemToAdd.info;Above way didn't work for me, but I think this is also not what I'm looking for right? I don't want to allow just one item, but at least 4 different types.
Another approach was to use weapon mods and just style/rename them, but this would mean one type of item (i.e. a silencer acting as Low Grade Fuel) can only be added once. Is there a way to bypass this limit? I tried playing with the availableSlots, but without success:
item.contents.availableSlots = ItemSlot.None;This leaves untouched, the itemList. I think this is what I am (also) looking for, but I could not make this work either. What I tried is creating an item i wanted to add to the gun and then add it to the itemList:
Item itemToAdd = ItemManager.CreateByName("lowgradefuel", 1);
item.contents.itemList.Add(itemToAdd);(2) So, does anyone know if this is possible? And if so, how to realize this?
Another question about the same topic: I found out, the capacity field (item.contents.capacity) lets me change the amount of slots for a gun. This works perfect, however the interface still shows the 4 original slots. I don't expect this to be able to changed, but you never know.
(3) Is it possible to change the UI of a gun, so it shows more than 4 weapon mod slots?
(4) Since we're here anyway: Is it possible to add new slots to weapons and tools that don't have slots by default? For example a hammer or wooden spear.
I know there are other ways around to make above possible. An alternative would be creating a storage container on the fly when people 'open' the gun. Maybe fake the slots UI and manage everything with a DataFile, but I just like the fact that a gun is really 'carrying' an item, uses slots and maybe even can use the durability system.
Thanks to whoever took the time!