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!

Lost - looking for direction

I created an addon for players to use in their house.

It looks like a bookcase inside the house but when 'DBL Clicked' it moves the player into a wine cellar below the house. From there the player can walk up a step that transports them back beside the bookcase.

Here is where I get stuck - Players or others who get into the wine cellar can mark runes there. They can recall into the wine cellar and even if the house is not Public (true - they cannot get upstairs but they can get into the cellar.

I am wondering how I can prevent anyone from Marking runes in this area. I have ruled out the use of Regions because players all over the land may install these cellars.

Does anyone have any idea where I could look for examples or guidance on how to prevent the use of spells while standing on certain tiles (addon components)?

Thx
 

Hammerhand

Knight
No example, but an idea.. What about adding a check into RecallRune.cs to see if the player is in the cellar addon. If they are, then dont allow marking. Not sure how it would be done exactly, but its an idea.
 
Thanks Hammerhand.

While waiting for ideas like yours I had been working away on the problem and thought I found a solution - 'wrong'.

When a player DBL clicks the bookcase to gain entry to the wine cellar, a special 'Marker' drops in his pack. This 'Marker' is removed when the player leaves the wine cellar. Having achieved that I tried the combination of script changes below.

However - my solution does not work because the player can still cast spells (Mark runes inside the wine cellar) while carrying the indicated 'Marker'


Here is the check I put in SpelHelper.cs

Code:
public static bool CheckCast( Mobile caster, Spell spell )
{
//********************************************************************
if( WineCellarMarker.ExistsOn( caster ) )
{
caster.SendLocalizedMessage( 502629 ); // You cannot cast spells here.
return false;
}
//********************************************************************
 
if( Factions.Sigil.ExistsOn( caster ) )
{
caster.SendLocalizedMessage( 1061632 ); // You can't do that while carrying the sigil.
return false;
}
else if( !caster.CanBeginAction( typeof( PolymorphSpell ) ) )
{
caster.SendLocalizedMessage( 1061628 ); // You can't do that while polymorphed.
return false;
}
else if( AnimalForm.UnderTransformation( caster ) )
{
caster.SendLocalizedMessage( 1061091 ); // You cannot cast that spell in this form.
return false;
}
 
return true;
}
 
public static bool OnCast( Mobile caster, Spell spell )
{
//********************************************************************
if( WineCellarMarker.ExistsOn( caster ) )
{
caster.SendLocalizedMessage( 502629 ); // You cannot cast spells here.
return false;
}
//*********************************************************************


And . . I put this bit in the Marker script

Code:
public static bool ExistsOn( Mobile mob )
{
Container pack = mob.Backpack;
 
return ( pack != null && pack.FindItemByType( typeof( WineCellarMarker ) ) != null );
}

Can anyone see whay this is not working to stop casting?
 

daat99

Moderator
Staff member
Add this at the top of CheckCast (before your code):
Code:
if ( caster is PlayerMobile )
    Console.WriteLine("CheckCast: {0} HasMarker: {1}.", ((PlayerMobile)caster).Name, WineCellarMarker.ExistsOn( caster ));
what does it write in the console when you try to cast a spell with that code in?
 
Add this at the top of CheckCast (before your code):
Code:
if ( caster is PlayerMobile )
    Console.WriteLine("CheckCast: {0} HasMarker: {1}.", ((PlayerMobile)caster).Name, WineCellarMarker.ExistsOn( caster ));
what does it write in the console when you try to cast a spell with that code in?



Thx Daat

Okay I addded the check to SpelHelper.cs and nothing happened (as a player or as an admin). So I also added the check to OnCast but got same result. Nothing shows in the console and the player can cast any spell including Mark.

Here is the current script snip:

Code:
public static bool CheckCast( Mobile caster, Spell spell )
{
 
 
if ( caster is PlayerMobile )
    Console.WriteLine("CheckCast: {0} HasMarker: {1}.", ((PlayerMobile)caster).Name, WineCellarMarker.ExistsOn( caster ));
//********************************************************************
if( WineCellarMarker.ExistsOn( caster ) )
{
caster.SendLocalizedMessage( 502629 ); // You cannot cast spells here.
return false;
}
//********************************************************************
 
 
if( Factions.Sigil.ExistsOn( caster ) )
{
caster.SendLocalizedMessage( 1061632 ); // You can't do that while carrying the sigil.
return false;
}
else if( !caster.CanBeginAction( typeof( PolymorphSpell ) ) )
{
caster.SendLocalizedMessage( 1061628 ); // You can't do that while polymorphed.
return false;
}
else if( AnimalForm.UnderTransformation( caster ) )
{
caster.SendLocalizedMessage( 1061091 ); // You cannot cast that spell in this form.
return false;
}
 
return true;
}
 
public static bool OnCast( Mobile caster, Spell spell )
{
 
 
if ( caster is PlayerMobile )
    Console.WriteLine("OnCast: {0} HasMarker: {1}.", ((PlayerMobile)caster).Name, WineCellarMarker.ExistsOn( caster ));
//********************************************************************
if( WineCellarMarker.ExistsOn( caster ) )
{
caster.SendLocalizedMessage( 502629 ); // You cannot cast spells here.
return false;
}
//*********************************************************************
 
Okay - continuing the effort. I decided to try an approach to find the Marker that has worked on quests I have made.

Well no luck same result. No console messages and player can cast all spells.

Here is my latest try (in SpelHelper.cs):

Code:
public static bool CheckCast( Mobile caster, Spell spell )
{
Item marker1 = caster.Backpack.FindItemByType(typeof(WineCellarMarker));
if (marker1 != null)
{
Console.WriteLine("CheckCast: {0} HasMarker: {1}.", ((PlayerMobile)caster).Name, WineCellarMarker.ExistsOn( caster ));
caster.SendLocalizedMessage( 502629 ); // You cannot cast spells here.
return false;
}
 
//********************************************************************
//if( WineCellarMarker.ExistsOn( caster ) )
//{
//caster.SendLocalizedMessage( 502629 ); // You cannot cast spells here.
//return false;
//}
//********************************************************************
 
if( Factions.Sigil.ExistsOn( caster ) )
{
caster.SendLocalizedMessage( 1061632 ); // You can't do that while carrying the sigil.
return false;
}
else if( !caster.CanBeginAction( typeof( PolymorphSpell ) ) )
{
caster.SendLocalizedMessage( 1061628 ); // You can't do that while polymorphed.
return false;
}
else if( AnimalForm.UnderTransformation( caster ) )
{
caster.SendLocalizedMessage( 1061091 ); // You cannot cast that spell in this form.
return false;
}
 
return true;
}
 
public static bool OnCast( Mobile caster, Spell spell )
{
Item marker1 = caster.Backpack.FindItemByType(typeof(WineCellarMarker));
if (marker1 != null)
{
   Console.WriteLine("OnCast: {0} HasMarker: {1}.", ((PlayerMobile)caster).Name, WineCellarMarker.ExistsOn( caster ));
caster.SendLocalizedMessage( 502629 ); // You cannot cast spells here.
return false;
}
 
//********************************************************************
//if( WineCellarMarker.ExistsOn( caster ) )
//{
//caster.SendLocalizedMessage( 502629 ); // You cannot cast spells here.
//return false;
//}
//*********************************************************************
 
Okay - problem solved by using a different approach.

I added this to Mark.cs

Code:
public override void OnCast()
{
Item marker1 = Caster.Backpack.FindItemByType(typeof(WineCellarMarker));
if (marker1 != null)
{
Caster.SendLocalizedMessage( 501800 ); // You cannot mark an object at that location.
return;
}
 
Caster.Target = new InternalTarget( this );
}

I have no idea why the efforts in SpellHelper.cs were not working but a fix is a fix I guess (as long as it does not break something else). I will add this check to Recall, Gate and Teleport to complete the security of the area below the house.

Thx to Daat and Hammerhand for the help here

*bows*
 

daat99

Moderator
Staff member
This is exactly why your efforts in SpellHelper didn't work:
Code:
		public override void OnCast()
		{
			Caster.Target = new InternalTarget( this );
		}
The OnCast method of Mark.cs doesn't call the base OnCast method (in our cast SpellHelper.cs) so it doesn't run your code.

However,
Code:
		public override bool CheckCast()
		{
			if ( !base.CheckCast() )
				return false;

			return SpellHelper.CheckTravel( Caster, TravelCheckType.Mark );
		}
CheckCast from Mark.cs does call the base CheckCast method so you might want to use CheckCast method inside SpellHelper.cs in order to achieve your goal.

Just add the same code you had in OnCast to CheckCast instead and return "false" if you want to block the cast.
 
Top