ServUO Version
Publish 57
Ultima Expansion
Endless Journey
Trying to create something, not ready to reveal it just yet so if you need the whole script just message me. Anyways I have this piece of code:
C#:
                if (from.IsParagon == false)
                {
                    from.SendMessage("That pet is not a paragon!");
                }
throwing this error:
C#:
error CS1061: 'Mobile' does not contain a definition for 'IsParagon' and no accessible extension method 'IsParagon' accepting a first argument of type 'Mobile' could be found (are you missing a using directive or an assembly reference?)
I have Server.Mobiles in the reference and there is an "IsParagon" in BaseCreature so I'm not sure what I'm doing wrong. Again if you need the full code just message me, thanks :)
 
Well like you wrote. IsParagon is in BaseCreature, not in Mobile.

What you need to do is make a check if from is BaseCreature and then cast that to BaseCreature so you can use the property of from, but as a BaseCreature
 
Something like this?
C#:
                if (from is BaseCreature)
                {
                    BaseCreature t = (BaseCreature)from;

                    if (t.IsParagon == true)
                    {
                        from.SendMessage("That pet is already a paragon!");
                    }
                    else

                    {
                        t.IsParagon = !t.IsParagon;
                        from.SendMessage("You convert this creature to a paragon!");
                    }

                }
 
Well like you wrote. IsParagon is in BaseCreature, not in Mobile.

What you need to do is make a check if from is BaseCreature and then cast that to BaseCreature so you can use the property of from, but as a BaseCreature
You could take it one further ;) by doing something like this;
Take it Further:
if (from is BaseCreature bc && !bc.IsParagon)
{
     from.SendMessage("That pet is not a paragon!");
}

However why are we SendingMessage to from if from is BaseCreature? We would want bc?.ControlMaster.SendMessage("Message here"); most likely, otherwise it is sending it to the pet Mobile from.

**Edit**
There is also no need for == false/true since IsParagon is true while !IsParagon is false.
 
You could take it one further ;) by doing something like this;
Take it Further:
if (from is BaseCreature bc && !bc.IsParagon)
{
     from.SendMessage("That pet is not a paragon!");
}

However why are we SendingMessage to from if from is BaseCreature? We would want bc?.ControlMaster.SendMessage("Message here"); most likely, otherwise it is sending it to the pet Mobile from.

**Edit**
There is also no need for == false/true since IsParagon is true while !IsParagon is false.
I am not sure atm if pub57 supported the .net Version to use pattern matching, but yes sure if it does going that way makes it shorter
 
if pattern matching is available you could also write it in this way:
C#:
if (from is BaseCreature { IsParagorn: false })
{
    from.SendMessage("That pet is not a paragon!");
}

I don't know if you have to send it also in case it was not a BaseCreature at all; in this case you could write it as:
C#:
if(from is not BaseCreature { IsParagorn: true })
{
    from.SendMessage("That pet is not a paragon!");
}
 
Sometimes creatures can't be paragons :)

The "from" reference should always refer to the player doing the action;
The "targetMobile" should always refer to the subject of the player's action;
This can be done with targeting, or using an existing reference like "from.Combatant", etc.

C#:
if ( targetMobile is BaseCreature creature )
{
    if ( creature.IsParagon )
    {
        from.SendMessage( "That creature is already a paragon!" );
    }
    else if ( creature.CanBeParagon )
    {
        creature.IsParagon = true;

        from.SendMessage( "You convert the creature to a paragon!" );
    }
    else
    {
        from.SendMessage( "That creature cannot be a paragon!" );
    }
}
 
Back