you can also use item level. For example item level 1 = melee weapons, so if unit wants to pick an item, you check if it does not already have an item with level 1 and if yes, you prevent the unit from picking the new item.
Items by default allow levels between 0 and 8, but shift clicking the field allows you to paste in a custom value. I set it to 40 and the game also returned 40, so it should work for you.