Vert-I-Go

Member
ServUO Version
Publish Unknown
Ultima Expansion
Stygian Abyss
Ok general question kind of out of the park here. I have a craftable item which on double click it will produce and mobile with a public enum I want the resource to match the enum when double clicked. but having some issues just need a nudge lol here is code have somewhat an idea but running into issues.
1. MechanicalScorpion scorpion = new MechanicalScorpion(); " I know in this area after the ;ast part the "() there will need to be something in there my enum will need to be in there to call out in the mobile just not quite sure how to do it if someone could just guide me to a example of a script i can look at to see would help.
2. ill post code for OnDoubleClick part im having an issue with not sure excatly how to go about this.
ondouble click:
public override void OnDoubleClick( Mobile from )
        {
                        if ( !IsChildOf( from.Backpack ) )
                        {
                                from.SendMessage( "You must have the Statue in your backpack to release the mechanical scorpion." );
                        }
            else if ( this.AllowCharging == true )
            {
                this.Delete();
                from.SendMessage( "You have now freed the Mechanical Scorpion from its Statue!!" );
               
                if ( this.Resource.DullCopper )
                {
                    MechanicalScorpion scorpion = new MechanicalScorpion();
                    scorpion.Map = from.Map;
                         scorpion.Location = from.Location;
                    scorpion.Controlled = true;
                    scorpion.ControlMaster = from;
                    scorpion.IsBonded = true;
                }
                else
                {
                    MechanicalScorpion scorpion = new MechanicalScorpion();
                    scorpion.Map = from.Map;
                         scorpion.Location = from.Location;
                    scorpion.Controlled = true;
                    scorpion.ControlMaster = from;
                    scorpion.IsBonded = true;
                }

And now ill post the error

error:
Errors:
 + Items/Skill Items/Tinkering/Mechs/MechanicalScorpionStatue.cs:
    CS0176: Line 51: Member 'Server.Items.CraftResource.DullCopper' cannot be accessed with an instance reference; qualify it with a type name instead
    CS0029: Line 51: Cannot implicitly convert type 'Server.Items.CraftResource' to 'bool'

Any help would be greatful some examples would be great.

opps ill post my enum from the basecreature mech im going to be spawning from the item.

enums:
public enum MaterialType
    {
        Iron,
        DullCopper,
        ShadowIron,
        Copper,
        Bronze,
        Gold,
        Silver,
        Cobalt,
        Thorium,
        Mythril
    }
 
Ok I got the spawned creature to get the enum flag I wanted now I just need the if statement to work lol here is what I did.
if ( this.Resource.DullCopper ) THIS is what I need to get to work....
ondouble click:
public override void OnDoubleClick( Mobile from )
		{
                        if ( !IsChildOf( from.Backpack ) ) 
                        { 
                                from.SendMessage( "You must have the Statue in your backpack to release the mechanical scorpion." );
                        } 
			else if ( this.AllowCharging == true )
			{
				this.Delete();
				from.SendMessage( "You have now freed the Mechanical Scorpion from its Statue!!" );
				
				if ( this.Resource.DullCopper )
				{
					MechanicalScorpion scorpion = new MechanicalScorpion();
					scorpion.Map = from.Map; 
         				scorpion.Location = from.Location; 
					scorpion.Controlled = true;
					scorpion.ControlMaster = from;
					scorpion.IsBonded = true;
					scorpion.MaterialType = MaterialType.DullCopper;
				}
				else
				{
					MechanicalScorpion scorpion = new MechanicalScorpion();
					scorpion.Map = from.Map; 
         				scorpion.Location = from.Location; 
					scorpion.Controlled = true;
					scorpion.ControlMaster = from;
					scorpion.IsBonded = true;
					scorpion.MaterialType = MaterialType.Iron;
				}

         			
			}
			else
			{
				from.SendMessage( "The Mechanical Scorpion is not yet ready to be released." );
			}
		}
OK YAY Got it working....... Here is how I did it in case anyone was wondering.

ondouble click:
if ( this.Resource == CraftResource.DullCopper )
				{
					MechanicalScorpion scorpion = new MechanicalScorpion();
					scorpion.Map = from.Map; 
         				scorpion.Location = from.Location; 
					scorpion.Controlled = true;
					scorpion.ControlMaster = from;
					scorpion.IsBonded = true;
					scorpion.MaterialType = MaterialType.DullCopper;
				}
				else
				{
					MechanicalScorpion scorpion = new MechanicalScorpion();
					scorpion.Map = from.Map; 
         				scorpion.Location = from.Location; 
					scorpion.Controlled = true;
					scorpion.ControlMaster = from;
					scorpion.IsBonded = true;
					scorpion.MaterialType = MaterialType.Iron;
				}
 
Last edited:
Question, why do you need the MaterialType enum? You can use the CraftResource enum too, then you wouldnt need to try to convert from one enum to another with a bunch of if statements.

You would just need to change the MechanicalScorpions MateralType property to use CraftResource instead.

In that way it would turn out to be this for all types:
C#:
                    MechanicalScorpion scorpion = new MechanicalScorpion();
                    scorpion.Map = from.Map;
                     scorpion.Location = from.Location;
                    scorpion.Controlled = true;
                    scorpion.ControlMaster = from;
                    scorpion.IsBonded = true;
                    scorpion.MaterialType = Resource;

And if you want to limit that to just metal or just specific materials you can always add a condition to it like this

C#:
               if(Resource >= CraftResource.Iron && Resource <= CraftResource.Mythril)
                {
                    MechanicalScorpion scorpion = new MechanicalScorpion();
                    scorpion.Map = from.Map;
                    scorpion.Location = from.Location;
                    scorpion.Controlled = true;
                    scorpion.ControlMaster = from;
                    scorpion.IsBonded = true;
                    scorpion.MaterialType = Resource;
                }
                else
                {
                    from.SendMessage("Something went wrong!");
                    return;
                }
 
Because its referencing it to a mobile enum from a craft resource i know might not make sense at glance if you saw the entire system would make sense later. The enum isnt the craft resource its just named the same thing i know its confusing but there is a method to the madness lol my mechs are based on a basemech that is trainable and other systems so on the surface i know what your saying it just goes much deeper.
 
I see, well I was just wondering, is all :D

if you want to be cheeky, you could keep your enum and make it simpler for you regardless.

Add the None in the enum, or set Iron to Value 1 and then you can simply do
scorpion.MaterialType = (MaterialType)Resource;

That is if your Resources have your indexing like MaterialType.
Enums are basically just number values, that are given an accessor so you get some "typesafety" but imo more felxibility and readability
 
Ya the enum is going to be used in a really flexible way when dealing with the mobile it self was just referencing it in this summoning statue for the crafting purpose for stats when crafting but will be used in other ways later. So it gets alittle confusing I know for listing it in the question i had I know having them the same name. I could have called it ConstructionType to eliminate the confusion since it really has nothing to do with the resource just wanted the two to reflect each other.
 
Hmm I see, then I would at least suggest an public static dictionary<CraftResource, MaterialType>

That way you can still get the value directly, and you wouldnt have to do all the conditions or switches in case you do need it in another script again
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back