It's enough to override the Use( Item item ) method in PlayerMobile for this idea and check the items on the Layer property.You have to create the double click code then add it to each of your base classes, BaseArmor, BaseWeapon, etc.
Place this code in the PlayerMobile.cs script.Can you give a more detailed example of the script and where to insert it?
public override void Use(Item item)
{
base.Use(item);
if (item.IsChildOf(this.Backpack))
{
if (item.Movable && item is ICraftable)
{
if (CanEquipItem(item))
EquipItem(item);
else
{
PlaceInBackpack(FindItemOnLayer(item.Layer));
EquipItem(item);
}
}
}
}
private bool CanEquipItem(Item item)
{
return !Items.Any(i => i.Layer == item.Layer);
}
Thanks, but unfortunately there is a compilation error(Place this code in the PlayerMobile.cs script.
C#:public override void Use(Item item) { base.Use(item); if (item.IsChildOf(this.Backpack)) { if (item.Movable && item is ICraftable) { if (CanEquipItem(item)) EquipItem(item); else { PlaceInBackpack(FindItemOnLayer(item.Layer)); EquipItem(item); } } } } private bool CanEquipItem(Item item) { return !Items.Any(i => i.Layer == item.Layer); }
public override bool AllowItemUse(Item item)
And can you be more precise where lower?You need to place that a little further along in your code, where it goes further down shouldn't actually matter.. I placed it right above here:
I have tested the code and it does work as expected, I would love for it to work both ways though..C#:public override bool AllowItemUse(Item item)
using System.Linq;
It works with replacing equipped itemsHi guys, thanks for this, I wanted to do the same. It works fine with double click, but I only have one problem. If I am already wearing a weapon and I double click a new one from the backpack it says: "You can only wield one weapon at time" instead of equip the new one and put the previous one directly in the backpack. Do you know how can I change that?
Thank you in advance!
I used this, but in my case, does not work if I am already wearing a weapon. I have to disarm the first weapon and then double click to equip the second one. Any ideas? Thanks.It works with replacing equipped items
public override void Use(Item item)
{
base.Use(item);
if (!item.IsChildOf(Backpack)) return;
if (!item.Movable || item is not ICraftable) return;
if (CanEquipItem(item))
EquipItem(item);
else
{
if (item is BaseWeapon wp)
{
switch (wp.Layer)
{
case Layer.TwoHanded:
PlaceInBackpack(FindItemOnLayer(Layer.TwoHanded));
PlaceInBackpack(FindItemOnLayer(Layer.OneHanded));
EquipItem(item);
return;
case Layer.OneHanded:
if (FindItemOnLayer(Layer.TwoHanded) is BaseWeapon thwp) PlaceInBackpack(thwp);
PlaceInBackpack(FindItemOnLayer(Layer.OneHanded));
EquipItem(item);
return;
}
}
else
{
PlaceInBackpack(FindItemOnLayer(item.Layer));
EquipItem(item);
}
}
}
private bool CanEquipItem(Item item)
{
if (!(item is BaseWeapon wp)) return Items.All(i => i.Layer != item.Layer);
switch (wp.Layer)
{
case Layer.TwoHanded:
return FindItemOnLayer(Layer.OneHanded) == null && FindItemOnLayer(Layer.TwoHanded) == null;
case Layer.OneHanded:
return FindItemOnLayer(Layer.OneHanded) == null && (FindItemOnLayer(Layer.TwoHanded) == null ||
FindItemOnLayer(Layer.TwoHanded) is BaseArmor);
default:
return Items.All(i => i.Layer != item.Layer);
}
}
That's because BaseWeapon needs a specific handling, due to its nature of being more particular: one handed can go only if there is nothing in 1h and nothing or not a weapon in 2h (1h works with shields, that are basearmor in twohanded layer). I'm not on a standard ServUO/RunUO and I don't know which .NET are you using (I'm on NET 7) so I tried to be as verbose and old-styled as possible, then you can prettify and modernise the code according to your necessities.
For example there is CleanHands that could be used, with the correct modifications to handle shields as well, etc. Lot of things can be done to make the code smarter, but I just wrote the most basic to make it work in "almost" any situation.
Anyway the concept is that you need to handle differently both che CanEquipItem check and the equipment itself for weapons, cause they work differently ^^.
Code:public override void Use(Item item) { base.Use(item); if (!item.IsChildOf(Backpack)) return; if (!item.Movable || item is not ICraftable) return; if (CanEquipItem(item)) EquipItem(item); else { if (item is BaseWeapon wp) { switch (wp.Layer) { case Layer.TwoHanded: PlaceInBackpack(FindItemOnLayer(Layer.TwoHanded)); PlaceInBackpack(FindItemOnLayer(Layer.OneHanded)); EquipItem(item); return; case Layer.OneHanded: if (FindItemOnLayer(Layer.TwoHanded) is BaseWeapon thwp) PlaceInBackpack(thwp); PlaceInBackpack(FindItemOnLayer(Layer.OneHanded)); EquipItem(item); return; } } else { PlaceInBackpack(FindItemOnLayer(item.Layer)); EquipItem(item); } } } private bool CanEquipItem(Item item) { if (!(item is BaseWeapon wp)) return Items.All(i => i.Layer != item.Layer); switch (wp.Layer) { case Layer.TwoHanded: return FindItemOnLayer(Layer.OneHanded) == null && FindItemOnLayer(Layer.TwoHanded) == null; case Layer.OneHanded: return FindItemOnLayer(Layer.OneHanded) == null && (FindItemOnLayer(Layer.TwoHanded) == null || FindItemOnLayer(Layer.TwoHanded) is BaseArmor); default: return Items.All(i => i.Layer != item.Layer); } }
We use essential cookies to make this site work, and optional cookies to enhance your experience.