Lemke

Member
Hello all!
Just trying to do players cannot hurt other players with levelable weapons,tryed this in BaseWeapon.cs :

C#:
public virtual void OnHit(Mobile attacker, IDamageable damageable, double damageBonus)
        {
            if (EndDualWield)
            {
                ProcessingMultipleHits = false;
                EndDualWield = false;
            }

            Mobile defender = damageable as Mobile;
            Clone clone = null;
            //
            if (defender is PlayerMobile && (XmlLevelItem)XmlAttach.FindAttachment(this, typeof(XmlLevelItem)))
            {
                attacker.SendMessage( "Cannot hurt players with levelable weapons!" );
                return;
            }
Getting this issue:
C#:
Errors:
 + Items/Equipment/Weapons/BaseWeapon.cs:
    CS0019: Line 2234: Operator '&&' cannot be applied to operands of type 'bool' and 'XmlLevelItem'
Scripts: One or more scripts failed to compile or no script files were found.

Any advice?Thank you!
 
Hello all!
Just trying to do players cannot hurt other players with levelable weapons,tryed this in BaseWeapon.cs :

C#:
public virtual void OnHit(Mobile attacker, IDamageable damageable, double damageBonus)
        {
            if (EndDualWield)
            {
                ProcessingMultipleHits = false;
                EndDualWield = false;
            }

            Mobile defender = damageable as Mobile;
            Clone clone = null;
            //
            if (defender is PlayerMobile && (XmlLevelItem)XmlAttach.FindAttachment(this, typeof(XmlLevelItem)))
            {
                attacker.SendMessage( "Cannot hurt players with levelable weapons!" );
                return;
            }
Getting this issue:
C#:
Errors:
 + Items/Equipment/Weapons/BaseWeapon.cs:
    CS0019: Line 2234: Operator '&&' cannot be applied to operands of type 'bool' and 'XmlLevelItem'
Scripts: One or more scripts failed to compile or no script files were found.

Any advice?Thank you!
You are on the right track, but because mobiles and items are handled in different ways, using different script libraries, you have to turn one into the other type. You are comparing Apples and Einstein, but you need to make them both Fruits (items), or both People(mobiles) ;)

Checking for one or the other first might be easier. If you go with Playermobile first then any player hitting another player will result in the error message. That does not seem like what you want to do. It seems to me as if you want *just* levelable items not to damage other players (which prevents the weapons from gaining XP).

So the other path is to go with the item (weapon) and check the attachment first and then check if it is Playermobile or Basecreature and then call the attachment or not. If you create a variable for XmlLevelItem like this:

XmlLevelItem a = (XmlLevelItem)XmlAttach.FindAttachment(this, typeof(XmlLevelItem));

You can check if a !=null (if a *is not* equal to null) then check if the defender is Playermobile and then call the attachment or not.
If a *is* null, the code jumps right out of the whole If/Then statement and ignores anything to do with XmlLevelItem, which seems to me like what you want.

Does that help? :)
 
yeah do it the way tass says, if you have leveleable RANGED weapons remember to add the same method to BaseRange.cs


C#:
XmlLevelItem a = (XmlLevelItem)XmlAttach.FindAttachment(this, typeof(XmlLevelItem));
if (attacker != null && defender != null && defender is PlayerMobile)
    {
    if (a != null)
            {
     attacker.SendMessage( "Cannot hurt players with levelable weapons!" );
                return;
            }
    }
 

Active Shards

Donations

Total amount
$50.00
Goal
$1,000.00
Back