Full Version : soccer
xmlspawner >>Scripting Support >>soccer
<< Prev | Next >>
ambak- 02-17-2006
this is my ball.i want to give it a range when double clicked and target a distance.how can i make it ?

CODE
using System; using Server; using Server.Mobiles; using Server.Items; using Server.Targeting;
namespace Server.MyQuests
{
// -------------------------------------------------------------------------------------------------------------------------
public class FutbolTopu : Item
{
[Constructable]
public FutbolTopu() : base( 0x2256 )
{
Movable = false;
Name = "Futbol Topu";
Weight = 5.0;
}
public override void OnDoubleClick( Mobile from )
{
from.Target = new TopTarget( this );
}
public FutbolTopu( 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();
}
public class TopTarget : Target
{
private static Item m_Item;
public TopTarget( Item item ) : base( -1, true, TargetFlags.None )
{
m_Item = item;
}
protected override void OnTarget( Mobile from, object o )
{
IPoint3D merkez = o as IPoint3D;
Point3D loc = new Point3D( merkez.X, merkez.Y, merkez.Z );
if ( !from.InRange( m_Item.GetWorldLocation(), 1 ) )
from.SendLocalizedMessage( 500446 ); // That is too far away.
else
m_Item.MoveToWorld( loc, from.Map);
}
}
}

with this one you can double click the ball and move it very far away.
Dian- 02-17-2006
First, to verify you are close enough to d-click.. (you can change distance if you need)

CODE
public override void OnDoubleClick( Mobile from ) { if( !from.InRange( this, 1 ) ) { from.SendMessage( "You are too far away to use that" );
return;
}
from.Target = new TopTarget( this );
}

I tested this out, and works great. Im sure there is a better way to do the math in a cleaner code structure..

CODE
using System; using Server; using Server.Mobiles; using Server.Items; using Server.Targeting;
namespace Server.MyQuests
{
public class FutbolTopu : Item
{
[Constructable]
public FutbolTopu() : base( 0x2256 )
{
Movable = false;
Name = "Futbol Topu";
Weight = 5.0;
}
public override void OnDoubleClick( Mobile from )
{
if( !from.InRange( this, 1 ) )
{
from.SendMessage( "You are too far away to use that" );
return;
}
else
from.Target = new TopTarget( this, from, this.Location );
}
public FutbolTopu( 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();
}
}
public class TopTarget : Target
{
private Item m_Item;
private Point3D m_TopuLoc;
private Mobile m_From;
public TopTarget( Item item, Mobile from, Point3D topuLoc ) : base( -1, true, TargetFlags.None )
{
m_Item = item;
m_TopuLoc = topuLoc;
m_From = from;
}
protected override void OnTarget( Mobile from, object o )
{
IPoint3D merkez = o as IPoint3D;
Point3D loc = new Point3D( merkez.X, merkez.Y, merkez.Z );
if ( merkez.X > m_TopuLoc.X + 5 || merkez.X < m_TopuLoc.X -5 || merkez.Y > m_TopuLoc.Y + 5 || merkez.Y < m_TopuLoc.Y - 5 )
from.SendLocalizedMessage( 500446 ); // That is too far away.
else
m_Item.MoveToWorld( loc, from.Map);
}
}
}

You might want to edit the distances on the target too.. maybe to 4, rather than 5.. and, I might add too.. this is prety fun might just use it for the Bag Ball arena I build a while back.. If you dont mind
Oh, the only other thing I am unsure of, without testing it with multiple people, Im not sure how it would handle several players d-clicking it at the same time, and trying to target a movement for the ball..