RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Guards

Rebirah

Sorceror
Guards

Alright, originaly posted here http://www.runuo.com/forum/showthread.php?t=53559&highlight=guards by DaZiL, he was trying to get his custom mobile Guards to attack greys and reds. Unfortunatly, it was never fixed on the post to work, so I'm re-posting. I've searched the whole forum, no luck. I've also searched through mobiles, I even tried looking at how the faction guards attack opposing factions. I've tried different things to this code below, but no luck. The guards ignore greys and reds.

Thanks in advance!
Code:
public virtual bool IsEnemy( Mobile m )
{
OppositionGroup g = this.OppositionGroup;
return false;
if ( g != null && g.IsEnemy( this, m ) )
	return false;

if ( m != null && ( m.Criminal == true || m.Kills >= 5 == true ) )
	return false;
if ( !(m is BaseCreature) || m is Server.Engines.Quests.Haven.MilitiaFighter )
	return false;

BaseCreature c = (BaseCreature)m;

}

Code:
// Guard by DaZiL
// I give most of the credit to Daat99, for helping me do the target criminal/murder part.
// if you have a problem email me , [email protected]

using System; 
using System.Collections; 
using Server.Misc; 
using Server.Items; 
using Server.Mobiles; 

namespace Server.Mobiles 
{ 
	public class Guards : BaseCreature 
	{ 
		[Constructable] 
		public Guards() : base( AIType.AI_Melee, FightMode.Agressor, 10, 1, 0.2, 0.4 ) 
		{ 
			InitStats( 100, 105, 15 ); 
			Title = "the guard"; 

			SpeechHue = Utility.RandomDyedHue(); 

			Hue = Utility.RandomSkinHue(); 

			if ( Female = Utility.RandomBool() ) 
			{ 
				Body = 401; 
				Name = NameList.RandomName( "female" ); 
			Sandals sandals = new Sandals(); 
			sandals.Hue = 43;
			AddItem( sandals ); 
			LeatherSkirt skirt = new LeatherSkirt(); 
			AddItem( skirt ); 
			PlateGloves gloves = new PlateGloves(); 
			AddItem( gloves );  
			OrderShield ss = new OrderShield(); 
			AddItem( ss ); 
			VikingSword s = new VikingSword();
			AddItem( s ); 
			FemaleStuddedChest a = new FemaleStuddedChest(); 
			AddItem( a ); 
			} 
			else 
			{ 
				Body = 400; 			
	Name = NameList.RandomName( "male" ); 
			PlateLegs legs = new PlateLegs(); 
			AddItem( legs ); 
			PlateGloves gloves = new PlateGloves(); 
			AddItem( gloves );
			Tunic tunic = new Tunic(); 
			AddItem( tunic );
OrderShield shield = new OrderShield();
AddItem( shield );
VikingSword sword = new VikingSword();
AddItem( sword );
			} 
		}

public virtual bool IsEnemy( Mobile m )
{
OppositionGroup g = this.OppositionGroup;
return false;
if ( g != null && g.IsEnemy( this, m ) )
	return false;

if ( m != null && ( m.Criminal == true || m.Kills >= 5 == true ) )
	return false;
if ( !(m is BaseCreature) || m is Server.Engines.Quests.Haven.MilitiaFighter )
	return false;

BaseCreature c = (BaseCreature)m;

}

		public Guards( Serial serial ) : base( serial ) 
		{ 
		} 

		public override void Serialize( GenericWriter writer ) 
		{ 
			base.Serialize( writer ); 

			writer.Write( (int) 0 ); // version 
		} 

		public override void Deserialize( GenericReader reader ) 
		{ 
			base.Deserialize( reader ); 

			int version = reader.ReadInt(); 
		} 
	} 
}
 

Kwwres10

Wanderer
Code:
if ( m != null && ( m.Criminal == true || m.Kills >= 5 == true ) )
	return false;
That is saying if the char is red or grey NOT to attack it. Change it to this:

Code:
if ( m != null && ( m.Criminal == true || m.Kills >= 5 == true ) )
return true;
 

Murzin

Knight
--------------
public virtual bool IsEnemy( Mobile m )
{
OppositionGroup g = this.OppositionGroup;
return false;
---------------

remove that return false;
and try again

you are returning false before you even do any checks.
 

Rebirah

Sorceror
I removed the return false; and got an error on compiling.
Code:
 - Error: Scripts\Mobiles\Guards2.cs: CS0161: (line 62, column 21) 'Server.Mobil
es.Guards.IsEnemy(Server.Mobile)': not all code paths return a value
 

Murzin

Knight
yup... you have checks that have return types, but there is no "base return type" at the end. because it sees return types for your checks, it wants a return type for the method if none of your checks provide one.

then it should work right as long as opposition group isnt providing a return type before you even get to your checks.
 

Rebirah

Sorceror
Alright, this is the while script with all my edits, they still don't wanna attack criminals, they just call guards themselves.

Code:
public virtual bool IsEnemy( Mobile m )
{
OppositionGroup g = this.OppositionGroup;
	
if ( g != null && g.IsEnemy( this, m ) )
	return false;

if ( m != null && ( m.Criminal == true ) )
	return false;
if ( !(m is BaseCreature) || m is Server.Engines.Quests.Haven.MilitiaFighter )
	return false;
	
BaseCreature c = (BaseCreature)m;
return false;

}

Code:
// Guard by DaZiL
// I give most of the credit to Daat99, for helping me do the target criminal/murder part.
// if you have a problem email me , [email protected]

using System; 
using System.Collections; 
using Server.Misc; 
using Server.Items; 
using Server.Mobiles; 

namespace Server.Mobiles 
{ 
	public class Guards : BaseCreature 
	{ 
		[Constructable] 
		public Guards() : base( AIType.AI_Melee, FightMode.Agressor, 10, 1, 0.2, 0.4 ) 
		{ 
			InitStats( 100, 105, 15 ); 
			Title = "the guard"; 

			SpeechHue = Utility.RandomDyedHue(); 

			Hue = Utility.RandomSkinHue(); 

			if ( Female = Utility.RandomBool() ) 
			{ 
				Body = 401; 
				Name = NameList.RandomName( "female" );
				AddItem( new Halberd() );
				switch( Utility.Random( 2 ) )
				{
					case 0: AddItem( new LeatherSkirt() ); break;
					case 1: AddItem( new LeatherShorts() ); break;
				}

				switch( Utility.Random( 5 ) )
				{
					case 0: AddItem( new FemaleLeatherChest() ); break;
					case 1: AddItem( new FemaleStuddedChest() ); break;
					case 2: AddItem( new LeatherBustierArms() ); break;
					case 3: AddItem( new StuddedBustierArms() ); break;
					case 4: AddItem( new FemalePlateChest() ); break;
				}
			}
			else 
			{ 
				Body = 400; 			
				Name = NameList.RandomName( "male" ); 
				AddItem( new PlateChest() );
				AddItem( new PlateArms() );
				AddItem( new PlateLegs() );
				AddItem( new Halberd() );

				switch( Utility.Random( 3 ) )
				{
					case 0: AddItem( new Doublet( Utility.RandomNondyedHue() ) ); break;
					case 1: AddItem( new Tunic( Utility.RandomNondyedHue() ) ); break;
					case 2: AddItem( new BodySash( Utility.RandomNondyedHue() ) ); break;
				}
			}
		}
public virtual bool IsEnemy( Mobile m )
{
OppositionGroup g = this.OppositionGroup;
	
if ( g != null && g.IsEnemy( this, m ) )
	return false;

if ( m != null && ( m.Criminal == true ) )
	return false;
if ( !(m is BaseCreature) || m is Server.Engines.Quests.Haven.MilitiaFighter )
	return false;
	
BaseCreature c = (BaseCreature)m;
return false;

}

		public Guards( Serial serial ) : base( serial ) 
		{ 
		} 

		public override void Serialize( GenericWriter writer ) 
		{ 
			base.Serialize( writer ); 

			writer.Write( (int) 0 ); // version 
		} 

		public override void Deserialize( GenericReader reader ) 
		{ 
			base.Deserialize( reader ); 

			int version = reader.ReadInt(); 
		} 
	} 
}
 

Murzin

Knight
try this

Code:
public virtual bool IsEnemy( Mobile m )
{
	OppositionGroup g = this.OppositionGroup;
	
	if ( g != null && g.IsEnemy( this, m ) )
		return true;

	if ( m != null && ( m.Criminal == true ) )
		return true;

	if ( !(m is BaseCreature && m.Owner == null ) || m is Server.Engines.Quests.Haven.MilitiaFighter )
		return false;
	
	BaseCreature c = (BaseCreature)m; // i dont get the whole point to this line...  is it from latent code?

	return true;
}
 

Rebirah

Sorceror
Tried, I get an error
Code:
 - Error: Scripts\Mobiles\Guards2.cs: CS0117: (line 72, column 30) 'Server.Mobil
e' does not contain a definition for 'Owner'
 

Rebirah

Sorceror
Alright, tried that, still no luck, same error.
Code:
- Error: Scripts\Mobiles\Guards2.cs: CS0117: (line 72, column 30) 'Server.Mobil
e' does not contain a definition for 'Controled'
 

Rebirah

Sorceror
Updated code:

Code:
// Guard by DaZiL
// I give most of the credit to Daat99, for helping me do the target criminal/murder part.
// if you have a problem email me , [email protected]

using System; 
using System.Collections; 
using Server.Misc; 
using Server.Items; 
using Server.Mobiles; 

namespace Server.Mobiles 
{ 
	public class Guards : BaseCreature 
	{ 
		[Constructable] 
		public Guards() : base( AIType.AI_Melee, FightMode.Agressor, 10, 1, 0.2, 0.4 ) 
		{ 
			InitStats( 100, 105, 15 ); 
			Title = "the guard"; 

			SpeechHue = Utility.RandomDyedHue(); 

			Hue = Utility.RandomSkinHue(); 

			if ( Female = Utility.RandomBool() ) 
			{ 
				Body = 401; 
				Name = NameList.RandomName( "female" );
				AddItem( new Halberd() );
				switch( Utility.Random( 2 ) )
				{
					case 0: AddItem( new LeatherSkirt() ); break;
					case 1: AddItem( new LeatherShorts() ); break;
				}

				switch( Utility.Random( 5 ) )
				{
					case 0: AddItem( new FemaleLeatherChest() ); break;
					case 1: AddItem( new FemaleStuddedChest() ); break;
					case 2: AddItem( new LeatherBustierArms() ); break;
					case 3: AddItem( new StuddedBustierArms() ); break;
					case 4: AddItem( new FemalePlateChest() ); break;
				}
			}
			else 
			{ 
				Body = 400; 			
				Name = NameList.RandomName( "male" ); 
				AddItem( new PlateChest() );
				AddItem( new PlateArms() );
				AddItem( new PlateLegs() );
				AddItem( new Halberd() );

				switch( Utility.Random( 3 ) )
				{
					case 0: AddItem( new Doublet( Utility.RandomNondyedHue() ) ); break;
					case 1: AddItem( new Tunic( Utility.RandomNondyedHue() ) ); break;
					case 2: AddItem( new BodySash( Utility.RandomNondyedHue() ) ); break;
				}
			}
		}
public virtual bool IsEnemy( Mobile m )
{
	OppositionGroup g = this.OppositionGroup;
	
	if ( g != null && g.IsEnemy( this, m ) )
		return true;

	if ( m != null && ( m.Criminal == true ) )
		return true;

	if ( !(m is BaseCreature && m.Controled == null) || m is Server.Engines.Quests.Haven.MilitiaFighter )
		return false;
	
	BaseCreature c = (BaseCreature)m; // i dont get the whole point to this line...  is it from latent code?

	return true;
}

		public Guards( Serial serial ) : base( serial ) 
		{ 
		} 

		public override void Serialize( GenericWriter writer ) 
		{ 
			base.Serialize( writer ); 

			writer.Write( (int) 0 ); // version 
		} 

		public override void Deserialize( GenericReader reader ) 
		{ 
			base.Deserialize( reader ); 

			int version = reader.ReadInt(); 
		} 
	} 
}
 

Greystar

Wanderer
Rebirah said:
Alright, tried that, still no luck, same error.
Code:
- Error: Scripts\Mobiles\Guards2.cs: CS0117: (line 72, column 30) 'Server.Mobil
e' does not contain a definition for 'Controled'

Code:
public virtual bool IsEnemy( Mobile m )
{
	OppositionGroup g = this.OppositionGroup;
	
	if ( g != null && g.IsEnemy( this, m ) )
		return true;

	if ( m != null && ( m.Criminal == true ) )
		return true;

	BaseCreature c = (BaseCreature)m; // i dont get the whole point to this line...  is it from latent code?

	if ( !(c is BaseCreature && c.Controled) || c is Server.Engines.Quests.Haven.MilitiaFighter )
		return false;
	

	return true;
}

although that may have to be !c.Controled

the term controled is a Boolean value and only exists in BaseCreature how you where using it was looking for it in Mobile same with Owner it only exists in BaseCreature.

Edit: Just noticed this post gave me my 300th post
 

Rebirah

Sorceror
Grats on your 300th!

I tried what you said, and it compiles fine, but the guards still just stand there and shout for guards. The guards still don't seem to be attacking criminals.
 

Greystar

Wanderer
Code:
public virtual bool IsEnemy( Mobile m )
{
	OppositionGroup g = this.OppositionGroup;
	
	if ( g != null && g.IsEnemy( this, m ) )
		return true;

	if ( m != null && ( m.Criminal == true ) )
		return true;

	BaseCreature c = (BaseCreature)m; // i dont get the whole point to this line...  is it from latent code?

	if ( !(c is BaseCreature && c.Controled) || c is Server.Engines.Quests.Haven.MilitiaFighter )
		return false;
	

	return true;
}

This is from your guards script right?
if it is try changing this line:
public virtual bool IsEnemy( Mobile m )

to

public override bool IsEnemy( Mobile m )
 

Rebirah

Sorceror
I placed spawners of these guys in town and disabled town guards. These will replace the insta-kill guards. I tried override, still nothing
 
Top