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

Greystar

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


Im trying to get my shard to compile to test my ideas before I post them. I have added a bunch of other stuff to my shard I havnt debugged yet so it might be a while before I reply again... but WHEN we get this to work you should post your code... many people including me have been trying to get Killable, noninstakill, nonteleporting guards for a while.

Well changing the fightmode to fightmode.Closest and using my mod to the IsEnemy script I got it to crash. So Im assuming its trying to go after the Criminal I put in town.

PHP:
Server Crash Report
===================

RunUO Version 1.0.0, Build 27838
Operating System: Microsoft Windows NT 5.1.2600.0
.NET Framework: 1.1.4322.2032
Time: 4/23/2005 4:46:22 PM
Mobiles: 28822
Items: 142743
Clients:
- Count: 1
+ 127.0.0.1: (account = Greystar) (mobile = 0x1 'Shawn Ruester')

Exception:
System.InvalidCastException: Specified cast is not valid.
   at Server.Mobiles.ModBaseGuard.IsEnemy(Mobile m)
   at Server.Mobiles.BaseAI.AquireFocusMob(Int32 iRange, FightMode acqType, Boolean bPlayerOnly, Boolean bFacFriend, Boolean bFacFoe)
   at Server.Mobiles.MeleeAI.DoActionWander()
   at Server.Mobiles.BaseAI.Think()
   at Server.Mobiles.AITimer.OnTick()
   at Server.Timer.Slice()
   at Server.Core.Main(String[] args)
 

Murzin

Knight
ok.. then i would say most likely your problem is coming from an opposition group defined somewhere else.

find out where that is defined.

you could try commenting out the opposition group lines and see if it works then.
 

Greystar

Wanderer
Got It I think

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="[email protected]"][email protected][/email]
 
using System; 
using System.Collections; 
using Server.Misc; 
using Server.Items; 
using Server.Mobiles; 
 
namespace Server.Mobiles 
{ 
	public class ModBaseGuard : BaseCreature 
	{ 
 
		public override double GetValueFrom( Mobile m, FightMode acqType, bool bPlayerOnly )
		{
			bPlayerOnly = false;
 
			return base.GetValueFrom(m, acqType, bPlayerOnly);
		}
 
		[Constructable] 
		public ModBaseGuard() : base( AIType.AI_Melee, FightMode.Closest, 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 override bool IsEnemy( Mobile m )
		{
			OppositionGroup g = this.OppositionGroup;
 
			if ( g != null && g.IsEnemy( this, m ) )
				return true;
 
			if ( m != null && m.Criminal )
				return true;
 
			BaseCreature c = m as BaseCreature; // i dont get the whole point to this line... is it from latent code?
 
			if ( c != null && ( !(m is BaseCreature && c.Controled) || c is Server.Engines.Quests.Haven.MilitiaFighter ) )
				return false;
 
			return true;
		}
 
		public ModBaseGuard( 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(); 
		} 
	} 
}

This will attack and kill criminals weather they are Players or Not.

Edit: well not exactly kill cause the mob that I was using as an example guard got its but kicked so it ran away... but it initiated the attack.

I am still editing this to see if I can make them come when someone calls for help.

EDIT 2:
Heading that I think would be appropriate if I where going to release this

// 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]
// Moded by Greystar to make it so that it attacked criminals and reintroduced by Rebirah
// Help was given by Murzin and Kwwres10
 

Rebirah

Sorceror
Alright, it's working! I gave the guard some stats/skills I feel would be right for the guards on my server. Thanks to everyone who helped!

Finished script:

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]
// Moded by Greystar to make it so that it attacked criminals and reintroduced by Rebirah
// Help was given by Murzin and Kwwres10

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

namespace Server.Mobiles 
{ 
	public class Guards : BaseCreature 
	{ 
			public override double GetValueFrom( Mobile m, FightMode acqType, bool bPlayerOnly )
		{
			bPlayerOnly = false;

			return base.GetValueFrom(m, acqType, bPlayerOnly);
		}

		[Constructable] 
		public Guards() : base( AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4 ) 
		{ 
			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;
				}
			SetStr( 86, 100 );
			SetDex( 81, 95 );
			SetInt( 61, 75 );

			SetDamage( 30, 45 );

			SetSkill( SkillName.MagicResist, 30.0, 47.5 );
			SetSkill( SkillName.Swords, 100.0, 100.0 );
			SetSkill( SkillName.Tactics, 65.0, 87.5 );
			SetSkill( SkillName.Wrestling, 50.0, 75.5 );
			}
			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;
				}
			SetStr( 86, 100 );
			SetDex( 81, 95 );
			SetInt( 61, 75 );

			SetDamage( 30, 45 );

			SetSkill( SkillName.MagicResist, 30.0, 47.5 );
			SetSkill( SkillName.Swords, 100.0, 100.0 );
			SetSkill( SkillName.Tactics, 65.0, 87.5 );
			SetSkill( SkillName.Wrestling, 50.0, 75.5 );
			}
		}
public override 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; 

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

	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, it's working! I gave the guard some stats/skills I feel would be right for the guards on my server. Thanks to everyone who helped!

Finished script:

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]
// Moded by Greystar to make it so that it attacked criminals and reintroduced by Rebirah
// Help was given by Murzin and Kwwres10
 
using System; 
using System.Collections; 
using Server.Misc; 
using Server.Items; 
using Server.Mobiles; 
 
namespace Server.Mobiles 
{ 
	public class Guards : BaseCreature 
	{ 
			public override double GetValueFrom( Mobile m, FightMode acqType, bool bPlayerOnly )
		{
			bPlayerOnly = false;
 
			return base.GetValueFrom(m, acqType, bPlayerOnly);
		}
 
		[Constructable] 
		public Guards() : base( AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4 ) 
		{ 
			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;
				}
			SetStr( 86, 100 );
			SetDex( 81, 95 );
			SetInt( 61, 75 );
 
			SetDamage( 30, 45 );
 
			SetSkill( SkillName.MagicResist, 30.0, 47.5 );
			SetSkill( SkillName.Swords, 100.0, 100.0 );
			SetSkill( SkillName.Tactics, 65.0, 87.5 );
			SetSkill( SkillName.Wrestling, 50.0, 75.5 );
			}
			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;
				}
			SetStr( 86, 100 );
			SetDex( 81, 95 );
			SetInt( 61, 75 );
 
			SetDamage( 30, 45 );
 
			SetSkill( SkillName.MagicResist, 30.0, 47.5 );
			SetSkill( SkillName.Swords, 100.0, 100.0 );
			SetSkill( SkillName.Tactics, 65.0, 87.5 );
			SetSkill( SkillName.Wrestling, 50.0, 75.5 );
			}
		}
public override 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; 
 
	if ( !(c is BaseCreature && !c.Controled) || c is Server.Engines.Quests.Haven.MilitiaFighter )
		return false;
 
 
	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(); 
		} 
	} 
}


Now keep in mind that will only attack criminals I think it still need some tweaking to make it attack others too, but thats what im working on now... but thanks to You and Daat99 and a little by the others I mentioned I think I'll finally be able to make forward progress on my guardpost scripts.
 

Greystar

Wanderer
Rebirah said:
Hmm, my server seems to be crashing now when the guards attack something.

Ill mess with my version and see if I get the same results just hold of on releasing it for now... and just revert back to your old guards... I'll send you a copy of mine but I really do appreciate you bringing this method of setting them up to my attention I never thought of using IsEnemy to make them work.
 

Rebirah

Sorceror
It seems to be crashing when you get close to one of the guards, criminal or not. I'm thinking it's not when they try to attack something.

EDIT: Alright, I see what's happening, I added two guards next to eachother, and it seems one of them attacks the other and goes grey.

EDIT2: It seems the guards attack a lot of NPCs, blue or grey.
 

Murzin

Knight
replace :

Code:
public override 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; 

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

	return true;
}

with this:

Code:
public override bool IsEnemy( Mobile m )
{
	if ( m != null && ( m.Criminal == true ) )
		return true;

	if ( m is BaseVendor || m is TownCrier )
		return false;

	BaseCreature c = (BaseCreature)m; 

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

	return true;
}
 

Rebirah

Sorceror
Alright, I did that but they would still attack eachother and hireables, so I changed it to this
Code:
public override bool IsEnemy( Mobile m )
{
	if ( m != null && ( m.Criminal == true ) )
		return true;

	if ( m is BaseVendor || m is TownCrier || m is Guards || m is BaseHire )
		return false;

	BaseCreature c = (BaseCreature)m; 

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

	return true;
}

Now, the server still,and only crashes when it sees a PC that ISN'T criminal. So, I'm thinking the server is crashing because it doesnt know what to do if they aren't criminal.

EDIT:
Changed to:
Code:
public override bool IsEnemy( Mobile m )
{
	if ( m != null && ( m.Criminal == true ) )

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

	if ( m is BaseVendor || m is TownCrier || m is Guards || m is BaseHire )
		return false;

	BaseCreature c = (BaseCreature)m; 

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

	return true;
}

No crashes!!

EDIT 2:
Release here http://www.runuo.com/forum/showthread.php?t=55032
 

Murzin

Knight
replace:

Code:
	if ( m != null && ( m.Criminal == true ) )

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

with this:

Code:
if ( m != null && ( m.Criminal == true ) ) { return true; } else { return false; }
 

akrondar

Wanderer
any of you guys use some race system..? I have tried many many times to make a check in the guards to not attack ally races ( i only included a check in the guarded region so the guards attacks anyone that not belongs to the race)..
 

TheLemonJuce

Wanderer
tell me plzzzzzz

why does thoes guards doesn't stay in their places they just disappear???:confused: hmm could any body tell me how to make em dont disappear?
 
Top