Custom Item Restriction for Two Handed Weapons

AlexM

New member
Hi! The script you made for the UCC integration that helps weapon equips go to the correct character slots is working perfectly.

My problem now is that I want to have Two Handed weapons (Longswords, Bows, etc.) to be mutually exclusive with One Handed weapons. Each type of weapon inherits a specific category (WeaponBoth for Two Hand, WeaponEither for One Hand). I decided to try making my own custom Item Restriction, making it so that when the player has one weapon type equipped, equipping the other weapon type will replace it. Currently, it just equips both types at once.

Unfortunately, I'm not a good programmer. I'm a bit confused on what to actually do here. I was using the ItemRestrictionSetObject script for reference, but it honestly left me feeling more overwhelmed. I was wondering if you could help break down the structure of the script, so I could understand it a little better. Or if you had an idea of how to solve this problem without writing code. I usually use Playmaker for scripting because it's easier for me to understand, and I have tried using it for this. It seems too limited to solve this problem, though.

Any help would be very appreciated. I really need to get better at C# ?
 
This page explains how to make custom ItemRestrictions. All you need is a class that inherits the IItemRestirction interface:

If you do the class will appear as an option within the itemRestrictionSetObject inspector. Check the ItemCollectionStackSizeRestriction or ItemCollectionCategoryRestriction for reference.

Trying to restrict the inventory without writing code or using play maker isn't really possible unless the solution already exists built-in the system.

Note that restriction are meant to prevent you from adding or removing items. They should NOT be used to replace items.
If you want to Equip the Bow, and replace the Sword then you should take another approach.

You can either create a custom Equip ItemAction if that's the only way you can equip items, that should be all you need.
If you can equip items in multiple ways (Item Action, Drop Action, directly in code), then another approach can be to create a custom ItemCollection.

Making a custom Equip Item Action would be the easiest option for you in my opinion. you can learn how to make ItemActions here:

You can inspire yourslef from the existing Equip Item Action which is called "MoveToCollectionItemAction".
I hope that helps.
 
Ok, so I did decide to make a custom item action instead of a restriction. I felt a lot more comfortable with it, actually, and I figured out how to replace a left hand item if a two hand item was equipped. I copied MoveToCollectionItemAction and made some edits. I found out, though, that it works strangely with the UCC integration.

My idea was to have two separate equip actions that only worked for equipping, not unequipping:
One would be for the right hand, which would check if the item being equipped was two handed. Then if it was, it would check for an item in the left hand, remove it, and equip to right.
The other action would be for the left hand, checking if there was an item in the right and if it was two handed. If the right hand item was two handed, it would remove it and equip to left.
Two handed items will only be able to be equipped in the right hand.

In the UI, they would be labelled separately ("Equip to Right" and "Equip to Left"), with only the right hand option showing for two handed items. The Equipment Screen would use the integration's CharacterEquipUnequipAction for the "Unequip" button, as I don't need to check for anything when just unequipping. I was going to remove drag/drop equipping in the future, because it would just complicate things further for me.

So I customized my own action based on MoveToCollectionItemAction, starting with the right hand equip first. It worked perfectly on the inventory side, replacing the item in the left hand back to the main inventory.
On the character side, it would equip the two hand, but still keep the left hand item in Character Slot 1. It did remove it from the Inventory Bridge, though. It also didn't work very well with replacing within the right hand only. Sometimes it would keep both inside the the Bridge, despite one of them being replaced in the inventory. Other times it would replace the old one completely, but the new item wouldn't show up in game when using my toggle equip item ability.

My next plan was to work off of CharacterEquipUnequipAction, but its equip was less straightforward for me. I'm not sure, but it seems like it equips from within the Inventory Bridge, which I don't want to mess with. I'll attach my first custom action here. Could you please tell me what I should do to change it? Sorry if my edits are a bit sloppy, I haven't written code in a while, so I'm kinda re-learning a lot of this.
 

Attachments

  • EquipRightAction.cs
    6.3 KB · Views: 3
Skimming through your code I don't see anything particularly wrong with it.
but you may want to have a further look at the CharacterEquipUnequipAction since it equips the item after adding it to the item collection. It does this inside the Bridge.
Check out the integration documentation, there should be some examples of equipping items.

Note there are differences between Equip/Unequip within UCC and UIS.
In UCC Equip means to hold the item and make it active.
In UIS Equip means adding it to the Equipment Item Collection.

We describe those states as Unequipped (in the Inventory), Soft Equipped (in the equipment collection, on the character, but not active) and Active Equipped (Active in the characters hand).
Read the Integration documentation again carefully and you might find your solution
 
After some messing around, I found that all I need to do is make sure the Default Item Set is active when equipping. The problems only happen when I try my custom equip while items are already Active Equipped. If I can set them to Soft Equipped by setting the Active Item Set to default (which is my "Relaxed/Sheathed" Set), the previously equipped items get replaced without issue.

I'm having problems finding the right way to do that, though. In game, I can use the "Toggle Equip" item ability on my character (bound to "T" key), and that solves the problem. I need to find a way to do that automatically through the equip action. Where can find the method to set the Active Item Set to Default, if there is one?
 
Never mind, I was able to figure it out! I feel very smart now lol :cool: Thank you for your help so far! Here's hoping I can figure the rest out myself now haha.

I'm going to drop my scripts here, in case anyone else is having a similar problem. Just as a note, if anyone is interested, I'm using these only to equip items. I'm using the regular CharacterEquipUnequip action for the Equipment Window unequip. This will help if you only have two item slots for each hand in an ItemSlotCollection and you use different categories for Two Hand and One hand items. Two Hand weapons are exclusive to One Handed ones. You'll definitely need to edit these, but I tried to simplify them as much as possible!
 

Attachments

  • CharacterEquipLeft.cs
    4.8 KB · Views: 0
  • CharacterEquipRight.cs
    4.8 KB · Views: 0
Top