Macil
Sorceror
http://www.runuo.com/community/threads/runuo-2-0-rc2-variable-carpet-addon-deeds.88200/
So, I'm trying to modify the above script (I would have posted it in that script's thread but it says I have insufficient access - no doubt it's archived as it's quite old).
The script works great on my server as-is for player usage. But I'd like to modify it to not consume the deed when you use it, and make it so you can use it ANYWHERE. So my staff members can use it for building variable carpets/rugs outside of player homes. Is this possible with this script? How would I go about do so?
I think a tool like this could be highly useful to anyone for world building.
VariableCarpetAddon.cs:
VariableCarpetAddonDeed.cs:
So, I'm trying to modify the above script (I would have posted it in that script's thread but it says I have insufficient access - no doubt it's archived as it's quite old).
The script works great on my server as-is for player usage. But I'd like to modify it to not consume the deed when you use it, and make it so you can use it ANYWHERE. So my staff members can use it for building variable carpets/rugs outside of player homes. Is this possible with this script? How would I go about do so?
I think a tool like this could be highly useful to anyone for world building.
VariableCarpetAddon.cs:
Code:
//================================================//
// Based on winecrafting grounds created by //
// dracana, modded by Manu from Splitterwelt.com //
// for use with carpets //
// Desc: For players to place carpets in their //
// houses. Especially useful for players //
// with non-custom housing.
// Modified for 2.0 by Draco Van Peeble
//================================================//
using System;
using System.Collections;
using Server;
using Server.Gumps;
using Server.Mobiles;
using Server.Multis;
using Server.Network;
namespace Server.Items
{
public class VariableCarpetAddon : BaseAddon
{
public override BaseAddonDeed Deed{ get{ return new VariableCarpetAddonDeed(); } }
#region Constructors
[Constructable]
public VariableCarpetAddon( VariableCarpetType type, int width, int height ) : this( (int)type, width, height )
{
}
public VariableCarpetAddon( int type, int width, int height )
{
VariableCarpetInfo info = VariableCarpetInfo.GetInfo( type );
AddComponent( new AddonComponent( info.GetItemPart( GroundPosition.Top ).ItemID ), 0, 0, 0 );
AddComponent( new AddonComponent( info.GetItemPart( GroundPosition.Right ).ItemID ), width, 0, 0 );
AddComponent( new AddonComponent( info.GetItemPart( GroundPosition.Left ).ItemID ), 0, height, 0 );
AddComponent( new AddonComponent( info.GetItemPart( GroundPosition.Bottom ).ItemID ), width, height, 0 );
int w = width - 1;
int h = height - 1;
for ( int y = 1; y <= h; ++y )
AddComponent( new AddonComponent( info.GetItemPart( GroundPosition.West ).ItemID ), 0, y, 0 );
for ( int x = 1; x <= w; ++x )
AddComponent( new AddonComponent( info.GetItemPart( GroundPosition.North ).ItemID ), x, 0, 0 );
for ( int y = 1; y <= h; ++y )
AddComponent( new AddonComponent( info.GetItemPart( GroundPosition.East ).ItemID ), width, y, 0 );
for ( int x = 1; x <= w; ++x )
AddComponent( new AddonComponent( info.GetItemPart( GroundPosition.South ).ItemID ), x, height, 0 );
for ( int x = 1; x <= w; ++x )
for ( int y = 1; y <= h; ++y )
AddComponent( new AddonComponent( info.GetItemPart( GroundPosition.Center ).ItemID ), x, y, 0 );
}
public VariableCarpetAddon( Serial serial ) : base( serial )
{
}
#endregion
public override void OnDoubleClick( Mobile from )
{
BaseHouse house = BaseHouse.FindHouseAt( this );
if ( house != null && house.IsCoOwner( from ) )
{
if ( from.InRange( GetWorldLocation(), 3 ) )
{
from.SendGump(new ConfirmRemovalGumpVariableCarpet( this ));
}
else
{
from.SendLocalizedMessage( 500295 ); // You are too far away to do that.
}
}
}
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 enum VariableCarpetType
{
BlueStructureBorder,
BluePlainBorder,
BlueYellowBorder,
RedStructureBorder,
RedPlainBorder,
YellowStructureBorder
}
public enum GroundPosition
{
Top,
Bottom,
Left,
Right,
West,
North,
East,
South,
Center
}
public class VariableCarpetInfo
{
private GroundItemPart[] m_Entries;
public GroundItemPart[] Entries{ get{ return m_Entries; } }
public VariableCarpetInfo( GroundItemPart[] entries )
{
m_Entries = entries;
}
public GroundItemPart GetItemPart( GroundPosition pos )
{
int i = (int)pos;
if ( i < 0 || i >= m_Entries.Length )
i = 0;
return m_Entries[i];
}
public static VariableCarpetInfo GetInfo( int type )
{
if ( type < 0 || type >= m_Infos.Length )
type = 0;
return m_Infos[type];
}
#region VariableCarpetInfo definitions
private static VariableCarpetInfo[] m_Infos = new VariableCarpetInfo[] {
/* BlueStructureBorder */new VariableCarpetInfo( new GroundItemPart[] {
new GroundItemPart( 0xAC3, GroundPosition.Top, 44, 0 ),
new GroundItemPart( 0xAC2, GroundPosition.Bottom, 44, 68 ),
new GroundItemPart( 0xAC4, GroundPosition.Left, 0, 28 ),
new GroundItemPart( 0xAC5, GroundPosition.Right, 88, 28 ),
new GroundItemPart( 0xAF6, GroundPosition.West, 22, 12 ),
new GroundItemPart( 0xAF7, GroundPosition.North, 66, 12 ),
new GroundItemPart( 0xAF8, GroundPosition.East, 66, 46 ),
new GroundItemPart( 0xAF9, GroundPosition.South, 22, 46 ),
new GroundItemPart( 0xABD, GroundPosition.Center, 44, 24 )
}),
/* BluePlainBorder */new VariableCarpetInfo( new GroundItemPart[] {
new GroundItemPart( 0xAC3, GroundPosition.Top, 44, 0 ),
new GroundItemPart( 0xAC2, GroundPosition.Bottom, 44, 68 ),
new GroundItemPart( 0xAC4, GroundPosition.Left, 0, 28 ),
new GroundItemPart( 0xAC5, GroundPosition.Right, 88, 28 ),
new GroundItemPart( 0xAF6, GroundPosition.West, 22, 12 ),
new GroundItemPart( 0xAF7, GroundPosition.North, 66, 12 ),
new GroundItemPart( 0xAF8, GroundPosition.East, 66, 46 ),
new GroundItemPart( 0xAF9, GroundPosition.South, 22, 46 ),
new GroundItemPart( 0xABE, GroundPosition.Center, 44, 24 )
}),
/* BlueYellowBorder */new VariableCarpetInfo( new GroundItemPart[] {
new GroundItemPart( 0xAD3, GroundPosition.Top, 44, 0 ),
new GroundItemPart( 0xAD2, GroundPosition.Bottom, 44, 68 ),
new GroundItemPart( 0xAD4, GroundPosition.Left, 0, 28 ),
new GroundItemPart( 0xAD5, GroundPosition.Right, 88, 28 ),
new GroundItemPart( 0xAD6, GroundPosition.West, 22, 8 ),
new GroundItemPart( 0xAD7, GroundPosition.North, 66, 8 ),
new GroundItemPart( 0xAD8, GroundPosition.East, 66, 46 ),
new GroundItemPart( 0xAD9, GroundPosition.South, 22, 46 ),
new GroundItemPart( 0xAD1, GroundPosition.Center, 44, 24 )
}),
/* RedStructureBorder*/new VariableCarpetInfo( new GroundItemPart[] {
new GroundItemPart( 0xACA, GroundPosition.Top, 44, 0 ),
new GroundItemPart( 0xAC9, GroundPosition.Bottom, 44, 68 ),
new GroundItemPart( 0xACB, GroundPosition.Left, 0, 28 ),
new GroundItemPart( 0xACC, GroundPosition.Right, 88, 28 ),
new GroundItemPart( 0xACD, GroundPosition.West, 22, 10 ),
new GroundItemPart( 0xACE, GroundPosition.North, 66, 12 ),
new GroundItemPart( 0xACF, GroundPosition.East, 66, 46 ),
new GroundItemPart( 0xAD0, GroundPosition.South, 22, 46 ),
new GroundItemPart( 0xAC7, GroundPosition.Center, 44, 24 )
}),
/* RedPlainBorder */new VariableCarpetInfo( new GroundItemPart[] {
new GroundItemPart( 0xACA, GroundPosition.Top, 44, 0 ),
new GroundItemPart( 0xAC9, GroundPosition.Bottom, 44, 68 ),
new GroundItemPart( 0xACB, GroundPosition.Left, 0, 28 ),
new GroundItemPart( 0xACC, GroundPosition.Right, 88, 28 ),
new GroundItemPart( 0xACD, GroundPosition.West, 22, 10 ),
new GroundItemPart( 0xACE, GroundPosition.North, 66, 12 ),
new GroundItemPart( 0xACF, GroundPosition.East, 66, 46 ),
new GroundItemPart( 0xAD0, GroundPosition.South, 22, 46 ),
new GroundItemPart( 0xAC8, GroundPosition.Center, 44, 24 )
}),
/* YellowStructureBorder */new VariableCarpetInfo( new GroundItemPart[] {
new GroundItemPart( 0xADC, GroundPosition.Top, 44, 0 ),
new GroundItemPart( 0xADB, GroundPosition.Bottom, 44, 68 ),
new GroundItemPart( 0xADD, GroundPosition.Left, 0, 28 ),
new GroundItemPart( 0xADE, GroundPosition.Right, 88, 28 ),
new GroundItemPart( 0xADF, GroundPosition.West, 22, 8 ),
new GroundItemPart( 0xAE0, GroundPosition.North, 66, 8 ),
new GroundItemPart( 0xAE1, GroundPosition.East, 66, 46 ),
new GroundItemPart( 0xAE2, GroundPosition.South, 22, 46 ),
new GroundItemPart( 0xADA, GroundPosition.Center, 44, 24 )
})
};
#endregion
public static VariableCarpetInfo[] Infos{ get{ return m_Infos; } }
}
public class GroundItemPart
{
private int m_ItemID;
private GroundPosition m_Info;
private int m_OffsetX;
private int m_OffsetY;
public int ItemID
{
get{ return m_ItemID; }
}
public GroundPosition GroundPosition
{
get{ return m_Info; }
}
// For Gump Rendering
public int OffsetX
{
get{ return m_OffsetX; }
}
// For Gump Rendering
public int OffsetY
{
get{ return m_OffsetY; }
}
public GroundItemPart( int itemID, GroundPosition info, int offsetX, int offsetY )
{
m_ItemID = itemID;
m_Info = info;
m_OffsetX = offsetX;
m_OffsetY = offsetY;
}
}
public class ConfirmRemovalGumpVariableCarpet : Gump
{
private VariableCarpetAddon m_VariableCarpetAddon;
public ConfirmRemovalGumpVariableCarpet(VariableCarpetAddon VariableCarpetaddon)
: base(50, 50)
{
m_VariableCarpetAddon = VariableCarpetaddon;
AddBackground(0, 0, 450, 260, 9270);
AddAlphaRegion(12, 12, 426, 22);
AddTextEntry(13, 13, 379, 20, 32, 0, @"Warning!");
AddAlphaRegion(12, 39, 426, 209);
AddHtml(15, 50, 420, 185, "<BODY>" +
"<BASEFONT COLOR=YELLOW>You are about to remove this carpet!<BR><BR>" +
"<BASEFONT COLOR=YELLOW>If it is removed, a deed will be placed " +
"<BASEFONT COLOR=YELLOW>in your backpack.<BR><BR>" +
"<BASEFONT COLOR=YELLOW>Are you sure that you want to remove this carpet?<BR><BR>" +
"</BODY>", false, false);
AddButton(13, 220, 0xFA5, 0xFA6, 1, GumpButtonType.Reply, 0);
AddHtmlLocalized(47, 222, 150, 20, 1052072, 0x7FFF, false, false); // Continue
//AddButton(200, 245, 0xFB1, 0xFB2, 0, GumpButtonType.Reply, 0);
//AddHtmlLocalized(47, 247, 450, 20, 1060051, 0x7FFF, false, false); // CANCEL
AddButton(350, 220, 0xFB1, 0xFB2, 0, GumpButtonType.Reply, 0);
AddHtmlLocalized(385, 222, 100, 20, 1060051, 0x7FFF, false, false); // CANCEL
}
public override void OnResponse(NetState sender, RelayInfo info)
{
if (info.ButtonID == 0 )
return;
Mobile from = sender.Mobile;
from.AddToBackpack(new VariableCarpetAddonDeed());
m_VariableCarpetAddon.Delete();
from.SendMessage( "Carpet removed" );
}
}
}
VariableCarpetAddonDeed.cs:
Code:
//================================================//
// Based on winecrafting grounds created by //
// dracana, modded by Manu from Splitterwelt.com //
// for use with carpets //
// Desc: For players to place carpets in their //
// houses. Especially useful for players //
// with non-custom housing.
// Modified for 2.0 by Draco Van Peeble
//================================================//
using System;
using System.Collections.Generic;
using Server;
using Server.Gumps;
using Server.Items;
using Server.Multis;
using Server.Network;
using Server.Targeting;
namespace Server.Items
{
public class VariableCarpetAddonDeed : BaseAddonDeed
{
public override BaseAddon Addon{ get{ return null; } }
[Constructable]
public VariableCarpetAddonDeed()
{
Name = "Variable Carpet Addon Deed";
}
public VariableCarpetAddonDeed( Serial serial ) : base( serial )
{
}
public override void OnDoubleClick( Mobile from )
{
if ( IsChildOf( from.Backpack ) )
BoundingBoxPicker.Begin( from, new BoundingBoxCallback( BoundingBox_Callback ), null );
else
from.SendLocalizedMessage( 1042001 ); // That must be in your pack for you to use it.
}
private void BoundingBox_Callback( Mobile from, Map map, Point3D start, Point3D end, object state )
{
IPoint3D p = start as IPoint3D;
if ( p == null || map == null )
return;
int width = (end.X - start.X), height = (end.Y - start.Y);
if ( width < 2 || height < 2 )
from.SendMessage( "The carpet has to cover a minimum area of 3x3 tiles." );
else if ( IsChildOf( from.Backpack ) )
from.SendGump( new VariableCarpetGump( this, p, map, width, height ) );
else
from.SendLocalizedMessage( 1042001 ); // That must be in your pack for you to use it.
}
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();
}
}
}
namespace Server.Gumps
{
public class VariableCarpetGump : Gump
{
private const int EntryCount = 3;
private BaseAddonDeed m_Deed;
private IPoint3D m_P3D;
private Map m_Map;
private int m_Width;
private int m_Height;
public VariableCarpetGump( BaseAddonDeed deed, IPoint3D p, Map map, int width, int height ) : base( 30, 30 )
{
m_Deed = deed;
m_P3D = p;
m_Map = map;
m_Width = width;
m_Height = height;
AddPage( 0 );
AddBackground( 0, 0, 450, 160, 9250 );
AddAlphaRegion( 12, 12, 381, 22 );
AddHtml( 13, 13, 379, 20, "<BASEFONT COLOR=WHITE>Choose your carpet</BASEFONT>", false, false );
AddAlphaRegion( 398, 12, 40, 22 );
AddAlphaRegion( 12, 39, 426, 109 );
AddImage( 400, 16, 9766 );
AddImage( 420, 16, 9762 );
AddPage( 1 );
int page = 1;
for ( int i = 0, index = 0; i < VariableCarpetInfo.Infos.Length; ++i, ++index )
{
if ( index >= EntryCount )
{
if ( (EntryCount * page) == EntryCount )
AddImage( 400, 16, 0x2626 );
AddButton( 420, 16, 0x15E1, 0x15E5, 0, GumpButtonType.Page, page + 1 );
++page;
index = 0;
AddPage( page );
AddButton( 400, 16, 0x15E3, 0x15E7, 0, GumpButtonType.Page, page - 1 );
if ( (VariableCarpetInfo.Infos.Length - (EntryCount * page)) < EntryCount )
AddImage( 420, 16, 0x2622 );
}
VariableCarpetInfo info = VariableCarpetInfo.GetInfo( i );
for ( int j = 0; j < info.Entries.Length; ++j )
{
if (info.Entries[j].OffsetX >= 0 && info.Entries[j].OffsetY >= 0 )
AddItem( 20 + (index * 140 ) + info.Entries[j].OffsetX, 46 + info.Entries[j].OffsetY, info.Entries[j].ItemID );
}
AddButton( 20 + (index * 140 ), 46, 1209, 1210, i+1, GumpButtonType.Reply, 0);
}
}
public override void OnResponse( NetState sender, RelayInfo info )
{
Mobile from = sender.Mobile;
if ( info.ButtonID >= 1 )
{
BaseAddon addon = new VariableCarpetAddon( info.ButtonID-1, m_Width, m_Height );
Server.Spells.SpellHelper.GetSurfaceTop( ref m_P3D );
BaseHouse house = null;
AddonFitResult res = addon.CouldFit( m_P3D, m_Map, from, ref house );
if ( res == AddonFitResult.Valid )
addon.MoveToWorld( new Point3D( m_P3D ), m_Map );
else if ( res == AddonFitResult.Blocked )
from.SendLocalizedMessage( 500269 ); // You cannot build that there.
else if ( res == AddonFitResult.NotInHouse )
from.SendLocalizedMessage( 500274 ); // You can only place this in a house that you own!
//else if ( res == AddonFitResult.DoorsTooClosed )
//from.SendMessage( "All doors must be closed!" );
if ( res == AddonFitResult.Valid )
{
m_Deed.Delete();
if ( house != null )
{
house.Addons.Add( addon );
from.SendGump( new VariableCarpetPlacedGump( m_Deed ) );
}
}
else
{
addon.Delete();
}
}
}
}
public class VariableCarpetPlacedGump : Gump
{
private BaseAddonDeed m_Deed;
public VariableCarpetPlacedGump( BaseAddonDeed deed ) : base( 30, 30 )
{
m_Deed = deed;
AddPage( 0 );
AddBackground( 0, 0, 450, 250, 9250 );
AddAlphaRegion( 12, 12, 426, 22 );
AddHtml( 13, 13, 379, 20, "<BASEFONT COLOR=WHITE>Carpet successfully placed</BASEFONT>", false, false );
AddAlphaRegion( 12, 39, 426, 199 );
AddHtml( 15, 50, 420, 185, "<BODY>" +
"<BASEFONT COLOR=YELLOW>Your carpet has been placed!<BR>" +
"<BASEFONT COLOR=YELLOW>You may remove this carpet again easily. " +
"<BASEFONT COLOR=YELLOW>Simply use an axe on the carpet.<BR>" +
"<BASEFONT COLOR=YELLOW>*Notice* You have to be within 3 tiles of the west corner of the addon to remove it.<BR><BR>" +
"</BODY>", false, false );
AddButton( 190, 210, 0xF7, 0xF8, 0, GumpButtonType.Reply, 0 );
}
public override void OnResponse( NetState sender, RelayInfo info )
{
Mobile from = sender.Mobile;
switch ( info.ButtonID )
{
case 0: //Case uses the ActionIDs defined above. Case 0 defines the actions for the button with the action id 0
{
//Cancel
from.SendMessage( "Enjoy your new carpet." );
break;
}
}
}
}
}