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!

Need help with adding new Command ^^

P

prettz

Guest
Need help with adding new Command ^^

Heya everyone, I need some help making an "AddHair" command (as opposed to "ShaveHair"). I've done a litte scripting, but I surely know next to nothing about C# :? Here's what I have so far:

This is at the top with all of the other commands in Handlers.cs
[code:1]
Register( "AddHair", AccessLevel.GameMaster, new CommandEventHandler( AddHair_OnCommand ) );
[/code:1]

And the rest...
[code:1]
private class AddItemByLayerTarget : Target
{
private Layer m_Layer;

public AddItemByLayerTarget( Layer layer ) : base( -1, false, TargetFlags.None )
{
m_Layer = layer;
}

protected override void OnTarget( Mobile from, object targeted )
{
if ( targeted is Mobile )
{
Item item = ((Mobile)targeted).FindItemOnLayer( m_Layer );

if ( item != null )
{

item.Delete();

Item hair = new Item( Utility.RandomList( 0x203B, 0x2049, 0x2048, 0x204A ) );

hair.Hue = Utility.RandomNondyedHue();
hair.Layer = Layer.Hair;
hair.Movable = false;
hair.Newbied = true;

((Mobile)targeted).AddItem( hair );

}
}
else
{
from.SendMessage( "Target a mobile." );
}
}
}


public static void AddHair_OnCommand( CommandEventArgs e )
{
e.Mobile.Target = new AddItemByLayerTarget( Layer.Hair );
}
[/code:1]

So far it seems I can only alter hair if it is present. However, say I use "ShaveHair". After that I can no longer add hair.. any ideas? ^^ Oh and thanks for the wonderful emulator :D

Ryousuke
 

krrios

Administrator
Re: Need help with adding new Command ^^

[code:1] private class AddItemByLayerTarget : Target
{
private Layer m_Layer;

public AddItemByLayerTarget( Layer layer ) : base( -1, false, TargetFlags.None )
{
m_Layer = layer;
}

protected override void OnTarget( Mobile from, object targeted )
{
if ( targeted is Mobile )
{
Item item = ((Mobile)targeted).FindItemOnLayer( m_Layer );

if ( item != null )
item.Delete();

Item hair = new Item( Utility.RandomList( 0x203B, 0x2049, 0x2048, 0x204A ) );

hair.Hue = Utility.RandomNondyedHue();
hair.Layer = Layer.Hair;
hair.Movable = false;
hair.Newbied = true;

((Mobile)targeted).AddItem( hair );
}
else
{
from.SendMessage( "Target a mobile." );
}
}
}

public static void AddHair_OnCommand( CommandEventArgs e )
{
e.Mobile.Target = new AddItemByLayerTarget( Layer.Hair );
}[/code:1]
 
L

Lost User

Guest
Right after i rescript it so it works (looks just like yours) I go to post it and so maybe I'll look smarter.. and you beat me to it! GRR hehe :D good job though =]
 
P

prettz

Guest
oops ^^

heh oops ^^

*kicks himself for making stupid mistake!* :rolleyes:

thanks for the help :)
 
Top