Full Version : Guns
xmlspawner >>Scripting Support >>Guns
<< Prev | Next >>
olsyke- 06-28-2006
okay now after i had finished the guns i started on those vehicle and nearly can already come up with a speederbike from starwars!
my only problems are that i have no idea on how to let the players look "mounted" during the flights and have them not be hidden/frozen
maybe you got an idea bout that

CODE
/////////////////////////////// // Alambik vehicle // /////////////////////////////// // Enjoy next UO generation // // Enjoy Cyber-Shards... //
///////////////////////////////
using System;
using Server;
using Server.Mobiles;
using Server.Gumps;
using Server.Network;
namespace Server.Items
{
public class Vehicle: Item, ILockable
{
//////////////////////////
// SCRIPT CONFIGURATION //
// UseFrench: if set to true, messages are sent in french else in english
static private bool UseFrench = false;
// TimerDelay: set the lowest speed (speed = 1) interval, in seconds.
static public double LowestSpeed = 0.5;
//////////////////////////
public enum EngineStatusType
{
Stopped = 0,
Stopping = 1,
Forward = 2,
Backward = 3,
Flying = 4,
Landing = 5
}
private InternalTimer m_TimerInterval;
private bool m_AlternateFlag;
private VehicleShadow m_Shadow;
public VehicleShadow Shadow
{ get{ return m_Shadow; } set{ m_Shadow = value; } }
private bool m_DebugMessages;
[CommandProperty( AccessLevel.GameMaster )]
public bool DebugMessages
{ get{ return m_DebugMessages; } set{ m_DebugMessages = value; } }
private bool m_InvisibleMobile;
[CommandProperty( AccessLevel.GameMaster )]
public bool InvisibleMobile
{ get{ return m_InvisibleMobile; } set{ m_InvisibleMobile = value; } }
private int m_NorthItemID;
[CommandProperty( AccessLevel.GameMaster )]
public int NorthItemID
{ get{ return m_NorthItemID; } set{ m_NorthItemID = value; } }
private int m_AlternativeItemID;
[CommandProperty( AccessLevel.GameMaster )]
public int AlternativeItemID
{ get{ return m_AlternativeItemID; } set{ m_AlternativeItemID= value; } }
private int m_EngineSound;
[CommandProperty( AccessLevel.GameMaster )]
public int EngineSound
{ get{ return m_EngineSound; } set{ m_EngineSound= value; } }
private int m_StartSound;
[CommandProperty( AccessLevel.GameMaster )]
public int StartSound
{ get{ return m_StartSound; } set{ m_StartSound= value; } }
private int m_StopSound;
[CommandProperty( AccessLevel.GameMaster )]
public int StopSound
{ get{ return m_StopSound; } set{ m_StopSound= value; } }
private int m_DiagonalOffset;
[CommandProperty( AccessLevel.GameMaster )]
public int DiagonalOffset
{ get{ return m_DiagonalOffset; } set{ m_DiagonalOffset= value; } }
private int m_MaxSpeed;
[CommandProperty( AccessLevel.GameMaster )]
public int MaxSpeed
{ get{ return m_MaxSpeed; } set{ m_MaxSpeed= value; } }
private int m_Speed;
[CommandProperty( AccessLevel.GameMaster )]
public int Speed
{ get{ return m_Speed; } set{ m_Speed= value; } }
private EngineStatusType m_EngineStatus;
[CommandProperty( AccessLevel.GameMaster )]
public EngineStatusType EngineStatus
{ get{ return m_EngineStatus; } set{ m_EngineStatus= value; } }
private int m_MaxResistance;
[CommandProperty( AccessLevel.GameMaster )]
public int MaxResistance
{ get{ return m_MaxResistance; } set{ m_MaxResistance= value; } }
private int m_Resistance;
[CommandProperty( AccessLevel.GameMaster )]
public int Resistance
{ get{ return m_Resistance; } set{ m_Resistance= value; } }
private int m_Fuel;
[CommandProperty( AccessLevel.GameMaster )]
public int Fuel
{ get{ return m_Fuel; } set{ m_Fuel= value; } }
private int m_MaxFuel;
[CommandProperty( AccessLevel.GameMaster )]
public int MaxFuel
{ get{ return m_MaxFuel; } set{ m_MaxFuel= value; } }
private int m_FlyAltitude;
[CommandProperty( AccessLevel.GameMaster )]
public int FlyAltitude
{ get{ return m_FlyAltitude; } set{ m_FlyAltitude= value; } }
private int m_MaxSlope;
[CommandProperty( AccessLevel.GameMaster )]
public int MaxSlope
{ get{ return m_MaxSlope; } set{ m_MaxSlope= value; } }
private bool m_IsInUse;
[CommandProperty( AccessLevel.GameMaster )]
public bool IsInUse
{ get{ return m_IsInUse; } set{ m_IsInUse= value; } }
private bool m_CanFly;
[CommandProperty( AccessLevel.GameMaster )]
public bool CanFly
{ get{ return m_CanFly; } set{ m_CanFly= value; } }
private bool m_EarthAllowed;
[CommandProperty( AccessLevel.GameMaster )]
public bool EarthAllowed
{ get{ return m_EarthAllowed; } set{ m_EarthAllowed= value; } }
private bool m_WaterAllowed;
[CommandProperty( AccessLevel.GameMaster )]
public bool WaterAllowed
{ get{ return m_WaterAllowed; } set{ m_WaterAllowed= value; } }
private bool m_MontainAllowed;
[CommandProperty( AccessLevel.GameMaster )]
public bool MountainAllowed
{ get{ return m_MontainAllowed; } set{ m_MontainAllowed= value; } }
private bool m_StarsAllowed;
[CommandProperty( AccessLevel.GameMaster )]
public bool StarsAllowed
{ get{ return m_StarsAllowed; } set{ m_StarsAllowed= value; } }
private Mobile m_Rider;
[CommandProperty( AccessLevel.GameMaster )]
public Mobile Rider
{ get{ return m_Rider; } set{ m_Rider= value; } }
private int m_Size;
[CommandProperty( AccessLevel.GameMaster )]
public int Size
{ get{ return m_Size; } set{ m_Size= value; } }
private bool m_Locked;
[CommandProperty( AccessLevel.GameMaster )]
public bool Locked
{ get{ return m_Locked; } set{ m_Locked = value; } }
private uint m_KeyValue;
[CommandProperty( AccessLevel.GameMaster )]
public uint KeyValue
{ get { return m_KeyValue; } set { m_KeyValue = value; } }
public Vehicle( int aNorthItemID ) : base( aNorthItemID )
{
NorthItemID = aNorthItemID;
Direction = Direction.North;
Movable = false;
Weight = 10000;
MaxFuel = 2000;
Fuel = MaxFuel;
Size = 1;
MaxSpeed = 1;
Speed = 0;
EngineStatus = EngineStatusType.Stopped;
IsInUse = false;
CanFly = false;
FlyAltitude = 100;
WaterAllowed = false;
MountainAllowed = false;
WaterAllowed = false;
StarsAllowed = false;
MaxResistance = 100;
Resistance = MaxResistance;
IsInUse = false;
InvisibleMobile= true;
}
public Vehicle( Serial serial ) : base( serial )
{
}
public override void OnDelete()
{
if (Shadow != null)
if (!Shadow.Deleted)
Shadow.Delete();
base.OnDelete();
}
/////////////////// INTERACT MANAGER ///////////////////
public override void OnDoubleClick( Mobile mobile )
{
if (!(mobile is PlayerMobile))
return;
PlayerMobile m = (PlayerMobile)mobile;
if ( m_IsInUse)
{
if (mobile == m_Rider)
{
if (m_EngineStatus != EngineStatusType.Stopped)
{
if (UseFrench)
m.SendMessage("Vous devez vous arrêter pour descendre.");
else
m.SendMessage("You must stop the vehicle to exit it.");
m.CloseGump(typeof(InternalGump));
m.SendGump(new InternalGump(this));
}
else
{
if (UseFrench)
m.SendMessage("Vous descendez du véhicule.");
else
m.SendMessage("You exit the vehicle.");
m.CloseGump(typeof(InternalGump));
m_IsInUse=false;
m.Frozen=false;
if (m.Alive)
m.Hidden=false;
}
}
else
{
if (UseFrench)
m.SendMessage("Il y a déjà quelqu'un au commandes.");
else
m.SendMessage("There's already somebody in it.");
}
}
else
{
if ( (!m.Frozen ) &&
(!m.Mounted) &&
(!m.Deleted) &&
( m.Alive ) )
{
if (Locked)
{
if (UseFrench)
m.SendMessage("Ce véhicule est fermé à clé.");
else
m.SendMessage("This vehicle is locked.");
return;
}
m_Rider=m;
m_IsInUse=true;
if (UseFrench)
m.SendMessage("Vous prenez les commandes du vehicule.");
else
m.SendMessage("You jump into the vehicle.");
m.Frozen=true;
if (m_InvisibleMobile)
m.Hidden=true;
m_Rider.MoveToWorld(new Point3D(X-DiagonalOffset,Y-DiagonalOffset,Z),Map);
m.SendGump(new InternalGump(this));
UpdateItemID();
}
}
}
/////////////////// COMMANDS MANAGER ///////////////////
public void TurnRight()
{
if ( !CheckEngine() )
return;
if (Direction == Direction.Up)
Direction=Direction.North;
else
Direction++;
UpdateItemID();
if (DebugMessages) m_Rider.SendMessage("RIGHT!");
}
public void TurnLeft()
{
if ( !CheckEngine() )
return;
if (Direction == Direction.North)
Direction=Direction.Up;
else
Direction--;
UpdateItemID();
if (DebugMessages) m_Rider.SendMessage("LEFT!");
}
public void Up()
{
if (!CanFly)
return;
if ( !CheckEngine() )
return;
if ( Z >= FlyAltitude )
return;
if (DebugMessages) m_Rider.SendMessage("Check Engine status...");
switch ( EngineStatus )
{
case EngineStatusType.Stopped: break; // YES
case EngineStatusType.Stopping: return; // NO
case EngineStatusType.Forward: return; // NO
case EngineStatusType.Backward: return; // NO
case EngineStatusType.Flying: return; // NO
case EngineStatusType.Landing: break; // YES
default: return; // NO
}
if (DebugMessages) m_Rider.SendMessage("Engine status OK");
if (EngineStatus == EngineStatusType.Stopped)
if (StartSound != 0)
Effects.PlaySound( Location, Map, StartSound);
Speed=0;
EngineStatus = EngineStatusType.Flying;
StartTimer();
if (DebugMessages) m_Rider.SendMessage("UP!");
}
public void Down()
{
if (!CanFly)
return;
if ( !CheckEngine() )
return;
if (DebugMessages) m_Rider.SendMessage("Check Engine status...");
switch ( EngineStatus )
{
case EngineStatusType.Stopped: return; // NO
case EngineStatusType.Stopping: return; // NO
case EngineStatusType.Forward: return; // NO
case EngineStatusType.Backward: return; // NO
case EngineStatusType.Flying: break; // YES
case EngineStatusType.Landing: return; // NO
default: return; // NO
}
if (DebugMessages) m_Rider.SendMessage("Engine status OK");
Speed=0;
EngineStatus = EngineStatusType.Landing;
StartTimer();
if (DebugMessages) m_Rider.SendMessage("DOWN!");
}
public void Forward()
{
if ( !CheckEngine() )
return;
if ( CanFly && (Z < FlyAltitude) )
return;
if (DebugMessages) m_Rider.SendMessage("Check Engine status...");
switch ( EngineStatus )
{
case EngineStatusType.Stopped: break; // YES
case EngineStatusType.Stopping: break; // YES
case EngineStatusType.Forward: break; // YES
case EngineStatusType.Backward: return; // NO
case EngineStatusType.Flying: break; // YES
case EngineStatusType.Landing: return; // NO
default: return; // NO
}
if (DebugMessages) m_Rider.SendMessage("Engine status OK");
if (EngineStatus == EngineStatusType.Stopped)
if (StartSound != 0)
Effects.PlaySound( m_Rider.Location, m_Rider.Map, StartSound);
if ( Speed < MaxSpeed )
Speed++;
EngineStatus = EngineStatusType.Forward;
StartTimer();
if (DebugMessages) m_Rider.SendMessage("FORWARD!");
}
public void Backward()
{
if ( !CheckEngine() )
return;
if ( CanFly && (Z < FlyAltitude) )
return;
if (DebugMessages) m_Rider.SendMessage("Check Engine status...");
switch ( EngineStatus )
{
case EngineStatusType.Stopped: break; // YES
case EngineStatusType.Stopping: return; // NO
case EngineStatusType.Forward: return; // NO
case EngineStatusType.Backward: return; // NO
case EngineStatusType.Flying: break; // YES
case EngineStatusType.Landing: return; // NO
default: return; // NO
}
if (DebugMessages) m_Rider.SendMessage("Engine status OK");
if (EngineStatus == EngineStatusType.Stopped)
if (StartSound != 0)
Effects.PlaySound( m_Rider.Location, m_Rider.Map, StartSound);
Speed=1;
EngineStatus = EngineStatusType.Backward;
StartTimer();
if (DebugMessages) m_Rider.SendMessage("BACKWARD!");
}
public void Stop()
{
if (DebugMessages) m_Rider.SendMessage("Check Engine status...");
switch ( EngineStatus )
{
case EngineStatusType.Stopped: return; // NO
case EngineStatusType.Stopping: return; // NO
case EngineStatusType.Forward: break; // YES
case EngineStatusType.Backward: break; // YES
case EngineStatusType.Flying: return; // NO
case EngineStatusType.Landing: return; // NO
default: return; // NO
}
if (DebugMessages) m_Rider.SendMessage("Engine status OK");
EngineStatus = EngineStatusType.Stopping;
StartTimer();
if (DebugMessages) m_Rider.SendMessage("STOP!");
}
public void F1()
{}
public void F2()
{}
public void F3()
{}
public void F4()
{}
/////////////////// ACTIONS MANAGER ///////////////////
public void StopImmediatly()
{
if ( CanFly && (Z >= FlyAltitude) )
{
EngineStatus = EngineStatusType.Flying;
} else {
EngineStatus = EngineStatusType.Stopped;
if (StopSound != 0)
Effects.PlaySound( m_Rider.Location, m_Rider.Map, StopSound);
StopTimer();
}
Speed=0;
}
public void Fly()
{
if(!CanFly)
return;
if (EngineStatus != EngineStatusType.Landing)
if ( ((Fuel <= 0) && (MaxFuel > 0)) || (Resistance <= 0))
{
EngineStatus=EngineStatusType.Landing;
UpdateGump();
return;
}
int xx=X;
int yy=Y;
int zz=Z;
if (( Z >= FlyAltitude ) && (EngineStatus == EngineStatusType.Flying))
return;
if (EngineStatus == EngineStatusType.Landing)
zz--;
else
zz++;
int maxz=0;
if ( CanFit(xx,yy,zz,ref maxz) )
{
MoveTo(xx,yy,zz);
}
else
{
StopImmediatly();
if (StopSound != 0)
Effects.PlaySound( m_Rider.Location, m_Rider.Map, StopSound);
}
}
public void MoveNow()
{
if (((Fuel <= 0) && (MaxFuel > 0))|| (Resistance <= 0))
{
if (CanFly)
EngineStatus=EngineStatusType.Landing;
else
EngineStatus=EngineStatusType.Stopping;
UpdateGump();
return;
}
if (MaxFuel > 0)
Fuel--;
int xx=X;
int yy=Y;
int movement;
if (EngineStatus == EngineStatusType.Backward)
movement=-1;
else
movement=1;
switch (Direction)
{
case Direction.North:
yy-=movement;
break;
case Direction.Right:
yy-=movement;
xx+=movement;
break;
case Direction.East:
xx+=movement;
break;
case Direction.Down:
yy+=movement;
xx+=movement;
break;
case Direction.South:
yy+=movement;
break;
case Direction.Left:
yy+=movement;
xx-=movement;
break;
case Direction.West:
xx-=movement;
break;
case Direction.Up:
xx-=movement;
yy-=movement;
break;
}
int zz=Z;
int maxz=0;
if (CanFit(xx,yy,zz,ref maxz))
{
if (CanFly)
MoveTo(xx,yy,zz);
else
MoveTo(xx,yy,maxz);
if (Shadow != null)
if (!Shadow.Deleted)
Shadow.MoveToWorld(
new Point3D(xx-DiagonalOffset,yy-DiagonalOffset,maxz),
m_Rider.Map);
} else {
if (Resistance>0)
Resistance--;
if (UseFrench)
m_Rider.SendMessage("Attention, vous avez heurté quelquechose!");
else
m_Rider.SendMessage("Be careful, you hurt something!");
Effects.PlaySound( m_Rider.Location, m_Rider.Map, 286);
StopImmediatly();
}
}
public void MoveTo(int x,int y,int z)
{
MoveToWorld(new Point3D(x,y,z),Map);
m_Rider.MoveToWorld(new Point3D(x-DiagonalOffset,y-DiagonalOffset,z),Map);
}
public void UpdateItemID()
{
if (m_AlternativeItemID == 0)
{
ItemID=m_NorthItemID+(int)Direction;
} else {
if (m_AlternateFlag)
ItemID=m_NorthItemID+(int)Direction;
else
ItemID=m_AlternativeItemID+(int)Direction;
if (m_EngineStatus != EngineStatusType.Stopped)
m_AlternateFlag=!m_AlternateFlag;
}
if (m_IsInUse)
if (m_Rider != null)
m_Rider.Direction=Direction;
}
/////////////////// CHECKS MANAGER ///////////////////
public bool CheckEngine()
{
if (DebugMessages) m_Rider.SendMessage("Checking Engine...");
if (m_Rider == null)
return false;
if ( (m_Resistance <= 0) && (m_MaxResistance > 0) )
{
if (UseFrench)
m_Rider.SendMessage("Le vehicule est endommagé.");
else
m_Rider.SendMessage("This vehicle is broken.");
return false;
}
if ( (m_Fuel <= 0) && (m_MaxFuel > 0) )
{
if (UseFrench)
m_Rider.SendMessage("Il n'y a plus de carburant...");
else
m_Rider.SendMessage("No fuel anymore...");
if (EngineStatus == EngineStatusType.Stopped)
if (StartSound != 0)
Effects.PlaySound( m_Rider.Location, m_Rider.Map, 1470);
return false;
}
if (DebugMessages) m_Rider.SendMessage("Engine OK");
return true;
}
public bool CanFit(int x,int y,int zz,ref int maxz)
{
int xx=x-DiagonalOffset;
int yy=y-DiagonalOffset;
maxz=-125;
///////////////////////////////////////////////////
// Check all land tiles, statified objects, dynamic items
for (int a=xx-Size;a<=xx+Size;a++)
for (int b=yy-Size;b<=yy+Size;b++)
{
bool topIsLandTile=true;
// 1) land tile
Tile landTile = Map.Tiles.GetLandTile( a, b );
// Compute max Z according to left/right/bottom/top tiles
int landZ = 0;
int landAvg = 0;
int landTop = 0;
Map.GetAverageZ( a, b, ref landZ, ref landAvg, ref landTop );
if (landTop>maxz)
maxz = landTop;
int localMaxZ=landTop;
// 1) statified objects (can be land, items...)
int topItemID=0;
Tile[] tiles = Map.Tiles.GetStaticTiles( a, b, true );
for ( int i = 0; i < tiles.Length; ++i )
{
Tile tile = tiles[i];
ItemData tileItemData = TileData.ItemTable[tile.ID & 0x3FFF];
int tileTop = tile.Z+tileItemData.CalcHeight;
// For non-flying vehicle, impossible to move over any not background
// impassable item if higher than the tand tile average.
if (!CanFly)
if ( /*((tileItemData.Flags & TileFlag.Background) == 0) &&*/
(tileItemData.Impassable) &&
(tileItemData.CalcHeight > 0))
if (( tileTop > landAvg) && (tileTop > Z) )
return false;
if (tileTop > maxz)
maxz = tileTop;
if (tileTop > localMaxZ)
{
localMaxZ = tileTop;
topIsLandTile = false;
topItemID = tile.ID;
}
}
// 1) dynamical items
IPooledEnumerable eable = Map.GetItemsInBounds(
new Rectangle2D( a, b, 1, 1 ) );
foreach ( Item item in eable )
{
if (!( (item is VehicleShadow) || (item is Corpse) || (item == this)))
if ( item.ItemID != 0x1CD9 ) //Shadow (blood)
if (item.Visible)
{
ItemData itemItemData = TileData.ItemTable[item.ItemID & 0x3FFF];
int tileTop = item.Z+itemItemData.CalcHeight;
// For non-flying vehicle, impossible to move over any not background
// impassable item if higher than the tand tile average.
if (!CanFly)
if ( /*((itemItemData.Flags & TileFlag.Background) == 0) &&*/
(itemItemData.Impassable) &&
(itemItemData.CalcHeight > 0) )
if ( (tileTop > landAvg) && (tileTop > Z) )
return false;
if (tileTop > maxz)
maxz = tileTop;
if (tileTop > localMaxZ)
{
localMaxZ = tileTop;
topIsLandTile = false;
topItemID = item.ItemID;
}
}
}
eable.Free();
// Check ID if allowed
if (topIsLandTile)
{
if ( !verifyLandTileID(landTile.ID) )
return false;
} else {
if ( !verifyItemID(topItemID) )
return false;
}
}
if (DebugMessages) m_Rider.SendMessage("Next Max Z={0}",maxz);
if (CanFly)
return ( zz >= maxz );
else
return ( zz+m_MaxSlope >= maxz);
}
bool verifyLandTileID(int id)
{
// See InsideUO, "Artwork"->"Landscapes Tiles" for more informations
if (DebugMessages) m_Rider.SendMessage("LandTile ID:{0}",id);
////////////////////
// STARS
if ((id >= 506) && (id <= 511))
return m_StarsAllowed;
if (id == 430)
return m_StarsAllowed;
////////////////////
// WATER
if ((id >= 168) && (id <= 171))
return m_WaterAllowed;
if ((id >= 310) && (id <= 311))
return m_WaterAllowed;
////////////////////
// MOUNTAIN
if ((id >= 543) && (id <= 560))
return m_MontainAllowed;
if ((id >= 1754) && (id <= 1757))
return m_MontainAllowed;
if ((id >= 1771) && (id <= 1790))
return m_MontainAllowed;
if ((id >= 1821) && (id <= 1824))
return m_MontainAllowed;
if ((id >= 1851) && (id <= 1854))
return m_MontainAllowed;
if ((id >= 1881) && (id <= 1884))
return m_MontainAllowed;
if ((id >= 2001) && (id <= 2004))
return m_MontainAllowed;
////////////////////
// EARTH
return m_EarthAllowed;
}
bool verifyItemID(int id)
{
// See InsideUO, "Artwork"->"Static Tiles" for more informations
if (DebugMessages) m_Rider.SendMessage("Item ID:{0}",id);
////////////////////
// STARS
if ((id >= 8511) && (id <= 8516))
return m_StarsAllowed;
////////////////////
// WATER
if ((id >= 6939) && (id <= 6066))
return m_WaterAllowed;
if ((id >= 13422) && (id <= 13445))
return m_WaterAllowed;
if ((id >= 13456) && (id <= 13483))
return m_WaterAllowed;
if ((id >= 13493) && (id <= 13525))
return m_WaterAllowed;
if ((id >= 13603) && (id <= 13616))
return m_WaterAllowed;
////////////////////
// MOUNTAIN
if ((id >= 4846) && (id <= 4941))
return m_MontainAllowed;
if (id == 4974)
return m_MontainAllowed;
if (id == 4990)
return m_MontainAllowed;
if (id == 4992)
return m_MontainAllowed;
if (id == 4994)
return m_MontainAllowed;
if ((id >= 6681) && (id <= 6782))
return m_MontainAllowed;
if ((id >= 11070) && (id <= 11109))
return m_MontainAllowed;
if ((id >= 12950) && (id <= 12953))
return m_MontainAllowed;
if ((id >= 13121) && (id <= 13137))
return m_MontainAllowed;
if ((id >= 13371) && (id <= 13420))
return m_MontainAllowed;
if ((id >= 13639) && (id <= 13644))
return m_MontainAllowed;
////////////////////
// EARTH
return m_EarthAllowed;
}
/////////////////// SAVE & LOAD MANAGER ///////////////////
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 1 ); // version
writer.Write(m_InvisibleMobile);
writer.Write(m_NorthItemID);
writer.Write(m_AlternativeItemID);
writer.Write(m_EngineSound);
writer.Write(m_StartSound);
writer.Write(m_StopSound);
writer.Write(m_DiagonalOffset);
writer.Write(m_MaxSpeed);
writer.Write(m_Speed);
writer.Write((int)m_EngineStatus);
writer.Write(m_MaxResistance);
writer.Write(m_Resistance);
writer.Write(m_Fuel);
writer.Write(m_MaxFuel);
writer.Write(m_FlyAltitude);
writer.Write(m_IsInUse);
writer.Write(m_MaxSlope);
writer.Write(m_CanFly);
writer.Write(m_EarthAllowed);
writer.Write(m_WaterAllowed);
writer.Write(m_MontainAllowed);
writer.Write(m_StarsAllowed);
writer.Write(m_Rider);
writer.Write(m_Size);
writer.Write(m_Shadow);
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
switch(version)
{
case 1:
m_InvisibleMobile = reader.ReadBool();
goto case 0;
case 0:
m_NorthItemID = reader.ReadInt();
m_AlternativeItemID = reader.ReadInt();
m_EngineSound = reader.ReadInt();
m_StartSound = reader.ReadInt();
m_StopSound = reader.ReadInt();
m_DiagonalOffset = reader.ReadInt();
m_MaxSpeed = reader.ReadInt();
m_Speed = reader.ReadInt();
m_EngineStatus = (EngineStatusType)reader.ReadInt();
m_MaxResistance = reader.ReadInt();
m_Resistance = reader.ReadInt();
m_Fuel = reader.ReadInt();
m_MaxFuel = reader.ReadInt();
m_FlyAltitude = reader.ReadInt();
m_IsInUse = reader.ReadBool();
m_MaxSlope = reader.ReadInt();
m_CanFly = reader.ReadBool();
m_EarthAllowed = reader.ReadBool();
m_WaterAllowed = reader.ReadBool();
m_MontainAllowed = reader.ReadBool();
m_StarsAllowed = reader.ReadBool();
m_Rider = reader.ReadMobile();
m_Size = reader.ReadInt();
m_Shadow = (VehicleShadow)reader.ReadItem();
break;
default:
break;
}
if (m_IsInUse)
if (m_Rider != null)
m_Rider.Frozen=true;
if ( EngineStatus != EngineStatusType.Stopped)
m_TimerInterval.Start();
}
/////////////////// TIMER MANAGER ///////////////////
public void StartTimer()
{
if (MaxSpeed == 0)
return;
if (m_TimerInterval == null)
m_TimerInterval = new InternalTimer( this );
if (!m_TimerInterval.Running)
m_TimerInterval.Start();
}
public void StopTimer()
{
if (m_TimerInterval == null)
return;
if (m_TimerInterval.Running)
m_TimerInterval.Stop();
UpdateGump();
if (StopSound != 0)
Effects.PlaySound( Location, Map, StopSound);
}
public override void OnAfterDelete()
{
if ( m_TimerInterval != null )
m_TimerInterval.Stop();
}
private class InternalTimer : Timer
{
private Vehicle m_Vehicle;
private int m_Speed;
public InternalTimer( Vehicle vehicle )
: base( TimeSpan.FromSeconds(0.0),
TimeSpan.FromSeconds(Vehicle.LowestSpeed/vehicle.MaxSpeed),
0 )
{
m_Vehicle = vehicle;
Priority = TimerPriority.FiftyMS;
m_Speed=0;
}
protected override void OnTick()
{
switch ( m_Vehicle.EngineStatus )
{
case EngineStatusType.Stopped:
m_Vehicle.StopTimer();
break;
case EngineStatusType.Stopping:
if (m_Vehicle.Speed > 0)
m_Vehicle.Speed--;
if (m_Vehicle.Speed == 0)
m_Vehicle.StopImmediatly();
else
m_Vehicle.MoveNow();
break;
case EngineStatusType.Forward:
goto case EngineStatusType.Backward;
case EngineStatusType.Backward:
if (m_Speed < (m_Vehicle.MaxSpeed - m_Vehicle.Speed))
{
m_Speed++;
}
else
{
m_Vehicle.MoveNow();
m_Speed=0;
}
if (!m_Vehicle.Rider.Alive)
m_Vehicle.Stop();
break;
case EngineStatusType.Flying:
if (!m_Vehicle.Rider.Alive)
m_Vehicle.Down();
if (m_Speed < m_Vehicle.MaxSpeed)
m_Speed++;
else
m_Vehicle.Fuel--;
goto case EngineStatusType.Landing;
case EngineStatusType.Landing:
m_Vehicle.Fly();
break;
default:
break;
}
if (m_Vehicle.EngineSound != 0)
Effects.PlaySound( m_Vehicle.Rider.Location,
m_Vehicle.Rider.Map,
m_Vehicle.EngineSound);
if (m_Vehicle.AlternativeItemID > 0)
m_Vehicle.UpdateItemID();
}
}
/////////////////// GUMP MANAGER /////////////////
public void UpdateGump()
{
if (!m_IsInUse)
return;
if (m_Rider == null)
return;
m_Rider.CloseGump(typeof(InternalGump));
m_Rider.SendGump(new InternalGump(this));
}
public class InternalGump : Gump
{
private Vehicle m_Vehicle;
public InternalGump(Vehicle vehicle)
: base( 0, 0 )
{
m_Vehicle=vehicle;
this.Closable=false;
this.Disposable=false;
this.Dragable=true;
this.Resizable=false;
this.AddBackground(7, 38, 152, 100, 9200);
this.AddAlphaRegion(11, 44, 141, 88);
this.AddButton(61, 53, 5600, 5604, (int)Buttons.Forward, GumpButtonType.Reply, 0);
this.AddButton(86, 78, 5601, 5605, (int)Buttons.Right, GumpButtonType.Reply, 0);
this.AddButton(61, 104, 5602, 5606, (int)Buttons.Backward, GumpButtonType.Reply, 0); this.AddButton(37, 78, 5603, 5607, (int)Buttons.Left, GumpButtonType.Reply, 0);
this.AddButton(62, 78, 11410, 11411, (int)Buttons.Stop, GumpButtonType.Reply, 0);
if (m_Vehicle.MaxFuel>0)
{
int level=(m_Vehicle.Fuel*10)/m_Vehicle.MaxFuel;
this.AddImage(16, 51, 10740+((level>8)?1:0)+((level>9)?1:0));
this.AddImage(16, 64, 10740+((level>6)?1:0)+((level>7)?1:0));
this.AddImage(16, 77, 10740+((level>4)?1:0)+((level>5)?1:0));
this.AddImage(16, 90, 10740+((level>2)?1:0)+((level>3)?1:0));
this.AddImage(16, 103, 10740+((level>0)?1:0)+((level>1)?1:0));
}
if (m_Vehicle.CanFly)
{
this.AddButton(39, 105, 250, 251, (int)Buttons.Up, GumpButtonType.Reply, 0);
this.AddButton(87, 104, 252, 253, (int)Buttons.Down, GumpButtonType.Reply, 0);
}
this.AddButton(106, 48, 2118, 2117, (int)Buttons.F1, GumpButtonType.Reply, 0);
this.AddButton(108, 109, 2118, 2117, (int)Buttons.F3, GumpButtonType.Reply, 0);
this.AddButton(130, 48, 2118, 2117, (int)Buttons.F2, GumpButtonType.Reply, 0);
this.AddButton(132, 109, 2118, 2117, (int)Buttons.F4, GumpButtonType.Reply, 0);
if ( m_Vehicle.Resistance <= 0 )
this.AddImage(112, 70, 10810);
else if ( m_Vehicle.EngineStatus == EngineStatusType.Stopped )
this.AddImage(112, 70, 10850);
else
this.AddImage(112, 70, 10830);
}
public enum Buttons
{
Exit,
Left,
Right,
Stop,
Forward,
Up,
Down,
F1,
F3,
F2,
F4,
Backward
}
public override void OnResponse( NetState sender, RelayInfo info )
{
Mobile from = sender.Mobile;
if (!from.Alive)
if (m_Vehicle.EngineStatus == EngineStatusType.Stopped)
{
m_Vehicle.OnDoubleClick(from);
return;
}
switch (info.ButtonID)
{
case (int)Buttons.Exit :
return;
case (int)Buttons.Left :
m_Vehicle.TurnLeft();
break;
case (int)Buttons.Right :
m_Vehicle.TurnRight();
break;
case (int)Buttons.Stop :
m_Vehicle.Stop();
break;
case (int)Buttons.Forward :
m_Vehicle.Forward();
break;
case (int)Buttons.Backward :
m_Vehicle.Backward();
break;
case (int)Buttons.Up :
m_Vehicle.Up();
break;
case (int)Buttons.Down :
m_Vehicle.Down();
break;
case (int)Buttons.F1 :
m_Vehicle.F1();
break;
case (int)Buttons.F2 :
m_Vehicle.F2();
break;
case (int)Buttons.F3 :
m_Vehicle.F3();
break;
case (int)Buttons.F4 :
m_Vehicle.F4();
break;
default:
break;
}
from.SendGump( new InternalGump( m_Vehicle ));
}
}
////////////////////// END ///////////////////////
}
}

would really be appreciated
olsyke- 06-28-2006
ok ok that was asked a lil much just looked too overwhelming at first
i managed to replace "frozen" with "CantWalk" and disabled "invisiblemobile" in my Speederbike.cs so the only problem i am left with is the "mounted" animation...
how would i declare the playermobile mounted while there is no actual mount or let the playermobile do the mounted-animation while being "rider" ?
obviously mounted=true diddnt do it for me ^^
ArteGordon- 06-28-2006
you would have to manually force the player to execute a mounted animation probably in your timer OnTick method that runs when they are in a vehicle with something like
m_Rider.Animate(action, 7, 1, true, false, 0);
where the action would be a value like 23,24, or 25 which are the mounted animations.
olsyke- 06-28-2006
okay well as far as i understand i would have to put something like this

CODE
private bool m_MountAnimation; [CommandProperty( AccessLevel.GameMaster )] public bool MountAnimation { get { return m_MountAnimation; } set { m_MountAnimation = value; } }

to have an entry accessable in the propertys named "Mountanimation" wich then could be set to true if you wanted the playermobile to do the Animation
and off course for this i would have to declare a loop with some IF statement that would keep the player do the animation - im gonna look into this
i just see a problem when it comes to combat while being mounted on the vehicle - will there still be the right mounted combat animations displayed if i keep telling him to Animate,25 all the time ?
wouldnt there be a other solution just to have the playermobile mount an invisible horse (invisible bodyvalue ?`) while the vehicle is put under him ?
ArteGordon- 06-28-2006
the invisible mount is a good idea.
olsyke- 06-28-2006
1 IF/FakeMount=true/22|4
2 GOTO/1
22 Horse/Mounted/true/Rider/GET,m.Rider,serial
4 the end
ok well if you could explain me in just in a short way how i set up an IF statement like the one above just in c++? i think i could handle the rest allone
Edit: and maybe point me towards some c++ tutorial so i dont have to bug you all the time
ArteGordon- 06-28-2006
there is a link to a c# tutorial pinned to the beginning of this forum.
it would look like
if(FakeMount)
{
horse.Mounted = true;
horse.Rider = m_Rider;
}
and for the horse you would create a mount with some bodytype that doesnt have mount animation which would make it invisible when mounted and just keep track of it on your vehicle.
olsyke- 06-28-2006
okay.....

CODE
private int m_Size; [CommandProperty( AccessLevel.GameMaster )] public int Size { get{ return m_Size; } set{ m_Size= value; } } private bool m_Locked;
[CommandProperty( AccessLevel.GameMaster )]
public bool Locked
{ get{ return m_Locked; } set{ m_Locked = value; } }
private uint m_KeyValue;
[CommandProperty( AccessLevel.GameMaster )]
public uint KeyValue
{ get { return m_KeyValue; } set { m_KeyValue = value; } }
///////This is where i added the definition for "FakeMount"//////////////////////////////////////////////////////////////////
public bool m_FakeMount;
[CommandProperty( AccessLevel.GameMaster )]
public bool FakeMount
{ get { return m_FakeMount; } set { m_FakeMount = value; } }
public Vehicle( int aNorthItemID ) : base( aNorthItemID )
{
NorthItemID = aNorthItemID;
Direction = Direction.North;
Movable = false;
Weight = 10000;
MaxFuel = 2000;
Fuel = MaxFuel;
Size = 1;
MaxSpeed = 1;
Speed = 0;
EngineStatus = EngineStatusType.Stopped;
IsInUse = false;
CanFly = false;
FlyAltitude = 100;
WaterAllowed = false;
MountainAllowed = false;
WaterAllowed = false;
StarsAllowed = false;
MaxResistance = 100;
Resistance = MaxResistance;
IsInUse = false;
InvisibleMobile= true;
////////////////////////////and added this line here to have it automaticly set to true on all vehicle class///////////////////////////////////////////////
FakeMount= true;
}
public Vehicle( Serial serial ) : base( serial )
{
}
public override void OnDelete()
{
if (Shadow != null)
if (!Shadow.Deleted)
Shadow.Delete();
base.OnDelete();
}
/////////////////// INTERACT MANAGER ///////////////////
public override void OnDoubleClick( Mobile mobile )
}
//////////////////////////////////// here i put the IF statement to check for FakeMount state and spawn a horse with bodyvalue of a polar bear
if (FakeMount)
{
Horse.Mounted = True;
Horse.Rider = m_Rider;
Horse.body = 0x5D;
}
if (!(mobile is PlayerMobile))
return;
PlayerMobile m = (PlayerMobile)mobile;
if ( m_IsInUse)
{
if (mobile == m_Rider)
{
if (m_EngineStatus != EngineStatusType.Stopped)
{
if (UseFrench)
m.SendMessage("Vous devez vous arrêter pour descendre.");
else
m.SendMessage("You must stop the vehicle to exit it.");
m.CloseGump(typeof(InternalGump));
m.SendGump(new InternalGump(this));
}
else
{
if (UseFrench)
m.SendMessage("Vous descendez du véhicule.");
else
m.SendMessage("You exit the vehicle.");
m.CloseGump(typeof(InternalGump));
m_IsInUse=false;
m.CantWalk=false;
if (m.Alive)
m.Hidden=false;
}
}
else
{
if (UseFrench)
m.SendMessage("Il y a déjà quelqu'un au commandes.");
else
m.SendMessage("There's already somebody in it.");
}
}
else
{
if ( (!m.CantWalk ) &&
(!m.Mounted) &&
(!m.Deleted) &&
( m.Alive ) )
{
if (Locked)
{
if (UseFrench)
m.SendMessage("Ce véhicule est fermé à clé.");
else
m.SendMessage("This vehicle is locked.");
return;
}
m_Rider=m;
m_IsInUse=true;
if (UseFrench)
m.SendMessage("Vous prenez les commandes du vehicule.");
else
m.SendMessage("You jump into the vehicle.");
m.CantWalk=true;
if (m_InvisibleMobile)
m.Hidden=true;
m_Rider.MoveToWorld(new Point3D(X-DiagonalOffset,Y-DiagonalOffset,Z),Map);
m.SendGump(new InternalGump(this));
UpdateItemID();
}
}
}

5 hours of scrolling later..

CODE
/////////////////// SAVE & LOAD MANAGER /////////////////// public override void Serialize( GenericWriter writer ) { base.Serialize( writer ); writer.Write( (int) 1 ); // version
writer.Write(m_InvisibleMobile);
writer.Write(m_NorthItemID);
writer.Write(m_AlternativeItemID);
writer.Write(m_EngineSound);
writer.Write(m_StartSound);
writer.Write(m_StopSound);
writer.Write(m_DiagonalOffset);
writer.Write(m_MaxSpeed);
writer.Write(m_Speed);
writer.Write((int)m_EngineStatus);
writer.Write(m_MaxResistance);
writer.Write(m_Resistance);
writer.Write(m_Fuel);
writer.Write(m_MaxFuel);
writer.Write(m_FlyAltitude);
writer.Write(m_IsInUse);
writer.Write(m_MaxSlope);
writer.Write(m_CanFly);
writer.Write(m_EarthAllowed);
writer.Write(m_WaterAllowed);
writer.Write(m_MontainAllowed);
writer.Write(m_StarsAllowed);
writer.Write(m_Rider);
writer.Write(m_Size);
writer.Write(m_Shadow);
writer.Write(m_FakeMount);
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
switch(version)
{
case 1:
m_InvisibleMobile = reader.ReadBool();
goto case 0;
case 0:
m_NorthItemID = reader.ReadInt();
m_AlternativeItemID = reader.ReadInt();
m_EngineSound = reader.ReadInt();
m_StartSound = reader.ReadInt();
m_StopSound = reader.ReadInt();
m_DiagonalOffset = reader.ReadInt();
m_MaxSpeed = reader.ReadInt();
m_Speed = reader.ReadInt();
m_EngineStatus = (EngineStatusType)reader.ReadInt();
m_MaxResistance = reader.ReadInt();
m_Resistance = reader.ReadInt();
m_Fuel = reader.ReadInt();
m_MaxFuel = reader.ReadInt();
m_FlyAltitude = reader.ReadInt();
m_IsInUse = reader.ReadBool();
m_MaxSlope = reader.ReadInt();
m_CanFly = reader.ReadBool();
m_EarthAllowed = reader.ReadBool();
m_WaterAllowed = reader.ReadBool();
m_MontainAllowed = reader.ReadBo();
m_StarsAllowed = reader.ReadBool();
////////////////////////////////////////////////wether this is here or not same error.. C# tutorial has no answer either what ReadBool is at all :P//////////
m_FakeMount = reader.ReadBool();
m_Rider = reader.ReadMobile();
m_Size = reader.ReadInt();
m_Shadow = (VehicleShadow)reader.ReadItem();
break;
default:
break;
}
if (m_IsInUse)
if (m_Rider != null)
m_Rider.CantWalk=true;
if ( EngineStatus != EngineStatusType.Stopped)
m_TimerInterval.Start();
}

well and here is the errors i get along with the newly add IF statement (line 242) i double checked for spelling but there seems to be something differend wrong.....
olsyke- 06-29-2006
well i kept working on that if statement and this is the result
Errors:
+ Vehicle.cs:
CS1519: Line 483: Invalid token 'if' in class, struct, or interface member declaration
CS1518: Line 483: Invalid token '>' in class, struct, or interface member declaration
CS1518: Line 520: Expected class, delegate, enum, interface, or struct
CS1518: Line 534: Expected class, delegate, enum, interface, or struct
CS1518: Line 569: Expected class, delegate, enum, interface, or struct
CS1518: Line 634: Expected class, delegate, enum, interface, or struct
CS0116: Line 636: A namespace does not directly contain members such as fields or methods
CS1022: Line 646: Type or namespace definition, or end-of-file expected
Scripts: One or more scripts failed.......

CODE
if (FakeMount) { public class Horse : Mobile { [Constructable]
public Horse() : base( 0x5D )
{
Rider = m_Rider;
Name = "a Horse";
body = 0x5d;
}
public Horse( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 );
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize( reader );
int version = reader.ReadInt();
}
}
}

running out of ideas i am.. also tried finding help on runuo forums but the original author doesnt seem to work on this anymore
ArteGordon- 06-29-2006
you cannot have statements like this

CODE
if (FakeMount) { }

outside of class definitions. You are trying to do this

CODE
if (FakeMount) { //define a class in here like public class Horse : Mobile {
}
}

and that is not allowed.
What you need to do is to add code like

CODE
if(FakeMount) { horse.Mounted = true; horse.Rider = m_Rider; }

into the method where players get into your vehicle.
olsyke- 06-29-2006
okay this got me a little further im starting to understand it a little i think..
error is now :

CODE
+Vehicle.cs: CS0103:Lince 307: The name 'horse" does not exist in the current context CS0103:Lince 307: The name 'horse" does not exist in the current context

and what i guess is that this is because..

CODE
if(FakeMount) { Horse.Mounted = true; /////.... this doesnt acually spawn a horse.just would set one to Mounted=true so it cant find one when executed, right ?//// Horse.Rider = m_Rider; }

so in my logical way of thinking there has to be a horse spawned before it can be set to mounted=true but....

CODE
if(FakeMount) { public Horse( Serial serial ) : base( serial ) /// this spawns a horse or what am i getting wrong ?////// Horse.Mounted = true; Horse.Rider = m_Rider;

.... the error stays the same: name horse not found...
and you said i should move it to the method where the player enters the vehicle so this is the part where that is happening:

CODE
if (Locked) { if (UseFrench) m.SendMessage("Ce véhicule est fermé à clé."); else
m.SendMessage("This vehicle is locked.");
return;
}
m_Rider=m;
m_IsInUse=true;
if (UseFrench)
m.SendMessage("Vous prenez les commandes du vehicule.");
else
m.SendMessage("You jump into the vehicle.");
m.CantWalk=true;
if(FakeMount)
{
public Horse( Serial serial ) : base( serial )
Horse.Mounted = true;
Horse.Rider = m_Rider;
}
if (m_InvisibleMobile)
m.Hidden=true;
m_Rider.MoveToWorld(new Point3D(X-DiagonalOffset,Y-DiagonalOffset,Z),Map);
m.SendGump(new InternalGump(this));
UpdateItemID();
}
}
}

ArteGordon- 06-29-2006
what you want is to use this

CODE
if(FakeMount) { horse.Mounted = true; horse.Rider = m_Rider; }

and then somewhere else, such as in the constructor for the vehicle, create and assign the horse variable, like

CODE
horse = new Horse();

You will need to define your horse variable in your Vehicle class, like
public Mobile horse;
olsyke- 06-29-2006
okay were getting close..
i managed to do what you said after playing around a little but now its getting weird...
error:

CODE
+Vehicle.cs: CS0200: Line 309: Property or indexer 'Server.Mobile.Mounted' cannot be assigned to -- it is read only CS0117: Line 310: 'Server.Mobile' does not contain a definition for 'Rider'

CODE
if(FakeMount) { Horse.Mounted = true; Horse.Rider = m_Rider; }

why i dont understand it at all is because there IS
"using Server.Mobiles;"
at the beginning of the script -> and the actuall spelling in the error-message doesnt even match it!
" 'Server.Mobile.Mounted' cannot be...."
" 'Server.Mobile' does not...."
what the... ?
ArteGordon- 06-29-2006
You just need to assign the Rider of the mount. You dont need to assign Mounted.
Your Horse class needs to be derived from BaseMount not Mobile, so change the Horse class and then when you declare the 'horse' variable do something like
public BaseMount horse;
and here
Horse.Rider = m_Rider;
you need to refer to the 'horse' variable that you assigned earlier not the Horse class.
Note, that you are probably going to run into problems if you name your class Horse since there is already a Horse class defined in the standard distribution.
olsyke- 06-29-2006
hehe guess what