|
||
|
|||||||
| Modification Suggestions This is where you can suggest a modifcation to RunUO! |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#4 (permalink) |
|
Forum Expert
Join Date: Sep 2005
Location: UK
Age: 29
Posts: 781
|
hi there i wanted to add this my my jail system. i use. but i cant find OnEnter.
thanks for any help. Code:
#region AuthorHeader
//
// Jail version 1.5, by Xanthos
//
// Based on original code and concept by Sirens Song
// (ie, Matron de Winter) 2004 and Grim Reaper. Thanks to
// Thundar for his ideas and testing.
//
#endregion AuthorHeader
using System;
using System.IO;
using System.Text;
using Server;
using Server.Items;
using Server.Mobiles;
using Server.Targeting;
using System.Collections;
namespace Xanthos.SpeechCop
{
public class Jail
{
// Configurable options
public static AccessLevel kJailImmuneLevel = AccessLevel.Administrator;
public static bool kJailWordsEnabled = true;
public static int kRockAmount = 100;
public static string kWhatToMine = "rock"; // Change this to mine your jail tiles. Find tile name with admin command [get name
public static int kHammerDifficulty = 65; // precent chance of getting no jail rock on a mining attempt
public static Point3D JailLocation = new Point3D( 1715, 1064, 0 );
public static Point3D FreeLocation = new Point3D( 3770, 1308, 0 );
public static Map JailMap = Map.Trammel;
public static Map FreeMap = Map.Felucca;
public static string kJailRockName = "Jail Rock"; // These should not be changed
private static string kJailWordFile = "Data/jailwords.txt";
private static ArrayList m_JailWords = new ArrayList();
public static void Initialize()
{
try
{
using ( StreamReader sr = new StreamReader( kJailWordFile ) )
{
String line;
while (( line = sr.ReadLine() ) != null )
{
m_JailWords.Add( line );
}
}
}
catch ( Exception e )
{
World.Broadcast( 0, true, "Jail: error reading jail words file.");
World.Broadcast( 0, true, e.Message );
}
Server.Commands.Register( "Jail", AccessLevel.GameMaster, new CommandEventHandler( Jail_OnCommand ) );
Server.Commands.Register( "UnJail", AccessLevel.GameMaster, new CommandEventHandler( UnJail_OnCommand ) );
Server.Commands.Register( "AddJailWord", AccessLevel.GameMaster, new CommandEventHandler( AddJailWord_OnCommand ) );
Server.Commands.Register( "DeleteJailWord", AccessLevel.GameMaster, new CommandEventHandler( DeleteJailWord_OnCommand ) );
Server.Commands.Register( "ListJailWords", AccessLevel.GameMaster, new CommandEventHandler( ListJailWords_OnCommand ) );
EventSink.Speech += new SpeechEventHandler( EventSink_Speech );
}
//
// Call this from your chat system command handler to have public
// chat monitored.
// For instance, to add monitoring to Knives chat 2.0
// Search for:
// string text = Filter( e.Mobile, e.ArgString );
// and insert this line directly after it:
// Xanthos.SpeechCop.Jail.CheckChatSpeech( e.Mobile, text ); // <- Added Jail speech checking this line only
//
public static void CheckChatSpeech( Mobile mobile, string speech )
{
PlayerMobile player = mobile as PlayerMobile;
if ( kJailWordsEnabled && null != player && CheckSpeech( speech ) )
JailThem( player );
}
//
// This handler monitors local speech for use of the above words.
//
public static void EventSink_Speech( SpeechEventArgs args )
{
PlayerMobile player = args.Mobile as PlayerMobile;
if ( kJailWordsEnabled && null != player && CheckSpeech( args.Speech ) )
JailThem( player );
}
[Usage( "Jail" )]
[Description( "Jails a targeted Player." )]
private static void Jail_OnCommand( CommandEventArgs e )
{
e.Mobile.Target = new JailTarget();
e.Mobile.SendMessage( "Whom do you wish to Jail?" );
}
[Usage( "UnJail" )]
[Description( "UnJails a targeted Player." )]
private static void UnJail_OnCommand( CommandEventArgs e )
{
e.Mobile.Target = new UnJailTarget();
e.Mobile.SendMessage( "Whom do you wish to release from jail?" );
}
[Usage( "AddJailWord" )]
[Description( "Adds a word to the bad words list." )]
private static void AddJailWord_OnCommand( CommandEventArgs e )
{
string[] args = e.Arguments;
if ( args.Length > 0 )
{
m_JailWords.Add( args[ 0 ] );
WriteJailWordsList( e.Mobile );
}
}
[Usage( "DeleteJailWord" )]
[Description( "Deletes a word from the bad words list." )]
private static void DeleteJailWord_OnCommand( CommandEventArgs e )
{
string[] args = e.Arguments;
if ( args.Length > 0 )
{
m_JailWords.Remove( args[ 0 ] );
WriteJailWordsList( e.Mobile );
}
}
[Usage( "ListJailWords" )]
[Description( "Displays the bad words list." )]
private static void ListJailWords_OnCommand( CommandEventArgs e )
{
for ( int i = 0; i < m_JailWords.Count; i++ )
e.Mobile.SendMessage( ((string)m_JailWords[ i ]) );
}
private static void WriteJailWordsList( Mobile from )
{
try
{
using ( StreamWriter sw = new StreamWriter( kJailWordFile ) )
{
for ( int i = 0; i < m_JailWords.Count; i++ )
sw.WriteLine( ((string)m_JailWords[ i ]) );
}
from.SendMessage( "Jail word list written to disk." );
}
catch ( Exception e )
{
from.SendMessage( "Exception raised writing bad words file" );
from.SendMessage( e.Message );
}
}
private static bool CheckSpeech( string speech )
{
ArrayList saidWords = toarray( Mytolower( speech ));
foreach ( string bad in m_JailWords )
{
foreach ( string said in saidWords )
{
if ( said == bad )
return true;
}
}
return false;
}
private class JailTarget : Target
{
public JailTarget() : base( -1, true, TargetFlags.None ) {}
protected override void OnTarget( Mobile from, object targ )
{
PlayerMobile player = targ as PlayerMobile;
if ( null == player )
from.SendMessage( "You can only Jail Players." );
else
JailThem ( player );
}
}
public static void JailThem( PlayerMobile player )
{
if ( null == player || player.AccessLevel >= kJailImmuneLevel )
return;
foreach ( Item item in player.Items )
{
if ( item is JailHammer ) // Jailed while jailed gets them another load of rock to mine
{
if ( 0 > ( ((JailHammer)item).RockAmount += Jail.kRockAmount ) ) // handle integer overflow
((JailHammer)item).RockAmount *= -1;
player.SendMessage( "Your remaining sentence has been increased - get back to work!" );
player.MoveToWorld( JailLocation, JailMap );
return;
}
}
// If mounted, dismount them and stable mount
if ( player.Mounted )
{
if ( player.Mount is EtherealMount )
{
EtherealMount pet = player.Mount as EtherealMount;
pet.Internalize();
pet.Rider = null;
}
else if ( player.Mount is BaseMount )
{
BaseMount pet = player.Mount as BaseMount;
pet.Rider = null;
Jail.StablePet( player, pet );
}
}
// Stable all other pets
foreach ( Mobile mobile in World.Mobiles.Values )
{
if ( mobile is BaseCreature )
{
BaseCreature bc = mobile as BaseCreature;
if ( null != bc && (bc.Controled && bc.ControlMaster == player) || (bc.Summoned && bc.SummonMaster == player) )
Jail.StablePet( player, bc );
}
}
// Move all items to a bag and move that to the bank
Container backpack = player.Backpack;
Backpack bag = new Backpack(); bag.Hue = 2665;
ArrayList equipedItems = new ArrayList( player.Items );
foreach ( Item item in equipedItems )
{
if ( item.Layer == Layer.Bank || item.Layer == Layer.Backpack || item.Layer == Layer.Hair || item.Layer == Layer.FacialHair || item is DeathShroud )
continue;
bag.DropItem( item );
}
ArrayList backpackItems = new ArrayList( backpack.Items );
foreach ( Item item in backpackItems )
{
if ( item is JailRock )
item.Delete();
else if ( item.Movable ) // Non movable pack items must remain (i.e. skill balls)
bag.DropItem( item );
}
// Remember their access level and make them a player
JailHammer hammer = new JailHammer();
hammer.PlayerAccessLevel = player.AccessLevel;
player.AccessLevel = AccessLevel.Player;
// Bank the bag of belongings, give them a hammer and welcome them
player.BankBox.DropItem( bag );
player.AddItem( hammer );
player.MoveToWorld( JailLocation, JailMap );
Item robe = new Robe(); robe.Hue = 2665;
player.AddItem( robe );
player.SendMessage( "You have been JAILED!" );
}
public static void StablePet( PlayerMobile player, BaseCreature pet )
{
if ( null == player || null == pet )
return;
pet.Internalize();
pet.ControlTarget = null;
pet.ControlOrder = OrderType.Stay;
pet.SetControlMaster( null );
pet.SummonMaster = null;
pet.IsStabled = true;
player.Stabled.Add( pet );
player.SendMessage( "Your pet has been stabled" );
}
private class UnJailTarget : Target
{
public UnJailTarget() : base( -1, true, TargetFlags.None ) {}
protected override void OnTarget( Mobile from, object targ )
{
PlayerMobile player = targ as PlayerMobile;
if ( null == player )
from.SendMessage( "You may only unjail players." );
else
{
from.SendMessage( "You free the player." );
FreeThem( player );
}
}
}
public static void FreeThem( PlayerMobile player )
{
if ( null == player )
return;
// Take away any JailRock
// No need to recurse containers since all their items were removed when jailed
RemoveRockFromList( new ArrayList( player.Items ) );
RemoveRockFromList( new ArrayList( player.Backpack.Items ) );
// Restore their access level
JailHammer hammer = player.FindItemOnLayer( Layer.OneHanded ) as JailHammer;
if ( null != hammer )
{
player.AccessLevel = hammer.PlayerAccessLevel;
hammer.Delete();
}
player.MoveToWorld( FreeLocation, FreeMap );
player.SendMessage( "You have been released from Jail!" );
}
private static void RemoveRockFromList( ArrayList list )
{
if ( null == list )
return;
foreach ( Item item in list )
{
if ( item is JailRock ) // Be sure no jail rock leaves the jail.
item.Delete();
}
}
private static string Mytolower( string str )
{
string s1 = "";
int strlen = str.Length;
for ( int i = 0; i < strlen; i++ )
{
char ch = str[i];
if (ch >= 'A' && ch <= 'Z')
{
int ucode = (int)ch;
ucode += 32;
s1 += (char)ucode;
}
else
{
s1 += ch;
}
}
return s1;
}
private static ArrayList toarray( string str )
{
ArrayList retarray = new ArrayList();
string s1 = "";
int strlen = str.Length;
for ( int i = 0; i < strlen; i++ )
{
char ch = str[i];
if (ch >= 'a' && ch <= 'z')
{
s1 += ch;
}
else
{
if ( s1 != "" )
{
retarray.Add( s1 );
s1 = "";
}
}
}
if ( s1 != "" )
retarray.Add( s1 );
return retarray;
}
}
}
__________________
*+ MW Admin Naturescorpse +* |
|
|
|
|
|
#5 (permalink) |
|
Forum Expert
Join Date: Dec 2005
Posts: 537
|
What you have there is the script to jail someone not the jail region, which he/she ment.
Anyhow you can just put the piece of code under the following method: public static void JailThem( PlayerMobile player ) find the following part: Code:
Item robe = new Robe(); robe.Hue = 2665; player.AddItem( robe ); player.SendMessage( "You have been JAILED!" ); Code:
foreach ( Mobile m in World.Mobiles.Values )
{
if ( m.AccessLevel >= AccessLevel.GameMaster )
m.SendMessage( "Player \"{0}\" has entered jail.", player.Name );
}
}
Code:
Item robe = new Robe(); robe.Hue = 2665;
player.AddItem( robe );
player.SendMessage( "You have been JAILED!" );
foreach ( Mobile m in World.Mobiles.Values )
{
if ( m.AccessLevel >= AccessLevel.GameMaster )
m.SendMessage( "Player \"{0}\" has entered jail.", player.Name );
}
}
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|