//////////////////////////////////////////
//           AOS HOUSE SYSTEM		//
//					//
//  Created by Coruja			//
//  coruja747 @ sphereserver.net forum	//
//  Script Version: 5.4			//
//  Last update: 02/06/2009		//
//  Plase don't remove this header	//
//					//
//////////////////////////////////////////
//					//
//            INSTALL NOTES		//
//					//
// This script is "drag & drop", just	//
// set the defnames below and put it in	//
// your scripts folder.			//
//      Works only on Sphere 056b	//
//					//
// To enable the auto-decay of invalid	//
// houses (houses without owners, duo	//
// account delection), just put:	//
//     SRC.remove_invalid_houses	//
// on the "sphere_serv_triggers.scp"	//
// script, at the section:		//
//     "f_onchar_delete"		//
//					//
// To enable the House Placement Tools,	//
// just add the item			//
//      "i_house_placement_tool"	//
// on your architect npc stock, on the	//
// script "sphere_template_vend.scp"	//
// at the VENDOR_S_DEED_TEMPLATE list.	//
// To enable the Interior Decorator,	//
// just add the item			//
//	"i_house_interior_decorator"	//
// on the same npc stock.		//
//					//
// This script is compatible with	//
// Custom Vendor systems. If you have	//
// problems on interactivity with your	//
// vendors, just modify the function	//
// "IsHouseVendor" in this script.	//
//					//
//////////////////////////////////////////

[DEFNAME HOUSE_SYSTEM]
//Misc Settings
HOUSE_USE_DEEDS			0	//When a house got demolished, you want get back your house deed or the house value in gold? (0=House Value in Gold / 1=House Deed)
HOUSE_DECAY_TIMER		30	//House decay timer, in days (0=Decay Off)
DEMOLITION_PEND_DECAY		5	//House decay timer for Demolition Pending houses, in days (Houses can only be pended to demolition by a Game Master)
MAX_ACCOUNT_HOUSES		2	//Max number of houses allowed per account
ACCOUNT_OWNERSHIP		1	//All character of the house owner account will get owner access in the house (0=Off / 1=On)
HOUSE_USE_TRASHBARREL		1	//Enable house command to place trash barrel (1=On / 0=Off)

//Placement Settings
PLACEMENT_MIN_DIST_AREA		1	//Minimum area distance allowed between placed houses (Default=1)
PLACEMENT_MIN_DIST_FRONT	5	//Minimum front distance allowed between placed houses (Default=5)
PLACEMENT_ILSHENAR_FACET	0	//Allow place houses on Ilshenar facet (1=Yes / 0=No)(Default=0)
PLACEMENT_WAITING_PERIOD	0	//Period in days that a player must wait to place a new house before house placement (Default=7)
DEMOLISH_REFUND_PERCENT		90	//% of house value that will be refunded on demolish (Default=90)

//Storage Settings
USE_GLOBAL_STORAGE		0	//Use Global Storage Limit value or calculate it by the house area? (0=Calculate by House Area / 1=Global Value)
GLOBAL_SECURE_STORAGE		600	//Global max secured storage allowed per house (secure containers + items inside secure containers)
GLOBAL_LOCKDOWNS		100	//Global max locked items allowed per house (this value will cont on Secure Storage Limit)

//Access Settings
HOUSE_DOOR_ACCESS		1	//Owner of the house can change the door access? (1=On / 0=Off)
MAX_HOUSE_COOWNERS		15	//Max number of co-owners allowed per house
MAX_HOUSE_FRIENDS		50	//Max number of friends allowed per house
MAX_HOUSE_BANS			50	//Max number of bans allowed per house
MAX_HOUSE_ACCESS		50	//Max number of players on access list allowed per house
HOUSE_USE_DEPTH_OF_FIELD	1	//Allow enter on private houses only who is in access list (1=On / 0=Off)
HOUSE_USE_BAN_ENGINE		1	//Enable house ban engine? (1=On / 0=Off)

//Addictional Features
ALLOW_BANKING			0	//Enable banking from the house sign? (1=On / 0=Off)
USE_NOTICE_SYSTEM		1	//Notice player using dialog when your house decay or when it removed from the house access list (0=Off / 1=On)

//AOS House Customization Settings
SIGN_CHANGE_PUBLIC_ONLY		1	//Only public houses can change house sign? (1=Yes / 0=No)
HOUSE_AOS_CUSTOMIZATION		1	//Enable AOS Customization system? (1=On / 0=Off)
HOUSE_COMPONENT_PRICE		500	//Price per customized component, in gp's (Default=500)
HOUSE_ALLOW_CONVERTION		0	//Classic houses can be converted into custom foundations? (1=Yes / 0=No)

//Custom Vendor Settings
HOUSE_USE_VENDORS		1	//Enable house interactivity with custom vendors (1=On / 0=Off)
HOUSE_VENDORS_PUBLIC_ONLY	0	//Vendors can be placed only on public houses? (1=On / 0=Off)
HOUSE_USE_GLOBAL_MAXVENDORS	0	//Use Global Vendor Limit or calculate it by the house area? (0=Calculate by House Area / 1=Global Value)
HOUSE_GLOBAL_MAXVENDORS		30	//Max number of vendors allowed per house

/////////////////////////////////////////

[FUNCTION IsHouseVendor]		//Configure this function to recognize your vendor script
IF ((<NPC> == brain_human) || (<NPC> == brain_vendor) || (<BASEID> == C_VENDOR_PLAYER))	//Do not use (<OWNER.ISPLAYER>), Sphere cannot recognize OWNER when the vendor got created.
 return 1
ELSE
 return 0
ENDIF

[FUNCTION HouseVendorRemove]		//Function called on vendor before the house remove it
SERV.NEWITEM I_DEED_VENDOR_POD
NEW.P=<P>
REMOVE

/////////////////////////////////////////

[DEFNAME Avaible_Houses]		//Avaible houses on House Placement Tool
house_classic_1			"i_multi_house_stone_plaster_small"
house_classic_2			"i_multi_house_stone_small"
house_classic_3			"i_multi_house_stone_brick_small"
house_classic_4			"i_multi_house_stone_wood_small"
house_classic_5			"i_multi_house_wood_plaster_small"
house_classic_6			"i_multi_house_wood_thatched_small"
house_classic_7			"i_multi_shop_stone_small"
house_classic_8			"i_multi_shop_marble_small"
house_classic_9			"i_multi_tower_wizard"
house_classic_10		"i_multi_house_patio_sand"
house_classic_11		"i_multi_villa_2story"
house_classic_12		"i_multi_cabin_log_2story"
house_classic_13		"i_multi_house_3room"
house_classic_14		"i_multi_house_wood_plaster_2story"
house_classic_15		"i_multi_house_stone_plaster_2story"
house_classic_16		"i_multi_shop_blacksmithy_large"
house_classic_17		"i_multi_house_patio_marble"
house_classic_18		"i_multi_tower"
house_classic_19		"i_multi_keep"
house_classic_20		"i_multi_castle"

house_custom_2story_1		"i_multi_foundation_7x7"
house_custom_2story_2		"i_multi_foundation_7x8"
house_custom_2story_3		"i_multi_foundation_7x9"
house_custom_2story_4		"i_multi_foundation_7x10"
house_custom_2story_5		"i_multi_foundation_7x11"
house_custom_2story_6		"i_multi_foundation_7x12"
house_custom_2story_7		"i_multi_foundation_8x7"
house_custom_2story_8		"i_multi_foundation_8x8"
house_custom_2story_9		"i_multi_foundation_8x9"
house_custom_2story_10		"i_multi_foundation_8x10"
house_custom_2story_11		"i_multi_foundation_8x11"
house_custom_2story_12		"i_multi_foundation_8x12"
house_custom_2story_13		"i_multi_foundation_8x13"
house_custom_2story_14		"i_multi_foundation_9x7"
house_custom_2story_15		"i_multi_foundation_9x8"
house_custom_2story_16		"i_multi_foundation_9x9"
house_custom_2story_17		"i_multi_foundation_9x10"
house_custom_2story_18		"i_multi_foundation_9x11"
house_custom_2story_19		"i_multi_foundation_9x12"
house_custom_2story_20		"i_multi_foundation_9x13"
house_custom_2story_21		"i_multi_foundation_10x7"
house_custom_2story_22		"i_multi_foundation_10x8"
house_custom_2story_23		"i_multi_foundation_10x9"
house_custom_2story_24		"i_multi_foundation_10x10"
house_custom_2story_25		"i_multi_foundation_10x11"
house_custom_2story_26		"i_multi_foundation_10x12"
house_custom_2story_27		"i_multi_foundation_10x13"
house_custom_2story_28		"i_multi_foundation_11x7"
house_custom_2story_29		"i_multi_foundation_11x8"
house_custom_2story_30		"i_multi_foundation_11x9"
house_custom_2story_31		"i_multi_foundation_11x10"
house_custom_2story_32		"i_multi_foundation_11x11"
house_custom_2story_33		"i_multi_foundation_11x12"
house_custom_2story_34		"i_multi_foundation_11x13"
house_custom_2story_35		"i_multi_foundation_12x7"
house_custom_2story_36		"i_multi_foundation_12x8"
house_custom_2story_37		"i_multi_foundation_12x9"
house_custom_2story_38		"i_multi_foundation_12x10"
house_custom_2story_39		"i_multi_foundation_12x11"
house_custom_2story_40		"i_multi_foundation_12x12"
house_custom_2story_41		"i_multi_foundation_12x13"
house_custom_2story_42		"i_multi_foundation_13x8"
house_custom_2story_43		"i_multi_foundation_13x9"
house_custom_2story_44		"i_multi_foundation_13x10"
house_custom_2story_45		"i_multi_foundation_13x11"
house_custom_2story_46		"i_multi_foundation_13x12"
house_custom_2story_47		"i_multi_foundation_13x13"

house_custom_3story_1		"i_multi_foundation_9x14"
house_custom_3story_2		"i_multi_foundation_10x14"
house_custom_3story_3		"i_multi_foundation_10x15"
house_custom_3story_4		"i_multi_foundation_11x14"
house_custom_3story_5		"i_multi_foundation_11x15"
house_custom_3story_6		"i_multi_foundation_11x16"
house_custom_3story_7		"i_multi_foundation_12x14"
house_custom_3story_8		"i_multi_foundation_12x15"
house_custom_3story_9		"i_multi_foundation_12x16"
house_custom_3story_10		"i_multi_foundation_12x17"
house_custom_3story_11		"i_multi_foundation_13x14"
house_custom_3story_12		"i_multi_foundation_13x15"
house_custom_3story_13		"i_multi_foundation_13x16"
house_custom_3story_14		"i_multi_foundation_13x17"
house_custom_3story_15		"i_multi_foundation_13x18"
house_custom_3story_16		"i_multi_foundation_14x9"
house_custom_3story_17		"i_multi_foundation_14x10"
house_custom_3story_18		"i_multi_foundation_14x11"
house_custom_3story_19		"i_multi_foundation_14x12"
house_custom_3story_20		"i_multi_foundation_14x13"
house_custom_3story_21		"i_multi_foundation_14x14"
house_custom_3story_22		"i_multi_foundation_14x15"
house_custom_3story_23		"i_multi_foundation_14x16"
house_custom_3story_24		"i_multi_foundation_14x17"
house_custom_3story_25		"i_multi_foundation_14x18"
house_custom_3story_26		"i_multi_foundation_15x10"
house_custom_3story_27		"i_multi_foundation_15x11"
house_custom_3story_28		"i_multi_foundation_15x12"
house_custom_3story_29		"i_multi_foundation_15x13"
house_custom_3story_30		"i_multi_foundation_15x14"
house_custom_3story_31		"i_multi_foundation_15x15"
house_custom_3story_32		"i_multi_foundation_15x16"
house_custom_3story_33		"i_multi_foundation_15x17"
house_custom_3story_34		"i_multi_foundation_15x18"
house_custom_3story_35		"i_multi_foundation_16x11"
house_custom_3story_36		"i_multi_foundation_16x12"
house_custom_3story_37		"i_multi_foundation_16x13"
house_custom_3story_38		"i_multi_foundation_16x14"
house_custom_3story_39		"i_multi_foundation_16x15"
house_custom_3story_40		"i_multi_foundation_16x16"
house_custom_3story_41		"i_multi_foundation_16x17"
house_custom_3story_42		"i_multi_foundation_16x18"
house_custom_3story_43		"i_multi_foundation_17x12"
house_custom_3story_44		"i_multi_foundation_17x13"
house_custom_3story_45		"i_multi_foundation_17x14"
house_custom_3story_46		"i_multi_foundation_17x15"
house_custom_3story_47		"i_multi_foundation_17x16"
house_custom_3story_48		"i_multi_foundation_17x17"
house_custom_3story_49		"i_multi_foundation_17x18"
house_custom_3story_50		"i_multi_foundation_18x13"
house_custom_3story_51		"i_multi_foundation_18x14"
house_custom_3story_52		"i_multi_foundation_18x15"
house_custom_3story_53		"i_multi_foundation_18x16"
house_custom_3story_54		"i_multi_foundation_18x17"
house_custom_3story_55		"i_multi_foundation_18x18"


[DEFNAME Classic_Houses_Convertion]	//Don't make changes here
convertion_i_multi_house_stone_plaster_small	"i_multi_foundation_7x7"
convertion_i_multi_house_stone_small		"i_multi_foundation_7x7"
convertion_i_multi_house_stone_brick_small	"i_multi_foundation_7x7"
convertion_i_multi_house_stone_wood_small	"i_multi_foundation_7x7"
convertion_i_multi_house_wood_plaster_small	"i_multi_foundation_7x7"
convertion_i_multi_house_wood_thatched_small	"i_multi_foundation_7x7"
convertion_i_multi_shop_stone_small		"i_multi_foundation_7x7"
convertion_i_multi_shop_marble_small		"i_multi_foundation_7x7"
convertion_i_multi_tower_wizard			"i_multi_foundation_8x7"
convertion_i_multi_house_patio_sand		"i_multi_foundation_12x8"
convertion_i_multi_villa_2story			"i_multi_foundation_11x11"
convertion_i_multi_cabin_log_2story		"i_multi_foundation_8x13"
convertion_i_multi_house_3room			"i_multi_foundation_14x14"
convertion_i_multi_house_wood_plaster_2story	""
convertion_i_multi_house_stone_plaster_2story	""
convertion_i_multi_shop_blacksmithy_large	"i_multi_foundation_15x14"
convertion_i_multi_house_patio_marble		"i_multi_foundation_15x14"
convertion_i_multi_tower			""
convertion_i_multi_keep				""
convertion_i_multi_castle			""


[FUNCTION AreaStorage]	//Don't make changes here
IF (<ARGS> < 50)
 return 589
ELIF (<ARGS> < 60)
 return 767
ELIF (<ARGS> < 65)
 return 848
ELIF (<ARGS> < 75)
 return 905
ELIF (<ARGS> < 82)
 return 963
ELIF (<ARGS> < 91)
 return 1020
ELIF (<ARGS> < 125)
 return 1465
ELIF (<ARGS> < 133)
 return 1523
ELIF (<ARGS> < 150)
 return 1680
ELIF (<ARGS> < 157)
 return 1738
ELIF (<ARGS> < 170)
 return 1795
ELIF (<ARGS> < 185)
 return 1853
ELIF (<ARGS> < 215)
 return 1876
ELIF (<ARGS> < 460)
 return 2937
ELIF (<ARGS> < 600)
 return 3519
ELIF (<ARGS> < 1000)
 return 5188
ENDIF

//////////////////////////////////////////////////////////////////////////////////

[ITEMDEF 0bd1]
DEFNAME=i_sign_brass
TYPE=t_sign_gump
CAN=CAN_I_DCIGNORELOS
CATEGORY=Decoration - Signs
SUBSECTION=Blank
DESCRIPTION=Brass Blank
DUPELIST=0bd2

ON=@Create
TIMERF 1,HouseCheckPlacement
TIMER=30

ON=@DClick
IF (<LINK.TYPE> == t_multi) || (<LINK.TYPE> == t_multi_custom)
 IF ((<SRC.ACCOUNT.PLEVEL> >= 4) && (<SRC.ISGM>)) || ((<SRC.ACCOUNT.PLEVEL> > 1) && (<SRC.ACCOUNT.PLEVEL> < 4))
   SDIALOG d_house_information
   return 1
 ELIF (<HousePlayerAccess <SRC>> >= 2)
   SRC.SYSMESSAGE @,,1 Welcome back, <SRC.NAME>.
   IF (<DEF.HOUSE_DECAY_TIMER> > 0) && (<isempty <TAG.DEMOLITION_PENDING>>)
    TIMER=<eval <DEF.HOUSE_DECAY_TIMER>*24*60*60>
   ENDIF
   SDIALOG d_house_information
   return 1
 ENDIF
 TAG0.VISITS ++
 SDIALOG d_house_visitor
 return 1
ENDIF

ON=@ClientToolTip
SRC.ADDCLILOC 1042971,A House Sign
SRC.ADDCLILOC 1061639,<NAME>
SRC.ADDCLILOC 1061640,<UID.<LINK.MORE1>.NAME>
SRC.ADDCLILOC <QVAL (<TAG0.Public>)? 1061641:1061642>
return 1

ON=@ContextMenuRequest
IF (<DEF.HOUSE_USE_VENDORS>) && (<TAG0.VENDORS>)
 SRC.AddContextEntry 747,6211
ENDIF

ON=@ContextMenuSelect
IF (<ARGN>==747)
 IF (<DISTANCE> > 5)
  SRC.SYSMESSAGE @,,2 1062429 // You must be within five paces of the house sign to use this option.
  return 1
 ENDIF
 SDIALOG d_house_vendor_list
ENDIF

ON=@Timer
IF !(<MORE2>)
 REF1=<LINK.MORE1>
 IF (<LINK.TAG0.PLACEMENT> != i_gold)
  SERV.NEWITEM <LINK.TAG0.PLACEMENT>
  NEW.CONT=<UID.<LINK.MORE1>.FINDLAYER.21>
 ENDIF
 IF (<REF1.ISONLINE>)
  TRYSRC <REF1> DIALOGCLOSE d_house_placement
 ENDIF
 REF1.NOTICE Too much time has passed and the test house you created has been deleted.  Please try again!
 LINK.REMOVE
ELIF (<DEF.HOUSE_DECAY_TIMER>) || (<TAG0.DEMOLITION_PENDING>)
 FOR <TAG0.Vendors>
  REF1=<TAG0.Vendor<dLOCAL._FOR>>
  IF (<REF1>)
   IF (<REF1.TAG0.Rent.End>)
    REF1.CLEARTAGS Rent.Renew
    LOCAL.HasRentedVendors ++
   ELSE
    REF1.HouseVendorRemove
    REF1.REMOVE
   ENDIF
  ENDIF
 ENDFOR
 IF (<LOCAL.HasRentedVendors>)
  MORE2=
  LINK.MORE1=
  CLEARTAGS Access
  FOR <TAG0.Vendors>
   REF1=<TAG.Vendor<dLOCAL._FOR>>
   IF (<REF1.TAG0.Rent.End>)
    REF1.TAG.DemolishHouse=1
   ENDIF
  ENDFOR
  TIMER=-1
  return 1
 ENDIF
 TRY UID.<MORE2>.NOTICE=Your house '<NAME>' was decayed on <serv.rtime.format %d>/<serv.rtime.format %m>/<serv.rtime.format %Y> <strsub 11 0 <serv.rtime>> because <QVAL (<STRARG <TAG0.DEMOLITION_PENDING>>)? you didn't remove it in a period of <dSTRARG <dTAG0.DEMOLITION_PENDING>> days(s) determined by the Staff to remove this house.:your house has inactive for <dDEF.HOUSE_DECAY_TIMER> days>.
 LINK.f_house_demolish 1
 LINK.REMOVE
ENDIF


[ITEMDEF 0100e]
DEFNAME=i_key_copper
WEIGHT=0.1
TYPE=T_KEY
CATEGORY=Provisions - Miscellaneous
SUBSECTION=Keys
DESCRIPTION=Copper Key

ON=@Click
MESSAGE (<LINK.NAME>)

ON=@DClick
return 1

[FUNCTION HouseCheckPlacement]
REF1=<LINK.MORE1>	//Owner
REF1.HouseRemoveKeys
IF (<LINK.HouseCheckNearArea>)
  REF1.SYSMESSAGE @,,2 501411 // The house could not be created here.  Either something is blocking the house, or the house would not be on valid terrain.
  IF !(<REF1.ISGM>)
    IF (<LINK.TAG0.PLACEMENT> != i_gold)
     SERV.NEWITEM <LINK.TAG.PLACEMENT>
     NEW.CONT=<REF1.FINDLAYER.21>
    ENDIF
    LINK.REMOVE
    return 1
  ENDIF
ELSE
  REF1.SYSMESSAGE @,,2 1011576
ENDIF
TRYSRC <REF1> DIALOG d_house_placement


[FUNCTION HouseRemoveKeys]
IF (<FINDLAYER.21.RESCOUNT>)
FOR 0 <FINDLAYER.21.RESCOUNT>
 REF1=<FINDLAYER.21.FINDCONT(<LOCAL._FOR>)>
 IF (<REF1.DISPID>==i_key_copper)
  IF STRMATCH("t_multi*","<REF1.LINK.TYPE>")
   REF1.REMOVE
  ENDIF
 ENDIF
ENDFOR
ENDIF
IF (<FINDLAYER.29.RESCOUNT>)
FOR 0 <FINDLAYER.29.RESCOUNT>
 REF1=<FINDLAYER.29.FINDCONT(<LOCAL._FOR>)>
 IF (<REF1.DISPID>==i_key_copper)
  IF STRMATCH("t_multi*","<REF1.LINK.TYPE>")
   REF1.REMOVE
  ENDIF
 ENDIF
ENDFOR
ENDIF

[DIALOG d_house_placement]
110,100
noclose

resizepic 0 0 5054 420 280
gumppictiled 10 10 400 20 2624
checkertrans 10 10 400 20
dhtmlgump 10 10 400 20 0 0 <DEF.L1>basefont color="#f70000"<DEF.R1><DEF.CENTER>WARNING
gumppictiled 10 40 400 200 2624
checkertrans 10 40 400 200
dhtmlgump 10 40 400 200 0 1 <DEF.L1>basefont color="#ffc600"<DEF.R1>You are about to place a new house.  Placing this house will <DEF.U>condemn<DEF.UE> any and all of your other houses that you may have.<DEF.BR><DEF.BR>In addition, you will not be able to place another house or have one transferred to you for one (1) real-life week.<DEF.BR><DEF.BR>Once you accept these terms, these effects cannot be reversed.  Re-deeding or transferring your new house will <DEF.U>not<DEF.UE> uncondemn your other house(s) nor will the one week timer be removed.<DEF.BR><DEF.BR>If you are absolutely certain you wish to proceed, click the button next to OKAY below.  If you do not wish to trade for this house, click CANCEL.
gumppictiled 10 250 400 20 2624
checkertrans 10 250 400 20
button 10 250 4005 4007 1 0 1
dtext 40 250 1152 OKAY
button 210 250 4005 4007 1 0 0
dtext 240 250 1152 CANCEL

[DIALOG d_house_placement BUTTON]
ON=0
IF (<LINK.TAG0.PLACEMENT> != i_gold)
 SERV.NEWITEM <LINK.TAG0.PLACEMENT>
 NEW.BOUNCE
ENDIF
LINK.REMOVE

ON=1
IF (<LINK.TAG0.PLACEMENT> == i_gold)
  IF (<SRC.ISGM>)
   SRC.SYSMESSAGE @,,1 <LINK.VALUE> gold would have been withdrawn from your bank if you were not a GM.
  ELIF (<SRC.BANKBALANCE> < <LINK.VALUE>)
   SRC.SYSMESSAGE @,,1 You do not have the funds avaible in your bankbox to purchase this house. Try placing a smaller house, or adding gold to your bankbox.
   LINK.REMOVE
   return 1
  ELSE
   SRC.GOLD -= <LINK.VALUE>
   SRC.UPDATE
   SRC.SYSMESSAGE @,,1 <LINK.VALUE> gold has been withdrawn from your bank box.
  ENDIF
ENDIF
MORE2=<SRC>
LINK.MORE2=<UID>
LINK.TAG.PLACEMENT=
TIMER=<eval <DEF.HOUSE_DECAY_TIMER>*24*60*60>
TAG.BUILTON=<serv.rtime.format %d>-<serv.rtime.format %m>-<serv.rtime.format %Y> <strsub 11 8 <serv.rtime>>
TAG.STORAGE_LIMIT=<AreaStorage <AREA>>
REGION.EVENTS=+r_house_system
IF (<LINK.TYPE>==t_multi_custom)
 LINK.HousePlaceFoundationStairs
ENDIF
IF !(<SRC.ISGM>) && (<DEF0.PLACEMENT_WAITING_PERIOD>)
 SRC.TAG.House.PlacementDelay=<eval <SERV.TIME>+(<DEF0.PLACEMENT_WAITING_PERIOD>*864000)+36000>
ENDIF

[FUNCTION HousePlaceFoundationStairs]
TAG.COMPONENTS=<COMPONENTS>
ARGS=<MULTIREGION>
FOR <ARGV2> <eval <ARGV0>+1>
 ADDITEM 1873,<LOCAL._FOR>,<ARGV3>,0
ENDFOR
COMMIT

//////////////////////////////////////////////////////////////////////////////////


[FUNCTION RenderHouseDialogBackground]
resizepic 0 0 5054 420 440
gumppictiled 10 10 400 100 2624
checkertrans 10 10 400 100
gumppictiled 10 120 400 260 2624
checkertrans 10 120 400 260
gumppictiled 10 390 400 40 2624
checkertrans 10 390 400 40
button 250 410 4005 4007 1 0 0
dtext 285 410 1152 CLOSE
gumppic 10 10 100
dhtmlgump 30 43 105 40 0 0 <DEF.CENTER><NAME><DEF.CENTERE>
IF (<HousePlayerAccess <SRC>> >= 2)
 button 150 10 4005 4007 1 0 1
 dtext 195 10 1152 INFORMATION
 button 150 30 4005 4007 1 0 2
 dtext 195 30 1152 SECURITY
 button 150 50 4005 4007 1 0 3
 dtext 195 50 1152 STORAGE
 button 150 70 4005 4007 1 0 4
 dtext 195 70 1152 CUSTOMIZE
 button 150 90 4005 4007 1 0 5
 dtext 195 90 1152 OWNERSHIP
 IF !(<TAG0.Public>) && (<DEF.HOUSE_USE_DEPTH_OF_FIELD>)
  button 10 390 4005 4007 1 0 9
  dtext 45 390 1152 Grant Access
  button 10 410 4005 4007 1 0 10
  dtext 45 410 1152 Revoke Access
 ELIF (<DEF.HOUSE_USE_BAN_ENGINE>)
  button 10 390 4005 4007 1 0 7
  dtext 45 390 1152 Banish
  button 10 410 4005 4007 1 0 8
  dtext 45 410 1152 Lift a Ban
 ENDIF
 IF (<DEF.ALLOW_BANKING>)
  button 250 390 4005 4007 1 0 6
  dtext 285 390 1152 Open Bank Box
 ENDIF
ENDIF


[FUNCTION DefaultHouseDialogButtons]
IF (<ARGS>==1)
  DIALOG d_house_information
  return 1
ELIF (<ARGS>==2)
  DIALOG d_house_security
  return 1
ELIF (<ARGS>==3)
  DIALOG d_house_storage
  return 1
ELIF (<ARGS>==4)
  DIALOG d_house_customize
  return 1
ELIF (<ARGS>==5)
  DIALOG d_house_ownership
  return 1
ELIF (<ARGS>==6)
  IF (<DEF.ALLOW_BANKING>)
   IF (<DISTANCE> < 15)
    SRC.BANKSELF
   ELSE
    SRC.SYSMESSAGE @,,1 You are too far away from the house sign.
   ENDIF
  ENDIF
  return 1
ELIF (<ARGS>==7)
  IF (<DEF.HOUSE_USE_BAN_ENGINE>)
   SRC.SYSMESSAGE @,,1 Target the individual to ban from this house.
   SRC.TARGETF f_house_banish <UID>
  ENDIF
  return 1
ELIF (<ARGS>==8)
  DIALOG d_house_security 2,-1,1
  return 1
ELIF (<ARGS>==9)
  IF (<DEF.HOUSE_USE_DEPTH_OF_FIELD>)
   SRC.SYSMESSAGE @,,1 Target the person you would like to grant access to.
   SRC.TARGETF f_house_grant_access <UID>
  ENDIF
  return 1
ELIF (<ARGS>==10)
  DIALOG d_house_security 2,1,1
  return 1
ENDIF


//////////////////////////////////////////////////////////////////////////////////

[DIALOG d_house_information]
50,40

page 0
RenderHouseDialogBackground
button 150 10 4006 4007 1 0 1
dtext 195 10 5 INFORMATION

page 1
dtext 20 130 1152 Owned By: 
dtext 210 130 1152 <UID.<MORE2>.NAME>
dtext 20 170 <QVAL (<TAG0.DEMOLITION_PENDING>)? 37 This house is improperly:5 This house is properly> placed.
dtext 20 190 5 This house is of modern design.
dtext 20 210 5 This is a <QVAL (<LINK.TYPE> != t_multi_custom)? pre:custom>-built house.
dtext 20 230 5 This house is <QVAL !(<TAG0.Public>)? private:open to the public>.
IF (<TAG0.DEMOLITION_PENDING>)
 dtext 20 250 37 This house is Condemned.
 dtext 20 270 37 This house will decay in: <eval <TIMER>/86400> days, <eval (<TIMER>%86400)/3600> hours and <eval ((<TIMER>%86400)%3600)/60> minutes.
ELIF (<DEF.HOUSE_DECAY_TIMER>) && (<TIMER> > 0)
 dtext 20 250 5 This house will decay in: <eval <TIMER>/86400> days, <eval (<TIMER>%86400)/3600> hours and <eval ((<TIMER>%86400)%3600)/60> minutes.
ELSE
 dtext 20 250 5 This house is Automatically refreshed.
ENDIF
dtext 20 290 5 Built On:
dtext 250 290 1152 <TAG0.BUILTON>
IF (<TAG0.LastTraded>)
 dtext 20 310 5 Last Traded:
 dtext 250 310 1152 <TAG0.LastTraded>
ENDIF
dtext 20 330 5 House Value:
dtext 250 330 1152 <eval (<LINK.HouseValue>*<DEF.DEMOLISH_REFUND_PERCENT>)/100> gps
dtext 20 360 5 Number of visits this building has had:
dtext 350 360 1152 <dTAG0.VISITS>

[DIALOG d_house_information BUTTON]
ON=1 10
DefaultHouseDialogButtons <ARGN>


//////////////////////////////////////////////////////////////////////////////////


[DIALOG d_house_security]
50,40

page 0
RenderHouseDialogBackground
button 150 30 4006 4007 1 0 2
dtext 195 30 5 SECURITY

page 1
IF (<IsOwner <SRC>>)
 button 10 150 4005 4007 1 0 11
 dtext 45 150 1152 Add a Co-Owner
 button 10 170 4005 4007 1 0 14
 dtext 45 170 1152 Remove a Co-Owner
 button 10 190 4005 4007 1 0 21
 dtext 45 190 1152 Clear Co-Owner List
ELSE
 dtext 45 150 998 Add a Co-Owner
 dtext 45 170 998 Remove a Co-Owner
 dtext 45 190 998 Clear Co-Owner List
ENDIF

button 10 220 4005 4007 1 0 15
dtext 45 220 1152 View Friends List
IF (<HousePlayerAccess <SRC>> >= 3)
 button 10 130 4005 4007 1 0 13
 dtext 45 130 1152 View Co-Owner List
 button 10 240 4005 4007 1 0 12
 dtext 45 240 1152 Add a Friend
 button 10 260 4005 4007 1 0 16
 dtext 45 260 1152 Remove a Friend
 button 10 280 4005 4007 1 0 22
 dtext 45 280 1152 Clear Friend List
ELSE
 dtext 45 130 998 View Co-Owner List
 dtext 45 240 998 Add a Friend
 dtext 45 260 998 Remove a Friend
 dtext 45 280 998 Clear Friend List
ENDIF

IF !(<TAG0.Public>) && (<DEF.HOUSE_USE_DEPTH_OF_FIELD>)
 button 10 310 4005 4007 1 0 19
 dtext 45 310 1152 View Access List
 IF (<HousePlayerAccess <SRC>> >= 3)
  button 10 330 4005 4007 1 0 24
  dtext 45 330 1152 Clear Access List
 ELSE
  dtext 45 330 998 Clear Access List
 ENDIF
ELIF (<DEF.HOUSE_USE_BAN_ENGINE>)
 button 10 310 4005 4007 1 0 17
 dtext 45 310 1152 View Ban List
 IF (<HousePlayerAccess <SRC>> >= 3)
  button 10 330 4005 4007 1 0 23
  dtext 45 330 1152 Clear Ban List
 ELSE
  dtext 45 330 998 Clear Ban List
 ENDIF
ENDIF

IF (<IsOwner <SRC>>)
 IF !(<TAG0.Public>)
  dtext 245 130 5 Change to Private
  button 210 150 4005 4007 1 0 31
  dtext 245 150 1152 Change to Public
 ELSE
  button 210 130 4005 4007 1 0 31
  dtext 245 130 1152 Change to Private
  dtext 245 150 5 Change to Public
 ENDIF
ELSE
 IF !(<TAG0.Public>)
  dtext 245 130 5 Change to Private
  dtext 245 150 998 Change to Public
 ELSE
  dtext 245 130 998 Change to Private
  dtext 245 150 5 Change to Public
 ENDIF
ENDIF

page 2
IF (0<ARGS>)
 RenderDialogAccessList <ARGS>
ENDIF


[DIALOG d_house_security BUTTON]
ON=1 10
DefaultHouseDialogButtons <ARGN>

ON=11
SRC.SYSMESSAGE @,,1 Target the person you wish to name a co-owner of your household.
SRC.TARGETF f_house_add_coowner <UID>

ON=12
SRC.SYSMESSAGE @,,1 Target the person you wish to name a friend of your household.
SRC.TARGETF f_house_add_friend <UID>

ON=13 20
IF (<ARGN>==13)		//Co-Owner View
 DIALOG d_house_security 2,3
ELIF (<ARGN>==14)	//Co-Owner Remove
 DIALOG d_house_security 2,3,1
ELIF (<ARGN>==15)	//Friend View
 DIALOG d_house_security 2,2
ELIF (<ARGN>==16)	//Friend Remove
 DIALOG d_house_security 2,2,1
ELIF (<ARGN>==17)	//Ban View
 DIALOG d_house_security 2,-1
ELIF (<ARGN>==18)	//Ban Remove
 DIALOG d_house_security 2,-1,1
ELIF (<ARGN>==19)	//Access View
 DIALOG d_house_security 2,1
ELIF (<ARGN>==20)	//Access Remove
 DIALOG d_house_security 2,1,1
ENDIF

ON=21
SDIALOG d_house_clear_coowners

ON=22
DIALOG d_house_clear_friends

ON=23
DIALOG d_house_clear_bans

ON=24
DIALOG d_house_clear_access_list

ON=31
IF !(<IsOwner <SRC>>)
 return 1
ELIF !(<TAG0.Public>)
 TAG.Public=1
 RESENDTOOLTIP
 DIALOG d_house_type 1
ELSE
 IF (<DEF.HOUSE_USE_VENDORS>) && (<DEF.HOUSE_VENDORS_PUBLIC_ONLY>) && (<TAG0.VENDORS>)
  DIALOG d_house_type 3
 ELSE
  TAG.Public=
  RESENDTOOLTIP
  IF (<DEF.SIGN_CHANGE_PUBLIC_ONLY>) && (<DISPID> != 0bd2)
   DISPID=0bd2
   UPDATEX
  ENDIF
  DIALOG d_house_type 2
 ENDIF
ENDIF

ON=100 199
IF (<HousePlayerAccess <SRC>> < 2)
 return 1
ENDIF
REF1=<HouseGetAccessRef -1,<eval <ARGN>-100>>
IF (<REF1>)
 SRC.SYSMESSAGE @,,1 The ban is lifted.
 HouseUpdateAccessListNumber <TAG.Access.<REF1>>
 TRY TAG.Access.<REF1>=
 TAG0.Access.Total.-1 --
ENDIF
SDIALOG d_house_security 2,-1,1

ON=200 299
IF (<HousePlayerAccess <SRC>> < 3)
 return 1
ENDIF
REF1=<HouseGetAccessRef 1,<eval <ARGN>-200>>
IF (<REF1>)
 SRC.SYSMESSAGE @,,1 The invitation has been revoked.
 HouseUpdateAccessListNumber <TAG.Access.<REF1>>
 TRY TAG.Access.<REF1>=
 TAG0.Access.Total.1 --
ENDIF
SDIALOG d_house_security 2,1,1

ON=300 399
IF (<HousePlayerAccess <SRC>> < 3)
 return 1
ENDIF
REF1=<HouseGetAccessRef 2,<eval <ARGN>-300>>
IF (<REF1>)
 SRC.SYSMESSAGE @,,1 Friend removed from list.
 REF1.NOTICE=You got removed from the Friend access list of the house '<NAME>' on <serv.rtime.format %d>/<serv.rtime.format %m>/<serv.rtime.format %Y> <strsub 11 0 <serv.rtime>>.
 HouseUpdateAccessListNumber <TAG.Access.<REF1>>
 TRY TAG.Access.<REF1>=
 TAG0.Access.Total.2 --
ENDIF
SDIALOG d_house_security 2,2,1

ON=400 499
IF (<HousePlayerAccess <SRC>> < 3)
 return 1
ENDIF
REF1=<HouseGetAccessRef 3,<eval <ARGN>-400>>
IF (<REF1>)
 SRC.SYSMESSAGE @,,1 Co-owner removed from list.
 REF1.NOTICE=You got removed from the Co-Owner access list of the house '<NAME>' on <serv.rtime.format %d>/<serv.rtime.format %m>/<serv.rtime.format %Y> <strsub 11 0 <serv.rtime>>.
 HouseUpdateAccessListNumber <TAG.Access.<REF1>>
 TRY TAG.Access.<REF1>=
 TAG0.Access.Total.3 --
ENDIF
SDIALOG d_house_security 2,3,1


[FUNCTION RenderDialogAccessList]
LOCAL.ACCESS=<ARGV[0]>
IF (0<ARGV[1]>)
 LOCAL.REMOVE=<ARGV[1]>
 LOCAL.BUTTON=<eval (<QVAL (<ARGV[0]>!=-1)? <ARGV[0]>:<eval <ARGV[0]>+1>>+1)*100>
ENDIF
ARGS=<HouseAccessList <ARGV[0]>>

dhtmlgump 10 120 400 20 0 0 <DEF.CENTER><DEF.BFONT_WHITE><DEF.Access_<dLOCAL.ACCESS>> LIST<DEF.CENTERE>
LOCAL.PAGE=2
LOCAL.Y=150
IF (<TAG0.Access.Total.<dLOCAL.ACCESS>>)
  IF !(<LOCAL.REMOVE>)
    FOR <TAG0.Access.Total.<dLOCAL.ACCESS>>
     CALL RenderDialogAccessListPage
     dtext 15 <dLOCAL.Y> 1152 * <UID.<ARGV<dLOCAL._FOR>>.NAME>
     LOCAL.Y += 20
    ENDFOR
  ELSE
    FOR <TAG0.Access.Total.<dLOCAL.ACCESS>>
     CALL RenderDialogAccessListPage
     REF1=<ARGV[<LOCAL._FOR>]>
     dtext 45 <dLOCAL.Y> 1152 * <REF1.NAME>
     button 10 <dLOCAL.Y> 4005 4007 1 0 <eval <STREAT <TAG0.Access.<REF1>>>+<dLOCAL.BUTTON>>
     LOCAL.Y += 20
    ENDFOR
  ENDIF
ENDIF

[FUNCTION RenderDialogAccessListPage]
IF (<LOCAL.Y> > 340)
 LOCAL.Y=150
 button 40 360 4005 4007 0 <eval <LOCAL.PAGE>+1> 0
 LOCAL.PAGE ++
 page <LOCAL.PAGE>
 button 10 360 4014 4016 0 <eval <LOCAL.PAGE>-1> 0
 dhtmlgump 10 120 400 20 0 0 <DEF.CENTER><DEF.BFONT_WHITE><DEF.Access_<dLOCAL.ACCESS>> LIST<DEF.CENTERE>
ENDIF

[DEFNAME AccessName]
Access_-1	"BAN"
Access_1	"ACCESS"
Access_2	"FRIENDS"
Access_3	"CO-OWNER"

[FUNCTION HouseUpdateAccessListNumber]
LOCAL.ACCESS=<ARGV[0]>
LOCAL.NUMBER=<ARGV[1]>
FOR 0 <eval <TAGCOUNT>-1>
 IF !STRCMP("<STRSUB 0 6 <TAGAT.<LOCAL._FOR>.KEY>>","access")
   IF (<LOCAL.ACCESS>==<STRARG <TAGAT.<LOCAL._FOR>.VAL>>) && (<LOCAL.NUMBER> < 0<STREAT <TAGAT.<LOCAL._FOR>.VAL>>)
    ARGS=<TAGAT.<LOCAL._FOR>.VAL>
    TRY TAG.<TAGAT.<LOCAL._FOR>.KEY>=<ARGV[0]>,<eval <ARGV[1]>-1>
   ENDIF
 ENDIF
ENDFOR


//////////////////////////////////////////////////////////////////////////////////


[DIALOG d_house_storage]
50,40

page 0
RenderHouseDialogBackground
button 150 50 4006 4007 1 0 3
dtext 195 50 5 STORAGE

page 1
dhtmlgump 10 130 400 20 0 0 <DEF.CENTER><DEF.BFONT_WHITE>HOUSE STORAGE SUMMARY<DEF.CENTERE>
IF (<TAG0.STORAGE_INCREASE>)
 dtext 10 150 1152 Increased Storage
 dtext 310 150 1152 <dTAG0.STORAGE_INCREASE>%
ENDIF
dtext 10 170 1152 Maximum Secure Storage
dtext 310 170 1152 <House_MaxSecureStorage>
//dtext 10 190 998 Used by Moving Crate
//dtext 310 190 998 0
dtext 10 210 1152 Used by Lockdowns
dtext 310 210 1152 <dTAG0.LOCKED_ITEMS>
dtext 10 230 1152 Used by Secure Containers
dtext 310 230 1152 <dTAG0.SECURE_CONT>
dtext 10 250 1152 Available Storage
dtext 310 250 1152 <House_AvaibleStorage>
dtext 10 290 1152 Maximum Lockdowns
dtext 310 290 1152 <House_MaxLockdowns>
dtext 10 310 1152 Available Lockdowns
dtext 310 310 1152 <House_AvaibleLockdowns>
IF (<DEF.HOUSE_USE_VENDORS>)
 dtext 10 350 1152 Vendor Count
 dtext 310 350 1152 <dTAG0.VENDORS> / <HouseMaxVendors>
ENDIF


[DIALOG d_house_storage BUTTON]
ON=1 10
DefaultHouseDialogButtons <ARGN>


//////////////////////////////////////////////////////////////////////////////////


[DIALOG d_house_customize]
50,40

page 0
RenderHouseDialogBackground
button 150 70 4006 4007 1 0 4
dtext 195 70 5 CUSTOMIZE

page 1
//dtext 45 180 998 Relocate Moving Crate
IF (<IsOwner <SRC>>)
  IF (<DEF.HOUSE_AOS_CUSTOMIZATION>) && (<DEF.HOUSE_ALLOW_CONVERTION>) && !(<isempty <DEF.convertion_<LINK.DISPID>>>)
   dtext 45 120 1152 Convert Into Customizable House
   button 10 120 4005 4007 1 0 20
  ELSE
   dtext 45 120 998 Convert Into Customizable House
  ENDIF
  IF (<DEF.HOUSE_AOS_CUSTOMIZATION>) && (<LINK.TYPE>==t_multi_custom)
   dtext 45 160 1152 Customize This House
   button 10 160 4005 4007 1 0 21
   dtext 45 230 1152 Change House Sign Hanger
   button 10 230 4005 4007 1 0 24
   dtext 45 250 1152 Change Signpost
   button 10 250 4005 4007 1 0 25
   dtext 45 280 1152 Change Foundation Style
   button 10 280 4005 4007 1 0 26
  ELSE
   dtext 45 160 998 Customize This House
   dtext 45 230 998 Change House Sign Hanger
   dtext 45 250 998 Change Signpost
   dtext 45 280 998 Change Foundation Style
  ENDIF
  IF ((<DEF.SIGN_CHANGE_PUBLIC_ONLY>) && (<TAG0.Public>)) || !(<DEF.SIGN_CHANGE_PUBLIC_ONLY>)
   button 10 210 4005 4007 1 0 23
   dtext 45 210 1152 Change House Sign
  ELSE
   dtext 45 210 998 Change House Sign
  ENDIF
  button 10 310 4005 4007 1 0 27
  dtext 45 310 1152 Rename House
ELSE
  dtext 45 120 998 Convert Into Customizable House
  dtext 45 160 998 Customize This House
  dtext 45 210 998 Change House Sign
  dtext 45 230 998 Change House Sign Hanger
  dtext 45 250 998 Change Signpost
  dtext 45 280 998 Change Foundation Style
  dtext 45 310 998 Rename House
ENDIF


[DIALOG d_house_customize BUTTON]
ON=1 10
DefaultHouseDialogButtons <ARGN>

ON=20 27
IF (<DISTANCE> > 15)
 SRC.SYSMESSAGE @,,1 You are too far away from the house sign.
 return 1
ELIF (<IsOwner <SRC>>)
 IF (<ARGN>==20)
   IF (<DEF.HOUSE_AOS_CUSTOMIZATION>) && (<DEF.HOUSE_ALLOW_CONVERTION>) && !(<isempty <DEF.convertion_<LINK.DISPID>>>)
    SDIALOG d_house_convertion
   ENDIF
   return 1
 ELIF (<ARGN>==21)
   IF (<DEF.HOUSE_AOS_CUSTOMIZATION>) && (<LINK.TYPE> == t_multi_custom)
    IF (<SRC.ACCOUNT.RESDISP> < 3)
     SRC.SYSMESSAGE @,,1 Sorry, your account must have the Age of Shadows update to do this.
     return 1
    ELIF (<LINK.DESIGNER>)
     SRC.SYSMESSAGE @,,1 <UID.<LINK.DESIGNER>.NAME> is designing this house.
     return 1
    ELIF !(<SRC.ISEVENT.e_house_customize>)
     SRC.EVENTS +e_house_customize
     SRC.DSPEECH +spk_house_customize
     LINK.F_InvisTeleporters
    ENDIF
    REF1=<LINK>
    FORCLIENTS 18
      IF (<REGION.UID>==<REF1>)
       GOUID <REF1.MORE2>
       MOVE S
       FIX
      ENDIF
    ENDFOR
    SRC.GO <P>
    LINK.CUSTOMIZE
   ENDIF
   return 1
 ELIF (<ARGN>==22)
   //Nothing
 ELIF (<ARGN>==23)
   SDIALOG d_house_features 1	//Change House Sign
 ELIF (<ARGN>==24)
   IF (<LINK.TYPE>==t_multi_custom)
    SDIALOG d_house_features 4	//Change House Sign Hanger
   ENDIF
 ELIF (<ARGN>==25)
   IF (<LINK.TYPE>==t_multi_custom)
    SDIALOG d_house_features 5	//Change Signpost
   ENDIF
 ELIF (<ARGN>==26)
   IF (<LINK.TYPE>==t_multi_custom)
    SDIALOG d_house_features 7	//Change Foundation Style
   ENDIF
 ELIF (<ARGN>==27)
   SRC.SYSMESSAGE @,,1 What dost thou wish the sign to say?
   SRC.PROMPTCONSOLE f_change_house_name
 ENDIF
ENDIF


[FUNCTION f_change_house_name]
IF (<TARG.TYPE>==t_sign_gump)
  IF !(<isempty <ARGS>>)
    IF STRMATCH("[a-z]*","<ARGS>")
     SYSMESSAGE @,,1 Sign changed.
     TARG.NAME=<ARGS>
     TARG.RESENDTOOLTIP
    ELSE
     SYSMESSAGE @,,1 Invalid name.
    ENDIF
  ELSE
    SYSMESSAGE @,,1 Cancelled.
  ENDIF
  TARG.DIALOG d_house_customize
ELSE
  SYSMESSAGE @,,1 An error has found, please try again.
ENDIF


//////////////////////////////////////////////////////////////////////////////////


[DIALOG d_house_ownership]
50,40

page 0
RenderHouseDialogBackground
button 150 90 4006 4007 1 0 5
dtext 195 90 5 OWNERSHIP

page 1
IF (<IsOwner <SRC>>)
 button 10 130 4005 4007 1 0 21
 dtext 45 130 1152 Demolish House
 button 10 150 4005 4007 1 0 22
 dtext 45 150 1152 Trade House
ELSE
 dtext 45 130 998 Demolish House
 dtext 45 150 998 Trade House
ENDIF
//dtext 45 190 998 Make Primary

IF (<SRC.ISGM>)
 dtext 125 250 1152 GAME MASTER OPTIONS
 dtext 45 300 1152 Reason:
 gumppictiled 90 300 310 36 9264
 checkertrans 90 300 310 36
 IF (<isempty <TAG.DEMOLITION_PENDING>>)
  button 10 280 4005 4007 1 0 31
  dtext 45 280 1152 Pend this house for Demolition on __ day(s)
  dtextentry 253 280 15 20 1152 0 <dDEF.DEMOLITION_PEND_DECAY>
  dtextentry 93 300 300 36 1152 1
 ELSE
  button 10 280 4005 4007 1 0 32
  dtext 45 280 5 Cancel Demolition Pending State
  dhtmlgump 93 300 300 36 0 0 <DEF.BFONT_WHITE><QVAL (<isempty <STREAT <TAG.DEMOLITION_PENDING>>>)? Not specified:<STREAT <TAG.DEMOLITION_PENDING>>>
 ENDIF
ENDIF


[DIALOG d_house_ownership BUTTON]
ON=1 10
DefaultHouseDialogButtons <ARGN>

ON=21
IF (<IsOwner <SRC>>)
 SDIALOG d_house_demolish
ENDIF

ON=22
IF !(<SRC.ISGM>)
 IF !(<IsOwner <SRC>>)
  return 1
 ELIF (<TAG0.VENDORS>)
  SRC.SYSMESSAGE @,,1 You cannot trade this house while you still have personal vendors inside.
  return 1
 ELIF (<TAG0.DEMOLITION_PENDING>)
  SRC.SYSMESSAGE @,,1 This house has been marked for demolition, and it cannot be transferred.
  return 1
 ENDIF
ENDIF
SRC.DIALOGCLOSE d_house_ownership
SRC.SYSMESSAGE @,,1 Target the person to whom you wish to give this house.
SRC.TARGETF f_house_transfer <UID>

ON=31 32
IF (<SRC.ACCOUNT.PLEVEL> < 2)
  return 1
ELIF (<ARGN>==31)
  IF (<isnum <ARGTXT[0]>>)
   IF (<ARGTXT[0]> < 100)
    SRC.SYSMESSAGE @,,1 This house is now Pended for Demolition. It will decay automatically in <dARGTXT[0]> days if the Owner not demolish it.
    TIMER=<ARGTXT[0]>*24*60*60
    TAG.DEMOLITION_PENDING=<ARGTXT[0]> <ARGTXT[1]>
    SDIALOG d_house_ownership
    TRY UID.<MORE2>.NOTICE=Your house '<SRC.TARG.NAME>' was Pended for Demolition on <serv.rtime.format %d>/<serv.rtime.format %m>/<serv.rtime.format %Y> <strsub 11 0 <serv.rtime>> and it will decay in <dARGTXT[0]> days if you not demolish it manually.
   ENDIF
  ENDIF
ELIF (<ARGN>==32)
  SRC.SYSMESSAGE @,,1 You cancel the Demolition Pending state of this house.
  TAG.DEMOLITION_PENDING=
  SDIALOG d_house_ownership
  TRY UID.<MORE2>.NOTICE=Your house Demolition Pending state for '<SRC.TARG.NAME>' was canceled on <serv.rtime.format %d>/<serv.rtime.format %m>/<serv.rtime.format %Y> <strsub 11 0 <serv.rtime>> and it will not be condemned anymore.
  IF (<DEF.HOUSE_DECAY_TIMER> > 0)
   TIMER=<eval <DEF.HOUSE_DECAY_TIMER>*24*60*60>
  ELSE
   TIMER=-1
  ENDIF
ENDIF


//////////////////////////////////////////////////////////////////////////////////


[DIALOG d_house_vendor_list]
50,40

page 0
RenderHouseDialogBackground

page 1
dhtmlgump 10 120 400 20 0 0 <DEF.CENTER><DEF.BFONT_WHITE>SHOPS<DEF.CENTERE>
LOCAL.Y=150
LOCAL.PAGE=1
FOR <TAG0.VENDORS>
 dtext 45 <LOCAL.Y> 5 <UID.<TAG0.VENDOR<dLOCAL._FOR>>.TAG.NAMESHOP>
 button 10 <LOCAL.Y> 4005 4007 1 0 <eval <LOCAL._FOR>+100>
 LOCAL.Y += 20
 CALL RenderDialogVendorListPage
ENDFOR

[FUNCTION RenderDialogVendorListPage]
IF (<LOCAL.Y> > 340)
 LOCAL.Y=150
 button 40 360 4005 4007 0 <eval <LOCAL.PAGE>+1> 0
 LOCAL.PAGE ++
 page <LOCAL.PAGE>
 button 10 360 4014 4016 0 <eval <LOCAL.PAGE>-1> 0
 dhtmlgump 10 120 400 20 0 0 <DEF.CENTER><DEF.BFONT_WHITE>SHOPS<DEF.CENTERE>
ENDIF


[DIALOG d_house_vendor_list BUTTON]
ON=1 10
DefaultHouseDialogButtons <ARGN>

ON=100 200
SRC.DClick <TAG0.VENDOR<eval <ARGN>-100>>


//////////////////////////////////////////////////////////////////////////////////


[DIALOG d_house_features]
50,40

page 0
RenderHouseDialogBackground

page 1	//Change House Sign 1/3
button 10 360 4005 4007 0 2 0
button 30 130 4005 4007 1 0 11
tilepic 50 130 2980
button 90 130 4005 4007 1 0 12
tilepic 110 130 2982
button 150 130 4005 4007 1 0 13
tilepic 170 130 2984
button 210 130 4005 4007 1 0 14
tilepic 230 130 2986
button 270 130 4005 4007 1 0 15
tilepic 290 130 2988
button 330 130 4005 4007 1 0 16
tilepic 350 130 2990
button 30 190 4005 4007 1 0 17
tilepic 50 190 2992
button 90 190 4005 4007 1 0 18
tilepic 110 190 2994
button 150 190 4005 4007 1 0 19
tilepic 170 190 2996
button 210 190 4005 4007 1 0 20
tilepic 230 190 2998
button 270 190 4005 4007 1 0 21
tilepic 290 190 3000
button 330 190 4005 4007 1 0 22
tilepic 350 190 3002
button 30 250 4005 4007 1 0 23
tilepic 50 250 3004
button 90 250 4005 4007 1 0 24
tilepic 110 250 3006
button 150 250 4005 4007 1 0 25
tilepic 170 250 3008
button 210 250 4005 4007 1 0 26
tilepic 230 250 3010
button 270 250 4005 4007 1 0 27
tilepic 290 250 3012
button 330 250 4005 4007 1 0 28
tilepic 350 250 3014

page 2	//Change House Sign 2/3
button 10 360 4005 4007 0 3 0
button 30 130 4005 4007 1 0 29
tilepic 50 130 3016
button 90 130 4005 4007 1 0 30
tilepic 110 130 3018
button 150 130 4005 4007 1 0 31
tilepic 170 130 3020
button 210 130 4005 4007 1 0 32
tilepic 230 130 3022
button 270 130 4005 4007 1 0 33
tilepic 290 130 3024
button 330 130 4005 4007 1 0 34
tilepic 350 130 3026
button 30 190 4005 4007 1 0 35
tilepic 50 190 3028
button 90 190 4005 4007 1 0 36
tilepic 110 190 3030
button 150 190 4005 4007 1 0 37
tilepic 170 190 3032
button 210 190 4005 4007 1 0 38
tilepic 230 190 3034
button 270 190 4005 4007 1 0 39
tilepic 290 190 3036
button 330 190 4005 4007 1 0 40
tilepic 350 190 3038
button 30 250 4005 4007 1 0 41
tilepic 50 250 3040
button 90 250 4005 4007 1 0 42
tilepic 110 250 3042
button 150 250 4005 4007 1 0 43
tilepic 170 250 3044
button 210 250 4005 4007 1 0 44
tilepic 230 250 3046
button 270 250 4005 4007 1 0 45
tilepic 290 250 3048
button 330 250 4005 4007 1 0 46
tilepic 350 250 3050

page 3	//Change House Sign 3/3
button 10 360 4005 4007 0 1 0
button 30 130 4005 4007 1 0 47
tilepic 50 130 3052
button 90 130 4005 4007 1 0 48
tilepic 110 130 3054
button 150 130 4005 4007 1 0 49
tilepic 170 130 3056
button 210 130 4005 4007 1 0 50
tilepic 230 130 3058
button 270 130 4005 4007 1 0 51
tilepic 290 130 3060
button 330 130 4005 4007 1 0 52
tilepic 350 130 3062
button 30 190 4005 4007 1 0 53
tilepic 50 190 3064
button 90 190 4005 4007 1 0 54
tilepic 110 190 3066
button 150 190 4005 4007 1 0 55
tilepic 170 190 3068
button 210 190 4005 4007 1 0 56
tilepic 230 190 3070
button 270 190 4005 4007 1 0 57
tilepic 290 190 3072
button 330 190 4005 4007 1 0 58
tilepic 350 190 3074
button 30 250 4005 4007 1 0 59
tilepic 50 250 3076
button 90 250 4005 4007 1 0 60
tilepic 110 250 3078
button 150 250 4005 4007 1 0 61
tilepic 170 250 3080
button 210 250 4005 4007 1 0 62
tilepic 230 250 3082
button 270 250 4005 4007 1 0 63
tilepic 290 250 3084
button 330 250 4005 4007 1 0 64
tilepic 350 250 3086

page 4	//Change House Sign Hanger
button 50 180 4005 4007 1 0 70
tilepic 70 180 2968
button 150 180 4005 4007 1 0 71
tilepic 170 180 2970
button 250 180 4005 4007 1 0 72
tilepic 270 180 2972
button 50 260 4005 4007 1 0 73
tilepic 70 260 2974
button 150 260 4005 4007 1 0 74
tilepic 170 260 2976
button 250 260 4005 4007 1 0 75
tilepic 270 260 2978

page 5	//Change Signpost 1/2
button 10 360 4005 4007 0 6 0
button 15 130 4005 4007 1 0 80
tilepic 25 130 9
button 65 130 4005 4007 1 0 81
tilepic 75 130 29
button 115 130 4005 4007 1 0 82
tilepic 125 130 54
button 165 130 4005 4007 1 0 83
tilepic 175 130 90
button 215 130 4005 4007 1 0 84
tilepic 225 130 147
button 265 130 4005 4007 1 0 85
tilepic 275 130 169
button 315 130 4005 4007 1 0 86
tilepic 325 130 177
button 365 130 4005 4007 1 0 87
tilepic 375 130 204
button 15 240 4005 4007 1 0 88
tilepic 25 240 251
button 65 240 4005 4007 1 0 89
tilepic 75 240 257
button 115 240 4005 4007 1 0 90
tilepic 125 240 263
button 165 240 4005 4007 1 0 91
tilepic 175 240 298
button 215 240 4005 4007 1 0 92
tilepic 225 240 347
button 265 240 4005 4007 1 0 93
tilepic 275 240 424
button 315 240 4005 4007 1 0 94
tilepic 325 240 441
button 365 240 4005 4007 1 0 95
tilepic 375 240 466

page 6	//Change Signpost 2/2
button 10 360 4005 4007 0 5 0
button 15 130 4005 4007 1 0 96
tilepic 25 130 514
button 65 130 4005 4007 1 0 97
tilepic 75 130 600
button 115 130 4005 4007 1 0 98
tilepic 125 130 601
button 165 130 4005 4007 1 0 99
tilepic 175 130 602
button 215 130 4005 4007 1 0 100
tilepic 225 130 603
button 265 130 4005 4007 1 0 101
tilepic 275 130 660
button 315 130 4005 4007 1 0 102
tilepic 325 130 666
button 365 130 4005 4007 1 0 103
tilepic 375 130 672
button 15 240 4005 4007 1 0 104
tilepic 25 240 898
button 65 240 4005 4007 1 0 105
tilepic 75 240 970
button 115 240 4005 4007 1 0 106
tilepic 125 240 974
button 165 240 4005 4007 1 0 107
tilepic 175 240 982

page 7	//Change Foundation Style
button 15 180 4005 4007 1 0 120
tilepic 40 180 014
button 95 180 4005 4007 1 0 121
tilepic 120 180 0bd
button 175 180 4005 4007 1 0 122
tilepic 200 180 02fd
button 255 180 4005 4007 1 0 123
tilepic 280 180 041
button 335 180 4005 4007 1 0 124
tilepic 360 180 065
//IF (<SERV.FeatureML> & 01)
// button 15 280 4005 4007 1 0 125
// tilepic 40 280 02df7
// button 95 280 4005 4007 1 0 126
// tilepic 120 280 02dfb
//ENDIF
//IF (<SERV.FeatureML> & 02)
// button 175 280 4005 4007 1 0 127
// tilepic 200 280 03672
// button 255 280 4005 4007 1 0 128
// tilepic 280 280 03676
//ENDIF


[DIALOG d_house_features BUTTON]
ON=1 10
DefaultHouseDialogButtons <ARGN>

ON=11 64
LOCAL.SIGN=2980
LOCAL.SIGN += <eval (<ARGN>-11)*2>
DISPID=<dLOCAL.SIGN>
UPDATEX
SDIALOG d_house_customize

ON=70 75
LOCAL.SIGN=2968
LOCAL.SIGN += <eval (<ARGN>-70)*2>
REF1=<UID>
FORITEMS 30
 IF (<REGION.UID>==<REF1.REGION.UID>)  
  IF (<DISPIDDEC> >= 2968) && (<DISPIDDEC> <= 2978) && (<LINK>==<REGION.UID>)
   DISPID=<dLOCAL.SIGN>
   UPDATEX
  ENDIF
 ENDIF
ENDFOR
SDIALOG d_house_customize

ON=80 107
IF (<ARGN>==80)
 LOCAL.SIGN=9
ELIF (<ARGN>==81)
 LOCAL.SIGN=29
ELIF (<ARGN>==82)
 LOCAL.SIGN=54
ELIF (<ARGN>==83)
 LOCAL.SIGN=90
ELIF (<ARGN>==84)
 LOCAL.SIGN=147
ELIF (<ARGN>==85)
 LOCAL.SIGN=169
ELIF (<ARGN>==86)
 LOCAL.SIGN=177
ELIF (<ARGN>==87)
 LOCAL.SIGN=204
ELIF (<ARGN>==88)
 LOCAL.SIGN=251
ELIF (<ARGN>==89)
 LOCAL.SIGN=257
ELIF (<ARGN>==90)
 LOCAL.SIGN=263
ELIF (<ARGN>==91)
 LOCAL.SIGN=298
ELIF (<ARGN>==92)
 LOCAL.SIGN=347
ELIF (<ARGN>==93)
 LOCAL.SIGN=424
ELIF (<ARGN>==94)
 LOCAL.SIGN=441
ELIF (<ARGN>==95)
 LOCAL.SIGN=466
ELIF (<ARGN>==96)
 LOCAL.SIGN=514
ELIF (<ARGN>==97)
 LOCAL.SIGN=600
ELIF (<ARGN>==98)
 LOCAL.SIGN=601
ELIF (<ARGN>==99)
 LOCAL.SIGN=602
ELIF (<ARGN>==100)
 LOCAL.SIGN=603
ELIF (<ARGN>==101)
 LOCAL.SIGN=660
ELIF (<ARGN>==102)
 LOCAL.SIGN=666
ELIF (<ARGN>==103)
 LOCAL.SIGN=672
ELIF (<ARGN>==104)
 LOCAL.SIGN=898
ELIF (<ARGN>==105)
 LOCAL.SIGN=970
ELIF (<ARGN>==106)
 LOCAL.SIGN=974
ELIF (<ARGN>==107)
 LOCAL.SIGN=982
ENDIF
REF1=<HouseSignPost>
IF (<REF1>)
 REF1.DISPID=<dLOCAL.SIGN>
 REF1.UPDATEX
ENDIF
SDIALOG d_house_customize

ON=120 128
IF (<ARGN>==120)
 HouseChangeFoundationStyle 0017,0016,0015,0014		//Wood
ELIF (<ARGN>==121)
 HouseChangeFoundationStyle 00c0,00bf,00be,00bd		//Bright Wood
ELIF (<ARGN>==122)
 HouseChangeFoundationStyle 0300,02fe,02ff,02fd		//Dungeon
ELIF (<ARGN>==123)
 HouseChangeFoundationStyle 0044,0042,0043,0041		//Brick
ELIF (<ARGN>==124)
 HouseChangeFoundationStyle 0066,0063,0064,0065		//Stone
ELIF (<ARGN>==125) //ML
 HouseChangeFoundationStyle 02df8,02dfa,02df9,02df7	//Elven Grey
ELIF (<ARGN>==126)
 HouseChangeFoundationStyle 02dfc,02dfe,02dfd,02dfb	//Elven Natural
ELIF (<ARGN>==127) //ML 9th age
 HouseChangeFoundationStyle 03673,03670,03671,03672	//Crystal
ELIF (<ARGN>==128)
 HouseChangeFoundationStyle 03677,03674,03675,03676	//Shadow
ENDIF
SDIALOG d_house_customize


//////////////////////////////////////////////////////////////////////////////////


[DIALOG d_house_visitor]
200,200

gumppic 10 10 100
dhtmlgump 30 43 105 40 0 0 <DEF.CENTER><NAME><DEF.CENTERE>




[DIALOG d_house_type]
160,150
noclose

page 0
resizepic 0 0 5054 320 180
gumppictiled 10 10 300 20 2624
checkertrans 10 10 300 20
dhtmlgump 10 10 300 20 0 0 <DEF.L1>basefont color="#f70000"<DEF.R1><DEF.CENTER>NOTICE
gumppictiled 10 40 300 100 2624
checkertrans 10 40 300 100
gumppictiled 10 150 300 20 2624
checkertrans 10 150 300 20
button 10 150 4005 4007 1 0 1
dtext 40 150 1152 OKAY

page 1
dhtmlgump 10 40 300 100 0 1 <DEF.L1>basefont color="#ffc600"<DEF.R1>This house is now public. <QVAL (<DEF.HOUSE_USE_VENDORS> && <DEF.HOUSE_VENDORS_PUBLIC_ONLY>)? The owner may now place vendors and vendor rental contracts.>

page 2
dhtmlgump 10 40 300 100 0 1 <DEF.L1>basefont color="#ffc600"<DEF.R1>This house is now private.

page 3
dhtmlgump 10 40 300 100 0 1 <DEF.L1>basefont color="#ffc600"<DEF.R1>You have vendors working out of this building. It cannot be declared private until there are no vendors in place.

[DIALOG d_house_type BUTTON]
ON=1
SDIALOG d_house_security




[DIALOG d_house_clear_coowners]
110,100
noclose

resizepic 0 0 5054 420 280
gumppictiled 10 10 400 20 2624
checkertrans 10 10 400 20
dtext 180 10 026 WARNING
gumppictiled 10 40 400 200 2624
checkertrans 10 40 400 200
dhtmlgump 10 40 400 200 0 1 You are about to remove ALL co-owners from your house. Are you certain you wish to clear the co-owner list?
gumppictiled 10 250 400 20 2624
checkertrans 10 250 400 20
button 10 250 4005 4007 1 0 1
dtext 40 250 1152 OKAY
button 210 250 4005 4007 1 0 0
dtext 240 250 1152 CANCEL

[DIALOG d_house_clear_coowners BUTTON]
ON=0
SDIALOG d_house_security

ON=1
ARGS=<HouseAccessList 3>
FOR <TAG0.Access.Total.3>
 REF1=<ARGV[<LOCAL._FOR>]>
 REF1.NOTICE=You got removed from the Co-Owner access list of the house '<SRC.TARG.NAME>' on <serv.rtime.format %d>/<serv.rtime.format %m>/<serv.rtime.format %Y> <strsub 11 0 <serv.rtime>>.
 TRY TAG.Access.<REF1>=
ENDFOR
TAG0.Access.Total.3=
SDIALOG d_house_security
SRC.SYSMESSAGE @,,1 All co-owners have been removed from this house.




[DIALOG d_house_clear_friends]
110,100
noclose

resizepic 0 0 5054 420 280
gumppictiled 10 10 400 20 2624
checkertrans 10 10 400 20
dtext 180 10 026 WARNING
gumppictiled 10 40 400 200 2624
checkertrans 10 40 400 200
dhtmlgump 10 40 400 200 0 1 If you go ahead with this option, all of the current friendships will be removed from the house, and any vendors associated with said friends will be made unwelcome. Are you sure you want to do this?
gumppictiled 10 250 400 20 2624
checkertrans 10 250 400 20
button 10 250 4005 4007 1 0 1
dtext 40 250 1152 OKAY
button 210 250 4005 4007 1 0 0
dtext 240 250 1152 CANCEL

[DIALOG d_house_clear_friends BUTTON]
ON=0
SDIALOG d_house_security

ON=1
ARGS=<HouseAccessList 2>
FOR <TAG0.Access.Total.2>
 REF1=<ARGV[<LOCAL._FOR>]>
 REF1.NOTICE=You got removed from the Friend access list of the house '<SRC.TARG.NAME>' on <serv.rtime.format %d>/<serv.rtime.format %m>/<serv.rtime.format %Y> <strsub 11 0 <serv.rtime>>.
 TRY TAG.Access.<REF1>=
ENDFOR
TAG0.Access.Total.2=
SDIALOG d_house_security
SRC.SYSMESSAGE @,,1 All friends have been removed from this house.




[DIALOG d_house_clear_bans]
110,100
noclose

resizepic 0 0 5054 420 280
gumppictiled 10 10 400 20 2624
checkertrans 10 10 400 20
dtext 180 10 026 WARNING
gumppictiled 10 40 400 200 2624
checkertrans 10 40 400 200
dhtmlgump 10 40 400 200 0 1 You are about to lift all bans for this house.  Are you sure you wish to do this?
gumppictiled 10 250 400 20 2624
checkertrans 10 250 400 20
button 10 250 4005 4007 1 0 1
dtext 40 250 1152 OKAY
button 210 250 4005 4007 1 0 0
dtext 240 250 1152 CANCEL

[DIALOG d_house_clear_bans BUTTON]
ON=0
SDIALOG d_house_security

ON=1
ARGS=<HouseAccessList -1>
FOR <TAG0.Access.Total.-1>
 TRY TAG.Access.<ARGV[<dLOCAL._FOR>]>=
ENDFOR
TAG0.Access.Total.-1=
SDIALOG d_house_security
SRC.SYSMESSAGE @,,1 All bans for this house have been lifted.




[DIALOG d_house_clear_access_list]
110,100
noclose

resizepic 0 0 5054 420 280
gumppictiled 10 10 400 20 2624
checkertrans 10 10 400 20
dtext 180 10 026 CUIDADO
gumppictiled 10 40 400 200 2624
checkertrans 10 40 400 200
dhtmlgump 10 40 400 200 0 1 This will revoke access from everyone on this list and immediately eject them from the house.  Those players will no longer be able to enter the house.  Are you sure you wish to clear the house access list?
gumppictiled 10 250 400 20 2624
checkertrans 10 250 400 20
button 10 250 4005 4007 1 0 1
dtext 40 250 1152 OKAY
button 210 250 4005 4007 1 0 0
dtext 240 250 1152 CANCEL

[DIALOG d_house_clear_access_list BUTTON]
ON=0
SDIALOG d_house_security

ON=1
ARGS=<HouseAccessList 1>
FOR <TAG0.Access.Total.1>
 REF1=<ARGV[<LOCAL._FOR>]>
 IF (<REF1.REGION.UID>==<REGION.UID>)
  REF1.P=<P>
  REF1.MOVE S
  REF1.FIX
  REF1.SYSMESSAGE @,,1 Your access to this house has been revoked.
 ENDIF
 TRY TAG.Access.<REF1>=
ENDFOR
TAG0.Access.Total.1=
SDIALOG d_house_security
SRC.SYSMESSAGE @,,1 This house's Access List has been cleared.




[DIALOG d_house_demolish]
110,100
noclose

resizepic 0 0 5054 420 280
gumppictiled 10 10 400 20 2624
checkertrans 10 10 400 20
dhtmlgump 10 10 400 20 0 0 <DEF.L1>basefont color="#f70000"<DEF.R1><DEF.CENTER>WARNING
gumppictiled 10 40 400 200 2624
checkertrans 10 40 400 200
dhtmlgump 10 40 400 200 0 1 <DEF.L1>basefont color="#ffc600"<DEF.R1>You are about to demolish your house. You will be refunded the house's value directly to your bank box. All items in the house will remain behind and can be freely picked up by anyone until decay. Once the house is demolished, anyone can attempt to place a new house on the vacant. Are you sure you wish to continue?
gumppictiled 10 250 400 20 2624
checkertrans 10 250 400 20
button 10 250 4005 4007 1 0 1
dtext 40 250 1152 OKAY
button 210 250 4005 4007 1 0 0
dtext 240 250 1152 CANCEL

[DIALOG d_house_demolish BUTTON]
ON=1
ARGS=<IsNearType.P t_stone_guild 40>
IF (<SERV.MAP(<ARGV0>,<ARGV1>,<ARGV3>).REGION.UID>==<REGION.UID>)
 SRC.SYSMESSAGE @,,1 You cannot demolish a house with a guildstone inside.
ELIF (<TAG0.VENDORS>)
 SRC.SYSMESSAGE @,,1 You cannot demolish a house with a vendor inside.
ELSE
 IF (<DISTANCE> < 15)
   IF (<SRC.REGION.UID>==<REGION.UID>)
    SRC.P=<P>
    SRC.UPDATEX
   ENDIF
   FOR <DEF.MAX_HOUSE_COOWNERS>
    TRY UID.<TAG0.CO_OWNER_<dLOCAL._FOR>>.NOTICE=You got removed from the Co-Owner access list of the house '<SRC.TARG.NAME>' because it was demolished on <serv.rtime.format %d>/<serv.rtime.format %m>/<serv.rtime.format %Y> <strsub 11 0 <serv.rtime>>.
   ENDFOR
   FOR <DEF.MAX_HOUSE_FRIENDS>
    TRY UID.<TAG0.FRIEND_<dLOCAL._FOR>>.NOTICE=You got removed from the Friend access list of the house '<SRC.TARG.NAME>' because it was demolished on <serv.rtime.format %d>/<serv.rtime.format %m>/<serv.rtime.format %Y> <strsub 11 0 <serv.rtime>>.
   ENDFOR
   LINK.f_house_demolish
 ELSE
   SRC.SYSMESSAGE @,,1 You are too far away from the house sign.
 ENDIF
ENDIF


[FUNCTION f_house_demolish]
IF (<isempty <ARGS>>)
  REF1=<QVAL (<SRC>)? <SRC>:<MORE1>>
  IF (<DEF.HOUSE_USE_DEEDS>) && !STRMATCH("*foundation*","<BASEID>")
    SERV.NEWITEM i_deed_<STRSUB 8 30 <BASEID>>
    NEW.CONT=<REF1.FINDLAYER.21>
    REF1.SYSMESSAGE @,,1 You put the house deed on your backpack.
  ELSE
    LOCAL.REFUND=<eval (<HouseValue>*<DEF.DEMOLISH_REFUND_PERCENT>)/100>
    REF1.GOLD += <dLOCAL.REFUND>
    REF1.SYSMESSAGE @,,1 <dLOCAL.REFUND> gold has been deposited into your bank box.
  ENDIF
ENDIF
REF1=<MORE2>
FOR <REF1.TAG0.Vendors>
 REF2=<REF1.TAG0.Vendor<dLOCAL._FOR>>
 IF (<REF2>)
  REF2.HouseVendorRemove
  REF2.REMOVE
 ENDIF
ENDFOR
REF1=<REGION.UID>
FORCHARS 40
  IF (<REGION.UID>==<REF1>)
   TIMERF 1,FIX
  ENDIF
ENDFOR
FORPLAYERS 40
  IF (<REGION.UID>==<REF1>)
   TIMERF 1,FIX
  ENDIF
ENDFOR
FORITEMS 40
  IF (<REGION.UID>==<REF1>) && (<ISSTORAGE>)
    TIMER=<eval <SERV.DecayTimer>*60>
    ATTR &= ~attr_move_never
    ATTR |= attr_decay
    EVENTS -t_locked_down
    TAG.AlwaysSend=
    TAG.Access=
    TIMERF 1,FIX
    UPDATE
  ENDIF
ENDFOR
REMOVE

[DIALOG d_house_convertion]
110,100
noclose

resizepic 0 0 5054 420 280
gumppictiled 10 10 400 20 2624
checkertrans 10 10 400 20
dhtmlgump 10 10 400 20 0 0 <DEF.L1>basefont color="#f70000"<DEF.R1><DEF.CENTER>WARNING
gumppictiled 10 40 400 200 2624
checkertrans 10 40 400 200
dhtmlgump 10 40 400 200 0 1 <DEF.L1>basefont color="#ffc600"<DEF.R1>You are about to turn your house into a customizable house.  You will be refunded the value of this house, and then be charged the cost of the equivalent customizable dirt lot.  All of your possessions in the house will be transported to a Moving Crate.  Deed-based house add-ons will be converted back into deeds.  Vendors and barkeeps will also be stored in the Moving Crate.  Your house will be leveled to its foundation, and you will be able to build new walls, windows, doors, and stairs.  Are you sure you wish to continue?
gumppictiled 10 250 400 20 2624
checkertrans 10 250 400 20
button 10 250 4005 4007 1 0 1
dtext 40 250 1152 OKAY
button 210 250 4005 4007 1 0 0
dtext 240 250 1152 CANCEL

[DIALOG d_house_convertion BUTTON]
ON=0
SDIALOG d_house_customize

ON=1
IF !(<SRC.ISGM>)
 LOCAL.Price.Old=<eval (<LINK.HouseValue>*<DEF.DEMOLISH_REFUND_PERCENT>)/100>
 LOCAL.Price.New=<SERV.ITEMDEF.<DEF.convertion_<LINK.DISPID>>.VALUE>
 LOCAL.Cost=<eval <LOCAL.Price.New>-<LOCAL.Price.Old>>
 IF (<LOCAL.Cost> > 0)
  IF (<SRC.BANKBALANCE> < <LOCAL.Cost>)
   SRC.SYSMESSAGE @,,1 You do not have enough funds in your bank to cover the difference between your old house and your new one.
   return 1
  ENDIF
  SRC.SYSMESSAGE @,,1 <dLOCAL.Cost> gold has been withdrawn from your bank box.
  SRC.GOLD -= <LOCAL.Cost>
 ELSE
  SRC.SYSMESSAGE @,,1 <eval <LOCAL.Cost>*-1> gold has been deposited into your bank box.
  SRC.GOLD += <eval <LOCAL.Cost>*-1>
 ENDIF
 SRC.UPDATE
ENDIF
SERV.NEWITEM <DEF.convertion_<LINK.DISPID>>
LOCAL.P=<LINK.P>
REF1=<LINK>
LINK=
REF1.REMOVE
NEW.P=<LOCAL.P>
NEW.MORE1=<SRC>
NEW.MORE2=<UID>
NEW.MULTICREATE
NEW.HousePlaceFoundationStairs
HouseConvertSign
SRC.NOTICE You have successfully replaced your original house with a new house.  The value of the replaced house has been deposited into your bank box.  All of the items in your original house have been relocated to a Moving Crate in the new house.  Any deed-based house add-ons have been converted back into deeds.  Vendors and barkeeps in the house, if any, have been stored in the Moving Crate as well.  Use the <DEF.B>Get Vendor<DEF.BE> context-sensitive menu option on your character to retrieve them.  These containers can be used to re-create the vendor in a new location.  Any barkeepers have been converted into deeds.

[FUNCTION HouseConvertSign]
REF1=<UID>
FORITEMS 40
 IF (<REGION.UID>==<REF1.REGION.UID>)
  IF (<TYPE>==t_sign_gump) && (<UID> != <REF1>)
   REF1.P=<P>
   REF1.LINK=<LINK>
   REMOVE
   return 1
  ENDIF
 ENDIF
ENDFOR

[DIALOG d_house_transfer]
110,100
noclose
CTAG.HOUSE.TRANSFER=<ARGS>

resizepic 0 0 5054 420 280
gumppictiled 10 10 400 20 2624
checkertrans 10 10 400 20
dtext 180 10 026 WARNING
gumppictiled 10 40 400 200 2624
checkertrans 10 40 400 200
dhtmlgump 10 40 400 200 0 1 <DEF.BFONT_YELLOW>Another player is attempting to initiate a house trade with you.  In order for you to see this window, both you and the other person are standing within two paces of the house to be traded.  If you click OKAY below, a house trade scroll will appear in your trade window and you can complete the transaction.  This scroll is a distinctive blue color and will show the name of the house, the name of the owner of that house, and the sextant coordinates of the center of the house when you hover your mouse over it.  In order for the transaction to be successful, you both must accept the trade and you both must remain within two paces of the house sign.<DEF.BR><DEF.BR>If you are absolutely certain you wish to proceed, click the button next to OKAY below. If you do not wish to trade for this house, click CANCEL.

gumppictiled 10 250 400 20 2624
checkertrans 10 250 400 20
button 10 250 4005 4007 1 0 1
dtext 40 250 1152 OKAY
button 210 250 4005 4007 1 0 0
dtext 240 250 1152 CANCEL

[DIALOG d_house_transfer BUTTON]
ON=0 1
REF1=<CTAG0.HOUSE.TRANSFER>
CTAG0.HOUSE.TRANSFER=
IF (<ARGN>==1)
 IF (<FINDTYPE.t_eq_trade_window>)
  SYSMESSAGE @,,1 You cannot trade a house while you have other trades pending.
  return 1
 ELIF (<SRC.FINDTYPE.t_eq_trade_window>)
  SRC.SYSMESSAGE @,,1 You cannot trade a house while you have other trades pending.
  return 1
 ENDIF
 SRC.EVENTS=+e_house_transfer
 SERV.NEWITEM i_deed
 NEW.ATTR=attr_move_never
 NEW.COLOR=0480
 NEW.LINK=<REF1>
 NEW.MORE1=<SRC>
 NEW.TYPE=t_trade_house_deed
 NEW.TIMERF 2,TRIGGER @Timer
 SRC.TRYSRC <UID> TradeWindow <NEW>
ENDIF

[EVENTS e_house_transfer]
ON=@TradeAccepted
DIALOGCLOSE d_house_demolish
DIALOGCLOSE d_house_ownership
FOR <ARGN1>
 IF (<REF<dLOCAL._FOR>.TYPE> == t_trade_house_deed)
  UID.<REF<dLOCAL._FOR>>.TRIGGER @HouseTraded
  UID.<REF<dLOCAL._FOR>>.REMOVE
 ENDIF
ENDFOR
EVENTS=-e_house_transfer

[DIALOG d_house_access]
50,50
REF1=<UID.<REGION.UID>.MORE2>
REF2=<UID.<REGION.UID>.MORE1>

resizepic 0 0 5054 220 180
gumppictiled 10 10 200 20 5124
gumppictiled 10 40 200 20 5124
gumppictiled 10 70 200 100 5124
checkertrans 10 10 200 160
dhtmlgump 10 10 200 20 0 0 <DEF.BFONT_white><DEF.CENTER>SET ACCESS<DEF.CENTERE>
dhtmlgump 10 40 50 20 0 0 <DEF.BFONT_white>Owner:
dhtmlgump 55 40 155 20 0 0 <DEF.BFONT_white><DEF.CENTER><REF2.NAME>

IF (<REF1.IsOwner <SRC>>)
 button 10 70 <QVAL (<TAG0.Access>==4)? 4006 4007:4005 4007> 1 0 1
 dhtmlgump 45 70 200 20 0 0 <QVAL (<TAG0.Access>==4)? <def.bfont_red>:<def.bfont_white>>Owner Only
ENDIF

button 10 90 <QVAL (<TAG0.Access>==3)? 4006 4007:4005 4007> 1 0 2
dhtmlgump 45 90 200 20 0 0 <QVAL (<TAG0.Access>==3)? <def.bfont_red>:<def.bfont_white>>Co-Owners

button 10 110 <QVAL (<TAG0.Access>==2)? 4006 4007:4005 4007> 1 0 3
dhtmlgump 45 110 200 20 0 0 <QVAL (<TAG0.Access>==2)? <def.bfont_red>:<def.bfont_white>>Friends

IF (<REF2.GUILD>)
 IF (<REF1.IsOwner <SRC>>)
  button 10 130 <QVAL (<TAG0.Access>==5)? 4006 4007:4005 4007> 1 0 4
  dhtmlgump 45 130 200 20 0 0 <QVAL (<TAG0.Access>==5)? <def.bfont_red>:<def.bfont_white>>Guild Members
 ENDIF
ENDIF

button 10 150 <QVAL (<TAG0.Access>==0)? 4006 4007:4005 4007> 1 0 5
dhtmlgump 45 150 200 20 0 0 <QVAL (<TAG0.Access>==0)? <def.bfont_red>:<def.bfont_white>>Anyone


[DIALOG d_house_access BUTTON]
ON=0
SRC.SYSMESSAGE @,,1 Access level unchanged.

ON=1 5
REF1=<UID.<REGION.UID>.MORE2>
IF (<TYPE>==t_container)
 LOCAL.RESCOUNT=<FCOUNT>
ENDIF
IF (<ARGN> < 5)
 IF (<TYPE>==t_container) && !(<TAG0.Access>)
  IF !(<REF1.House_AvaibleLockdowns>) || (<LOCAL.RESCOUNT> > <REF1.House_AvaibleStorage>)
   SRC.SYSMESSAGE @,,1 This action would exceed the secure storage limit of the house.
   return 1
  ELIF (<ARGN>==1) && (<REF1.HousePlayerAccess <SRC>> < 4)
   return 1
  ELIF (<ARGN>==2) && (<REF1.HousePlayerAccess <SRC>> < 3)
   return 1
  ENDIF
  REF1.TAG0.LOCKED_ITEMS -= <LOCAL.RESCOUNT>
  REF1.TAG0.SECURE_CONT += <LOCAL.RESCOUNT>
 ENDIF
ENDIF
IF (<ARGN>==1)
 TAG.Access=4
ELIF (<ARGN>==2)
 TAG.Access=3
ELIF (<ARGN>==3)
 TAG.Access=2
ELIF (<ARGN>==4)
 TAG.Access=5
ELIF (<ARGN>==5)
 IF (<TYPE>==t_container) && (<TAG0.Access>)
  REF1.TAG0.SECURE_CONT -= <LOCAL.RESCOUNT>
  REF1.TAG0.LOCKED_ITEMS += <LOCAL.RESCOUNT>
 ENDIF
 TAG.Access=
ENDIF
UPDATE
SRC.SYSMESSAGE @,,1 New access level set.


//////////////////////////////////////////////////////////////////////////////////


[REGIONTYPE r_house_system]
ON=@Enter
SRC.MUSIC=37
REF1=<UID.<UID>.MORE2>
IF (<REF1.HousePlayerAccess <SRC>>==-1)
  SRC.SYSMESSAGE @,,1 You are banned from this house!
  return 1
ELIF (<SRC.ISPLAYER>)
  IF !(<SRC.ISGM>)
   IF (<DEF.HOUSE_USE_DEPTH_OF_FIELD>) && !(<REF1.TAG0.Public>) && (<REF1.HousePlayerAccess <SRC>> < 1)
    return 1
   ELIF (<UID.<UID>.TYPE>==t_multi_custom)
    IF (<UID.<UID>.DESIGNER>)
     return 1
    ENDIF
   ENDIF
  ENDIF
  return 0
ELSE
  IF (<SRC.IsHouseVendor>)
   IF (<REF1.TAG0.VENDORS> >= <UID.<UID>.HouseMaxVendors>) || ((<DEF.HOUSE_VENDORS_PUBLIC_ONLY>) && !(<REF1.TAG0.Public>))
    SRC.TIMERF 1,HouseVendorRemove
    SRC.TIMERF 1,REMOVE
   ELSE
    SRC.TAG.House=<UID>
    SRC.EVENTS +e_aos_house_vendor
    REF1.TAG0.VENDORS ++
    REF1.TAG.VENDOR<dREF1.TAG0.VENDORS>=<SRC>
   ENDIF
  ELIF (<DEF.HOUSE_USE_DEPTH_OF_FIELD>) && !(<REF1.TAG0.Public>) && (<REF1.HousePlayerAccess <SRC.OWNER>> < 1)
   return 1
  ENDIF
ENDIF

ON=@CliPeriodic
SRC.MUSIC=37

[EVENTS e_aos_house_vendor]
ON=@RegionLeave
return 1

ON=@Destroy
REF1=<UID.<TAG0.House>.MORE2>
FOR <REF1.TAG0.VENDORS>
  IF (<REF1.TAG0.Vendor<dLOCAL._FOR>>==<UID>)
    TRY REF1.TAG0.VENDOR<dLOCAL._FOR>=
    FOR x <LOCAL._FOR> <REF1.TAG0.VENDORS>
     TRY REF1.TAG.VENDOR<dLOCAL.X>=<REF1.TAG.VENDOR<eval <LOCAL.X>+1>>
    ENDFOR
    REF1.TAG0.VENDORS --
  ENDIF
ENDFOR
IF (<TAG0.DemolishHouse>) && !(<REF1.TAG0.VENDORS>)
 REF1.TIMER=0
ENDIF


//////////////////////////////////////////////////////////////////////////////////

[FUNCTION HouseAddAccess]	//uid,access
IF !(<TAG0.Access.<ARGV0>>)
 TRY TAG0.Access.Total.<ARGV1> = <eval <TAG0.Access.Total.<ARGV1>>+1>
ENDIF
TRY TAG.Access.<ARGV0>=<ARGV1>,<dTAG0.Access.Total.<ARGV1>>

[FUNCTION HouseGetAccessRef]	//access,number
FOR 0 <eval <TAGCOUNT>-1>
 IF !STRCMP("<STRSUB 0 6 <TAGAT.<LOCAL._FOR>.KEY>>","access")
   IF (<ARGV0>==<STRARG <TAGAT.<LOCAL._FOR>.VAL>>) && (<ARGV1>==<STREAT <TAGAT.<LOCAL._FOR>.VAL>>)
    return <STRSUB 7 0 <TAGAT.<LOCAL._FOR>.KEY>>
   ENDIF
 ENDIF
ENDFOR

[FUNCTION HouseAccessList]	//access
FOR 0 <eval <TAGCOUNT>-1>
 IF !STRCMP("<STRSUB 0 6 <TAGAT.<LOCAL._FOR>.KEY>>","access") && STRCMP("<STRSUB 7 5 <TAGAT.<LOCAL._FOR>.KEY>>","total")
  IF (<ARGV0>==<STRARG <TAGAT.<LOCAL._FOR>.VAL>>)
   LOCAL.LIST .= ,<STRSUB 7 0 <TAGAT.<LOCAL._FOR>.KEY>>
  ENDIF
 ENDIF
ENDFOR
return <LOCAL.LIST>

[FUNCTION HousePlayerAccess]	//uid
IF (<MORE2> == <ARGS>) || ((<DEF.ACCOUNT_OWNERSHIP>) && !STRCMP("<UID.<MORE2>.ACCOUNT>","<UID.<ARGS>.ACCOUNT>")) || (<UID.<ARGS>.ISGM>)
 return 5
ELSE
 return <STRARG <TAG0.Access.<ARGS>>>
ENDIF


[FUNCTION IsOwner]
IF (<HousePlayerAccess <ARGS>> >= 4)
 return 1
ENDIF
return 0

[FUNCTION IsCoOwner]
IF (<HousePlayerAccess <ARGS>>==3)
 return 1
ENDIF
return 0

[FUNCTION IsFriend]
IF (<HousePlayerAccess <ARGS>>==2)
 return 1
ENDIF
return 0

[FUNCTION IsBanned]
IF !(<DEF.HOUSE_USE_BAN_ENGINE>) || (<HousePlayerAccess <ARGS>> != -1)
 return 0
ENDIF
return 1

[FUNCTION HasAccess]
IF !(<DEF.HOUSE_USE_DEPTH_OF_FIELD>) || (<HousePlayerAccess <ARGS>> > 0)
 return 1
ENDIF
return 0


[FUNCTION CanAccess]
IF (<SRC.ISPLAYER>)
 IF (<UID.<UID.<REGION.UID>.MORE2>.HousePlayerAccess <SRC>> >= <TAG0.Access>) || ((<TAG0.Access>==5) && (<SRC.GUILD> == <UID.<UID.<REGION.UID>.MORE1>.GUILD>)) || (<SRC.ISGM>)
  return 1
 ENDIF
ENDIF
return 0

[FUNCTION IsStorage]
IF (<TYPE>==t_door_locked) || (<TYPE>==t_door) || (<TYPE>==t_sign_gump) || (<TYPE>==t_corpse) || (<TYPE>==t_spell)
 return 0
ELIF (<ISEVENT.t_locked_down>)
 IF !(<TAG0.Access>)
  return 1
 ELSE
  return 2
 ENDIF
ELSE
 return 0
ENDIF

[FUNCTION IsOnHouse]
IF ((<UID.<REGION.UID>.TYPE>==t_multi) || (<UID.<REGION.UID>.TYPE>==t_multi_custom)) && (<Z> != <SERV.MAP(<P.X>,<P.Y>,<P.M>).TERRAIN.Z>)
 return 1
ELSE
 return 0
ENDIF


[FUNCTION House_MaxSecureStorage]
IF (<DEF.USE_GLOBAL_STORAGE>)
 return <eval (<dDEF.GLOBAL_SECURE_STORAGE>+<MulDiv <DEF.GLOBAL_SECURE_STORAGE>,<TAG0.STORAGE_INCREASE>,100>)>
ELSE
 return <eval (<TAG0.STORAGE_LIMIT>+<MulDiv <TAG0.STORAGE_LIMIT>,<TAG0.STORAGE_INCREASE>,100>)>
ENDIF

[FUNCTION House_AvaibleStorage]
return <eval <House_MaxSecureStorage>-(<TAG0.LOCKED_ITEMS>+<TAG0.SECURE_CONT>)>

[FUNCTION House_MaxLockdowns]
return <eval <House_MaxSecureStorage>/2>

[FUNCTION House_AvaibleLockdowns]
LOCAL.LOCKDOWNS=<House_MaxLockdowns>-<TAG0.LOCKED_ITEMS>
IF (<House_AvaibleStorage> > <LOCAL.LOCKDOWNS>)
 return <dLOCAL.LOCKDOWNS>
ELSE
 return <House_AvaibleStorage>
ENDIF


[FUNCTION f_house_add_coowner]
REF1=<ARGS>
IF !(<ARGO.ISPLAYER>)
 SRC.SYSMESSAGE @,,1 That can't be the co-owner of the house.
 return 1
ELIF (<REF1.TAG0.Access.Total.3> >= <DEF.MAX_HOUSE_COOWNERS>)
 SRC.SYSMESSAGE @,,1 Your co-owner list is full!
 return 1
ELIF (<REF1.IsOwner <ARGO.UID>>)
 SRC.SYSMESSAGE @,,1 This person is already the house owner!
 return 1
ELIF (<REF1.IsCoOwner <ARGO.UID>>)
 SRC.SYSMESSAGE @,,1 This person is already on your co-owner list!
 return 1
ELIF (<REF1.IsFriend <ARGO.UID>>)
 SRC.SYSMESSAGE @,,1 This person is a friend of the house. Remove them first.
 return 1
ELIF (<REF1.IsBanned <ARGO.UID>>)
 SRC.SYSMESSAGE @,,1 This person is banned!  Unban them first.
 return 1
ENDIF
REF1.HouseAddAccess <ARGO.UID>,3
SRC.SYSMESSAGE @,,1 You made <ARGO.NAME> a co-owner of the house.
ARGO.SYSMESSAGE @,,1 You have been made a co-owner of this house.


[FUNCTION f_house_add_friend]
REF1=<ARGS>
IF !(<ARGO.ISPLAYER>)
 SRC.SYSMESSAGE @,,1 That can't be a friend of the house.
 return 1
ELIF (<REF1.TAG0.Access.Total.2> >= <DEF.MAX_HOUSE_FRIENDS>)
 SRC.SYSMESSAGE @,,1 Your friends list is full!
 return 1
ELIF (<REF1.IsOwner <ARGO.UID>>)
 SRC.SYSMESSAGE @,,1 This person is already the house owner!
 return 1
ELIF (<REF1.IsCoOwner <ARGO.UID>>)
 SRC.SYSMESSAGE @,,1 This person is already on your co-owner list!
 return 1
ELIF (<REF1.IsFriend <ARGO.UID>>)
 SRC.SYSMESSAGE @,,1 This person is already on your friends list!
 return 1
ELIF (<REF1.IsBanned <ARGO.UID>>)
 SRC.SYSMESSAGE @,,1 This person is banned!  Unban them first.
 return 1
ENDIF
REF1.HouseAddAccess <ARGO.UID>,2
SRC.SYSMESSAGE @,,1 You made <ARGO.NAME> a friend of the house.
ARGO.SYSMESSAGE @,,1 You have been made a friend of this house.


[FUNCTION f_house_grant_access]
REF1=<ARGS>
IF !(<ARGO.ISPLAYER>)
 SRC.SYSMESSAGE @,,1 That is not a player.
 return 1
ELIF (<REF1.TAG0.Access.Total.1> >= <DEF.MAX_HOUSE_ACCESS>)
 SRC.SYSMESSAGE @,,1 The access list limit for this house has been reached!
 return 1
ELIF (<REF1.IsBanned <ARGO.UID>>)
 SRC.SYSMESSAGE @,,1 This person is banned!  Unban them first.
 return 1
ELIF (<REF1.HousePlayerAccess <ARGO.UID>>)
 SRC.SYSMESSAGE @,,1 That person already has access to this house.
 return 1
ENDIF
REF1.HouseAddAccess <ARGO.UID>,1
ARGO.SYSMESSAGE @,,1 You have been granted access to this house.


[FUNCTION f_house_banish]
REF1=<ARGS>
IF (<ARGO.ISITEM>)
 SRC.SYSMESSAGE @,,1 You cannot ban that.
 return 1
ELIF (<REF1.TAG0.Access.Total.-1> >= <DEF.MAX_HOUSE_BANS>)
 SRC.SYSMESSAGE @,,1 The ban limit for this house has been reached!
 return 1
ELIF (<ARGO.UID>==<SRC>)
 SRC.SYSMESSAGE @,,1 You can't ban yourself!
 return 1
ELIF (<REF1.IsBanned <ARGO.UID>>)
 SRC.SYSMESSAGE @,,1 <ARGO.NAME> is already banned from this house!
 return 1
ELIF (<ARGO.IsHouseVendor>)
 SRC.SYSMESSAGE @,,1 You can't ban a house vendor!
 return 1
ELIF (<REF1.IsOwner <ARGO.UID>>)
 SRC.SYSMESSAGE @,,1 You can't ban the house owner!
 return 1
ELIF (<REF1.IsCoOwner <ARGO.UID>>)
 SRC.SYSMESSAGE @,,1 You can't ban a house co-owner!
 return 1
ELIF (<REF1.IsFriend <ARGO.UID>>)
 SRC.SYSMESSAGE @,,1 You can't ban a house friend!
 return 1
ELIF (<ARGO.REGION.UID> != <REF1.REGION.UID>)
 SRC.SYSMESSAGE @,,1 You may not eject someone who is not in your house!
 return 1
ENDIF
REF1.HouseAddAccess <ARGO.UID>,-1
ARGO.GO <REF1.P>
ARGO.MOVE S
ARGO.FIX
SRC.SYSMESSAGE @,,1 <ARGO.NAME> has been banned from this house.
ARGO.SYSMESSAGE @,,1 You have been banned from this house.


[FUNCTION f_house_eject]
REF1=<ARGS>
IF (<ARGO.ISITEM>)
 SRC.SYSMESSAGE @,,1 You cannot eject that from the house!
 return 1
ELIF (<ARGO.REGION.UID> != <REF1.REGION.UID>)
 SRC.SYSMESSAGE @,,1 <ARGO.NAME> is not in your house.
 return 1
ELIF (<ARGO.UID>==<SRC>)
 SRC.SYSMESSAGE @,,1 You can't eject yourself!
 return 1
ELIF (<REF1.IsOwner <ARGO.UID>>)
 SRC.SYSMESSAGE @,,1 You can't eject the house owner!
 return 1
ELIF (<REF1.IsCoOwner <ARGO.UID>>)
 SRC.SYSMESSAGE @,,1 You can't eject a house co-owner!
 return 1
ELIF (<REF1.IsFriend <ARGO.UID>>)
 SRC.SYSMESSAGE @,,1 You can't eject a house friend!
 return 1
ENDIF
ARGO.GO <REF1.P>
ARGO.FIX
SRC.SYSMESSAGE @,,1 <ARGO.NAME> has been ejected from this house.
ARGO.SYSMESSAGE @,,1 You have been ejected from this house. If you persist in entering, you may be banned from the house.


[FUNCTION f_house_lock]
IF !(<ARGO.ISITEM>)
  SRC.SYSMESSAGE @,,1 You cannot lock that down!
  return 1
ELIF (<ARGO.TYPE>==t_container)
  LOCAL.RESCOUNT=<ARGO.FCOUNT>
ENDIF
IF (<ARGO.CONT>) || (<SRC.REGION.UID> != <ARGO.REGION.UID>) || !(<ARGO.IsOnHouse>)
  SRC.SYSMESSAGE @,,1 This is not in your house.
ELIF (<ARGO.LINK>==<ARGO.REGION.UID>) || (<ARGO.TYPE>==t_door_locked) || (<ARGO.TYPE>==t_door) || (<ARGO.TYPE>==t_sign_gump) || (<ARGO.TYPE>==t_corpse) || (<ARGO.TYPE>==t_spell) || (<ARGO.BASEID>==i_horse_dung)
  SRC.SYSMESSAGE @,,1 You cannot lock that down!
ELIF (<ARGO.ATTR> & attr_move_never)
  SRC.SYSMESSAGE @,,1 This is already locked down.
ELIF (<eval 1+<LOCAL.RESCOUNT>> > <UID.<ARGS>.House_AvaibleLockdowns>)
  SRC.SYSMESSAGE @,,1 That would exceed the maximum lock down limit for this house.
ELSE
  ARGO.HouseSetLockedProps 1
  UID.<ARGS>.TAG0.LOCKED_ITEMS += <LOCAL.RESCOUNT>
ENDIF

[FUNCTION f_house_secure]
IF !(<ARGO.ISITEM>)
  SRC.SYSMESSAGE @,,1 You cannot secure this.
  return 1
ELIF (<ARGO.TYPE>==t_container)
  LOCAL.RESCOUNT=<ARGO.FCOUNT>
ENDIF
IF (<ARGO.CONT>) || (<SRC.REGION.UID> != <ARGO.REGION.UID>) || !(<ARGO.IsOnHouse>)
  SRC.SYSMESSAGE @,,1 This is not in your house.
ELIF (<ARGO.LINK>==<ARGO.REGION.UID>) || (<ARGO.TYPE>==t_door_locked) || (<ARGO.TYPE>==t_door) || (<ARGO.TYPE>==t_sign_gump) || (<ARGO.TYPE>==t_corpse) || (<ARGO.TYPE>==t_spell) || (<ARGO.BASEID>==i_horse_dung)
  SRC.SYSMESSAGE @,,1 You cannot secure this.
ELIF !(<ARGO.CanAccess>)
  SRC.SYSMESSAGE @,,1 You cannot change the access for this.
ELIF (<ARGO.ATTR> & attr_move_never) && (<ARGO.TYPE> != t_container)
  SRC.SYSMESSAGE @,,1 This is already locked down and cannot be secured.
ELIF (<ARGO.ISSTORAGE>)
  ARGO.SDIALOG d_house_access
ELIF !(<UID.<ARGS>.House_AvaibleLockdowns>) || (<LOCAL.RESCOUNT> > <UID.<ARGS>.House_AvaibleStorage>)
  SRC.SYSMESSAGE @,,1 This action would exceed the secure storage limit of the house.
ELSE
  ARGO.HouseSetLockedProps 1
  IF (<ARGO.TYPE> == t_container)
   ARGO.TAG.Access=3
   ARGO.UPDATE
   UID.<ARGS>.TAG0.SECURE_CONT += <LOCAL.RESCOUNT>
   ARGO.SDIALOG d_house_access
  ENDIF
ENDIF

[FUNCTION f_house_release]
IF !(<ARGO.ISITEM>)
  SRC.SYSMESSAGE @,,1 That isn't locked down...
ELIF (<ARGO.REGION.UID> != <UID.<ARGS>.REGION.UID>)
  SRC.SYSMESSAGE @,,1 This is not in your house.
ELIF !(<ARGO.ISSTORAGE>)
  SRC.SYSMESSAGE @,,1 That isn't locked down...
ELIF (<UID.<ARGS>.HousePlayerAccess <SRC>> < <ARGO.TAG0.Access>)
  SRC.SYSMESSAGE @,,1 You lack privilege to release this.
ELSE
  IF (<ARGO.TYPE>==t_container)
    IF (<ARGO.IsStorage>==1)
     UID.<ARGS>.TAG0.LOCKED_ITEMS -= <ARGO.FCOUNT>
    ELIF (<ARGO.IsStorage>==2)
     ARGO.TAG.Access=
     UID.<ARGS>.TAG0.SECURE_CONT -= <ARGO.FCOUNT>
    ENDIF
  ENDIF
  ARGO.HouseSetLockedProps 0
ENDIF

[FUNCTION HouseSetLockedProps]
FixHouseSubcontainers <ARGS>
IF (<ARGS>)
  IF (<CAN> & can_i_block)
   TAG.AlwaysSend=1
  ENDIF
  ATTR=<ATTR>&~attr_decay
  ATTR=<ATTR>|attr_move_never
  TIMER=-1
  EVENTS +t_locked_down
  UID.<UID.<REGION.UID>.MORE2>.TAG0.LOCKED_ITEMS ++
  UPDATE
  return 1
ELSE
  TAG.AlwaysSend=
  ATTR=<ATTR>&~attr_move_never
  EVENTS -t_locked_down
  UID.<UID.<REGION.UID>.MORE2>.TAG0.LOCKED_ITEMS --
  IF !(<REGION.FLAGS> & region_flag_nodecay)
    ATTR=<ATTR>|attr_decay
    TIMER=<eval <SERV.DecayTimer>*60>
  ENDIF
  UPDATE
  return 1
ENDIF

[FUNCTION FixHouseSubcontainers]
IF (<TOPOBJ.UID> != <UID>) && (<TYPE> == t_container)
 EVENTS=<QVAL (<ARGS>) ? +:->t_subcont
ENDIF
IF (<TOPOBJ.UID> != <UID>)
IF (<TYPE> == t_container)
FORCONT <UID>
 IF (<TYPE> == t_container)
  EVENTS=<QVAL (<ARGS>) ? +:->t_subcont
 ENDIF
ENDFOR
ENDIF
ENDIF

[FUNCTION f_house_transfer]
IF !(<ARGO.ISPLAYER>)
 SRC.SYSMESSAGE @,,1 Only players can own a house!
 return 1
ENDIF
REF1=<ARGS>
IF (<ARGO.UID> == <SRC>)
 SRC.SYSMESSAGE @,,1 You cannot transfer a house to yourself, silly.
 return 1
ELIF ((<ARGO.IsOnHouse>) || (<SRC.IsOnHouse>)) || ((<ARGO.DISTANCE <REF1>> > 2) || (<SRC.DISTANCE <REF1>> > 2))
 SRC.SYSMESSAGE @,,1 In order to transfer the house, you and the recipient must both be outside the building and within two paces of the house sign.
 return 1
ELIF (<ARGO.CHECK_ACCOUNT_TYPEDEF t_multi*> >= <DEF.MAX_ACCOUNT_HOUSES>)
 SRC.SYSMESSAGE @,,1 <ARGO.NAME> already have <dDEF.MAX_ACCOUNT_HOUSES> houses and can't own another one!
 return 1
ELIF (<DEF0.PLACEMENT_WAITING_PERIOD>) && (<ARGO.TAG0.House.PlacementDelay> > <SERV.TIME>)
 SRC.SYSMESSAGE @,,1 That player cannot have a house transferred to them at this time.
 ARGO.SYSMESSAGE @,,1 Number of days you will have to wait till you can have a house transfered to you: <eval (<ARGO.TAG0.House.PlacementDelay>-<SERV.TIME>)/864000>
 return 1
ENDIF
SRC.SYSMESSAGE @,,1 Please wait while the other player verifies the transfer.
SRC.TRYSRC <ARGO.UID> DIALOG d_house_transfer 0,<REF1>

[TYPEDEF t_trade_house_deed]
ON=@ClientToolTip
SRC.ADDCLILOC 1061112,<LINK.NAME>
SRC.ADDCLILOC 1061113,<UID.<LINK.MORE2>.NAME>
SRC.ADDCLILOC 1061114,<STRARG <LINK.SEXTANTP>> <STREAT <LINK.SEXTANTP>>

ON=@Timer
IF (<CONT.TYPE> == t_eq_trade_window)
 TIMERF 2,trigger @Timer
ELSE
 UID.<MORE1>.EVENTS=-e_house_transfer
 REMOVE
ENDIF
return 1

ON=@HouseTraded
REF1=<MORE1>		//New Owner
REF2=<LINK.MORE2>	//Old Owner
REF1.EVENTS=-e_house_transfer
REF2.SYSMESSAGE @,,1 You have transferred ownership of the house.
REF1.SYSMESSAGE @,,1 You are now the owner of this house.  The house's co-owner, friend, ban, and access lists have been cleared.  You should double-check the security settings on any doors and teleporters in the house.
LINK.TAG.LastTraded=<serv.rtime.format %d>-<serv.rtime.format %m>-<serv.rtime.format %Y> <strsub 11 0 <serv.rtime>>
LINK.MORE2=<REF1>
LINK.LINK.MORE1=<REF1>
FOR <eval <REF2.COUNT>-1> 0
 IF (<REF2.FINDCONT.<LOCAL._FOR>.LINK>==<LINK.LINK>)
  REF2.FINDCONT.<dLOCAL._FOR>.CONT=<REF1>
 ENDIF
ENDFOR
FOR 1 3
 ARGS=<LINK.HouseAccessList <LOCAL._FOR>>
 FOR x <LINK.TAG0.Access.Total.<LOCAL._FOR>>
  UID.<ARGV[<dLOCAL.X>]>.NOTICE You got removed from the <DEF.Access_<LOCAL._FOR>> list of the house '<LINK.NAME>' because it was been traded to a new owner on <serv.rtime.format %d>/<serv.rtime.format %m>/<serv.rtime.format %Y> <strsub 11 0 <serv.rtime>>.
 ENDFOR
ENDFOR
IF !(<REF1.ISGM>) && (<DEF0.PLACEMENT_WAITING_PERIOD>)
 REF1.TAG.House.PlacementDelay=<eval <SERV.TIME>+(<DEF0.PLACEMENT_WAITING_PERIOD>*864000)+36000>
ENDIF
LINK.CLEARTAGS Access


[FUNCTION remove_invalid_houses]
FOR 0 <eval <COUNT>-1>
 IF (<FINDCONT.<LOCAL._FOR>.LINK.ISITEM>)
   IF STRMATCH("t_multi*","<FINDCONT.<LOCAL._FOR>.LINK.TYPE>")
    UID.<UID.<FINDCONT.<LOCAL._FOR>.LINK>.MORE2>.TIMER=1
   ENDIF
 ENDIF
ENDFOR


[FUNCTION check_account_typedef]
FOR 0 <eval <ACCOUNT.CHARS>-1>
 LOCAL.RETURN += <ACCOUNT.CHAR.<LOCAL._FOR>.f_check_typedefs <ARGS>>
ENDFOR
return <LOCAL.RETURN>

[FUNCTION f_check_typedefs]
FOR 0 <eval <RESCOUNT>-1>
 IF (<UID.<FINDCONT(<LOCAL._FOR>).LINK>.ISITEM>)
  IF STRMATCH("<ARGS>","<UID.<FINDCONT(<LOCAL._FOR>).LINK>.TYPE>")
   LOCAL.FOUND ++
  ENDIF
 ENDIF
ENDFOR
return <LOCAL.FOUND>


[FUNCTION area]
IF (<SERV.ITEMDEF.<ARGS>.MULTIREGION>)
 ARGS=<SERV.ITEMDEF.<ARGS>.MULTIREGION>
 return <eval ((<ARGV0>*-1)+<ARGV2>+1)*((<ARGV1>*-1)+<ARGV3>)>
ELIF (<UID.<REGION.UID>.MULTIREGION>)
 ARGS=<UID.<REGION.UID>.MULTIREGION>
 return <eval ((<ARGV0>*-1)+<ARGV2>+1)*((<ARGV1>*-1)+<ARGV3>)>
ENDIF

[FUNCTION area.x]
IF (<SERV.ITEMDEF.<ARGS>.MULTIREGION>)
 ARGS=<SERV.ITEMDEF.<ARGS>.MULTIREGION>
 return <eval (<ARGV0>*-1)+<ARGV2>+1>
ELIF (<UID.<REGION.UID>.MULTIREGION>)
 ARGS=<UID.<REGION.UID>.MULTIREGION>
 return <eval (<ARGV0>*-1)+<ARGV2>+1>
ENDIF

[FUNCTION area.y]
IF (<SERV.ITEMDEF.<ARGS>.MULTIREGION>)
 ARGS=<SERV.ITEMDEF.<ARGS>.MULTIREGION>
 return <eval (<ARGV1>*-1)+<ARGV3>>
ELIF (<UID.<REGION.UID>.MULTIREGION>)
 ARGS=<UID.<REGION.UID>.MULTIREGION>
 return <eval (<ARGV1>*-1)+<ARGV3>>
ENDIF


[FUNCTION HouseMaxVendors]
IF !(<DEF.HOUSE_USE_GLOBAL_MAXVENDORS>)
 return <eval ((<AREA.X>+<AREA.Y>)/4)+1>
ELSE
 return <dDEF.HOUSE_GLOBAL_MAXVENDORS>
ENDIF


[FUNCTION HouseSignPost]
REF1=<REGION.UID>
FORITEMS 30
 IF (<REGION.UID>==<REF1.REGION.UID>)
  IF (<LINK>==<REGION.UID>) && (<TYPE>==t_wall) && (<DISPIDDEC> < 1000)
   return <UID>
  ENDIF
 ENDIF
ENDFOR


[FUNCTION HouseFloor]
LOCAL.TERRAIN=<eval <SERV.MAP(<P.X>,<P.Y>,<P.M>).TERRAIN.Z>+5>
IF (<ARGS> > <LOCAL.TERRAIN>)
 return <eval 1+(<ARGS>-<LOCAL.TERRAIN>)/20>
ENDIF
return 0


[FUNCTION HouseCheckNearArea]
ARGS=<UID.<REGION.UID>.MULTIREGION>
SERV.NEWNPC c_pig
NEW.FLAGS=statf_invul|statf_insubstantial
FOR 0 7
 NEW.P=<UID.<REGION.UID>.P>
 DOSWITCH <LOCAL._FOR>
  NEW.MOVE <ARGV0> <ARGV1>
  NEW.MOVE 0 <ARGV1>
  NEW.MOVE <ARGV2> <ARGV1>
  NEW.MOVE <ARGV2> 0
  NEW.MOVE <ARGV2> <ARGV3>
  NEW.MOVE 0 <ARGV3>
  NEW.MOVE <ARGV0> <ARGV3>
  NEW.MOVE <ARGV0> 0
 ENDDO
 DOSWITCH <LOCAL._FOR>
  LOCAL.CLEAR=<NEW.CANMOVE nw>
  LOCAL.CLEAR=<NEW.CANMOVE n>
  LOCAL.CLEAR=<NEW.CANMOVE ne>
  LOCAL.CLEAR=<NEW.CANMOVE e>
  LOCAL.CLEAR=<NEW.CANMOVE se>
  LOCAL.CLEAR=<NEW.CANMOVE s>
  LOCAL.CLEAR=<NEW.CANMOVE sw>
  LOCAL.CLEAR=<NEW.CANMOVE w>
 ENDDO
 IF (<NEW.IsOnRoad>) || !(<LOCAL.CLEAR>) || (<NEW.ISNEARTYPE t_tree 1>)
  NEW.REMOVE
  return 1
 ENDIF
ENDFOR
IF (<DEF.PLACEMENT_MIN_DIST_AREA>)
  LOCAL.AREA=<DEF.PLACEMENT_MIN_DIST_AREA>
  FOR 0 7
   NEW.P=<UID.<REGION.UID>.P>
   DOSWITCH <LOCAL._FOR>
    NEW.MOVE <eval <ARGV0>+(<LOCAL.AREA>*-1)> <eval <ARGV1>+(<LOCAL.AREA>*-1)>
    NEW.MOVE 0 <eval <ARGV1>+(<LOCAL.AREA>*-1)>
    NEW.MOVE <eval <ARGV2>+<LOCAL.AREA>> <eval <ARGV1>+(<LOCAL.AREA>*-1)>
    NEW.MOVE <eval <ARGV2>+<LOCAL.AREA>> 0
    NEW.MOVE <eval <ARGV2>+<LOCAL.AREA>> <eval <ARGV3>+<LOCAL.AREA>>
    NEW.MOVE 0 <eval <ARGV3>+<LOCAL.AREA>>
    NEW.MOVE <eval <ARGV0>+(<LOCAL.AREA>*-1)> <eval <ARGV3>+<LOCAL.AREA>>
    NEW.MOVE <eval <ARGV0>+(<LOCAL.AREA>*-1)> 0
   ENDDO
   IF STRMATCH("t_multi*","<UID.<NEW.REGION.UID>.TYPE>")
    NEW.REMOVE
    return 2
   ENDIF
  ENDFOR
ENDIF
IF (<DEF.PLACEMENT_MIN_DIST_FRONT>)
  LOCAL.FRONT=<DEF.PLACEMENT_MIN_DIST_FRONT>
  FOR 0 5
   NEW.P=<UID.<REGION.UID>.P>
   DOSWITCH <LOCAL._FOR>
    NEW.MOVE <ARGV2> <eval <ARGV3>+<LOCAL.FRONT>>
    NEW.MOVE 0 <eval <ARGV3>+<LOCAL.FRONT>>
    NEW.MOVE <ARGV0> <eval <ARGV3>+<LOCAL.FRONT>>
    NEW.MOVE <ARGV0> <eval <ARGV1>+(<LOCAL.FRONT>*-1)>
    NEW.MOVE 0 <eval <ARGV1>+(<LOCAL.FRONT>*-1)>
    NEW.MOVE <ARGV2> <eval <ARGV1>+(<LOCAL.FRONT>*-1)>
   ENDDO
   IF STRMATCH("t_multi*","<UID.<NEW.REGION.UID>.TYPE>")
    NEW.REMOVE
    return 3
   ENDIF
  ENDFOR
ENDIF
NEW.REMOVE
return 0

[FUNCTION IsOnRoad]
LOCAL.TERRAIN=<SERV.MAP(<P.X>,<P.Y>,<P.M>).TERRAIN>
IF (<LOCAL.TERRAIN> >= 113) && (<LOCAL.TERRAIN> <= 140)
 return 1
ELIF (<LOCAL.TERRAIN> >= 232) && (<LOCAL.TERRAIN> <= 235)
 return 1
ELIF (<LOCAL.TERRAIN> >= 332) && (<LOCAL.TERRAIN> <= 335)
 return 1
ELIF (<LOCAL.TERRAIN> >= 353) && (<LOCAL.TERRAIN> <= 372)
 return 1
ELIF (<LOCAL.TERRAIN> >= 496) && (<LOCAL.TERRAIN> <= 499)
 return 1
ELIF (<LOCAL.TERRAIN> >= 622) && (<LOCAL.TERRAIN> <= 633)
 return 1
ELIF (<LOCAL.TERRAIN> >= 638) && (<LOCAL.TERRAIN> <= 641)
 return 1
ELIF (<LOCAL.TERRAIN> >= 804) && (<LOCAL.TERRAIN> <= 940)
 return 1
ELIF (<LOCAL.TERRAIN> >= 1351) && (<LOCAL.TERRAIN> <= 1366)
 return 1
ELIF (<LOCAL.TERRAIN> >= 1431) && (<LOCAL.TERRAIN> <= 1446)
 return 1
ELIF (<LOCAL.TERRAIN> >= 1966) && (<LOCAL.TERRAIN> <= 1969)
 return 1
ELIF (<LOCAL.TERRAIN> >= 1090) && (<LOCAL.TERRAIN> <= 1145)	// Sand stones
 return 1
ELIF (<LOCAL.TERRAIN> >= 1281) && (<LOCAL.TERRAIN> <= 1296)	// Sand stones
 return 1
ELIF (<LOCAL.TERRAIN> >= 9) && (<LOCAL.TERRAIN> <= 21)		// Furrows
 return 1
ELIF (<LOCAL.TERRAIN> >= 336) && (<LOCAL.TERRAIN> <= 348)	// Furrows
 return 1
ELSE
 return 0
ENDIF


[FUNCTION HouseValue]
IF (<TYPE> != t_multi_custom)
 return <VALUE>
ELSE
 return <eval <VALUE>+((((<QVAL (<isempty <ARGS>>)? <COMPONENTS>:<ARGS>> - <TAG0.COMPONENTS>)-<AREA.X>-1)*<DEF.HOUSE_COMPONENT_PRICE>))>
ENDIF


[FUNCTION HouseChangeFoundationStyle]
REF1=<REGION.UID>
REF1.REVERT
LOCAL.ITEM=<ARGS>
ARGS=<REF1.MULTIREGION>
REF1.AddItem <STRARG <LOCAL.ITEM>>,<ARGV0>,<ARGV1>,0
LOCAL.ITEM=<STREAT <LOCAL.ITEM>>
FOR <ARGV2> <eval <ARGV0>+1>
 REF1.AddItem <STRARG <LOCAL.ITEM>>,<LOCAL._FOR>,<ARGV1>,0
 REF1.AddItem <STRARG <LOCAL.ITEM>>,<LOCAL._FOR>,<eval <ARGV3>-1>,0
ENDFOR
LOCAL.ITEM=<STREAT <LOCAL.ITEM>>
FOR <eval <ARGV3>-1> <eval <ARGV1>+1>
 REF1.AddItem <STRARG <LOCAL.ITEM>>,<ARGV0>,<LOCAL._FOR>,0
 REF1.AddItem <STRARG <LOCAL.ITEM>>,<ARGV2>,<LOCAL._FOR>,0
ENDFOR
LOCAL.ITEM=<STREAT <LOCAL.ITEM>>
REF1.AddItem <STRARG <LOCAL.ITEM>>,<ARGV2>,<eval <ARGV3>-1>,0
REF1.Commit


[FUNCTION TradeWindow] //Credits to Terrikate for provide the function engine
REF1=<SRC>
REF2=<UID>
REF3=<ARGS>
IF (<REF1>==<REF2>) || !((<REF1.ISPLAYER>) && (<REF2.ISPLAYER>))
 return 1
ENDIF
FOR 2
 SERV.NEWITEM i_bulletin_board
 LOCAL.TRADE_WINDOW_<dLOCAL._FOR>=<NEW>
 NEW.TYPE t_eq_trade_window
 REF<LOCAL._FOR>.EQUIP <NEW>
ENDFOR
UID.<LOCAL.TRADE_WINDOW_1>.LINK=<LOCAL.TRADE_WINDOW_2>
UID.<LOCAL.TRADE_WINDOW_2>.LINK=<LOCAL.TRADE_WINDOW_1>
IF (<REF3>)
 REF3.CONT=<LOCAL.TRADE_WINDOW_1>
ENDIF
REF1.SENDPACKET 06F W02F B0 D<REF2> D<LOCAL.TRADE_WINDOW_1> D<LOCAL.TRADE_WINDOW_2> 01 <TradeWindow_PacketSplit <REF2.NAME>>
REF2.SENDPACKET 06F W02F B0 D<REF1> D<LOCAL.TRADE_WINDOW_2> D<LOCAL.TRADE_WINDOW_1> 01 <TradeWindow_PacketSplit <REF1.NAME>>

[FUNCTION TradeWindow_PacketSplit]
LOCAL.LENGHT=<eval STRLEN(<ARGS>)>
ARGS=<ASC <ARGS>>
FOR <eval (30-<LOCAL.LENGHT>)>
 ARGS .= " 00"
ENDFOR
return <ARGS>


[FUNCTION CodexOfWisdomDialog]
return <DEF.L1>a href = "?ForceTopic<ARGV0>"<DEF.R1><STREAT <ARGS>><DEF.L1>/a<DEF.R1>


//////////////////////////////////////////////////////////////////////////////////


[SPEECH spk_player]
ON=I wish to lock this down
IF !STRMATCH("t_multi*","<UID.<REGION.UID>.TYPE>")
 return 0
ENDIF
REF1=<UID.<SRC.REGION.UID>.MORE2>
IF (<REF1.HousePlayerAccess <SRC>> >= 3)
 IF (<REF1.House_AvaibleLockdowns>)
  SRC.TARGETF f_house_lock <REF1>
  SRC.SYSMESSAGE @,,1 Lock what down?
 ELSE
  SRC.SYSMESSAGE @,,1 You can't lock more items because you reach the House Storage limit.
 ENDIF
ENDIF

ON=I wish to secure this
IF !STRMATCH("t_multi*","<UID.<REGION.UID>.TYPE>")
 return 0
ENDIF
REF1=<UID.<SRC.REGION.UID>.MORE2>
IF (<REF1.HousePlayerAccess <SRC>> >= 3)
 IF (<REF1.House_AvaibleLockdowns>)
  SRC.TARGETF f_house_secure <REF1>
  SRC.SYSMESSAGE @,,1 Choose the item you wish to secure
 ELSE
  SRC.SYSMESSAGE @,,1 You can't secure more items because you reach the House Storage limit.
 ENDIF
ENDIF

ON=I wish to release this
IF !STRMATCH("t_multi*","<UID.<REGION.UID>.TYPE>")
 return 0
ENDIF
REF1=<UID.<SRC.REGION.UID>.MORE2>
IF (<REF1.HousePlayerAccess <SRC>> >= 3)
 SRC.TARGETF f_house_release <REF1>
 SRC.SYSMESSAGE @,,1 Choose the item you wish to release
ENDIF

ON=I ban thee
IF !(<DEF.HOUSE_USE_BAN_ENGINE>) || !STRMATCH("t_multi*","<UID.<REGION.UID>.TYPE>")
 return 0
ENDIF
REF1=<UID.<SRC.REGION.UID>.MORE2>
IF (<REF1.HousePlayerAccess <SRC>> >= 2)
 SRC.TARGETF f_house_banish <REF1>
 SRC.SYSMESSAGE @,,1 Select the individual to ban from this house.
ENDIF

ON=Remove thyself
IF !(<DEF.HOUSE_USE_BAN_ENGINE>) || !STRMATCH("t_multi*","<UID.<REGION.UID>.TYPE>")
 return 0
ENDIF
REF1=<UID.<SRC.REGION.UID>.MORE2>
IF (<REF1.HousePlayerAccess <SRC>> >= 2)
 SRC.TARGETF f_house_eject <REF1>
 SRC.SYSMESSAGE @,,1 Select the individual to eject from this house.
ENDIF

ON=I wish to place a trash barrel
IF !(<DEF.HOUSE_USE_TRASHBARREL>) || !STRMATCH("t_multi*","<UID.<REGION.UID>.TYPE>")
  return 0
ENDIF
REF1=<UID.<SRC.REGION.UID>.MORE2>
IF (<REF1.HousePlayerAccess <SRC>> >= 3)
  IF ((<SRC.ISNEARTYPE t_door 1>) || (<SRC.ISNEARTYPE t_door_locked 1>))
    SRC.SYSMESSAGE @,,1 You cannot place a trash barrel near a door or near steps.
    return 0
  ELSE
    FORITEMS 40
     IF (<BASEID> == i_trash_barrel) && (<UID.<REGION.UID>.MORE2>==<REF1>)
      P=<SRC.P>
      return 0
     ENDIF
    ENDFOR
    SERV.NEWITEM i_trash_barrel
    NEW.P=<SRC.P>
    NEW.LINK=<NEW.REGION.UID>
    SRC.SYSMESSAGE @,,1 You have a new trash barrel.  Three minutes after you put something in the barrel, the trash will be emptied.  Be forewarned, this is permanent!
  ENDIF
ENDIF

//////////////////////////////////////////////////////////////////////////////////

[ITEMDEF i_trash_barrel]
ID=i_barrel_open
NAME=trash barrel

ON=@Create
COLOR=946
ATTR=<DEF.ATTR_MOVE_NEVER>

ON=@Timer
IF !(<ATTR>&attr_decay)
	IF (<COUNT>)
	SAY @,,1 Emptying the trashcan!
	TIMERF 1,EMPTY
	RETURN 1
	ENDIF
ENDIF

ON=@DropOn_Self
IF (<COUNT> >= 50)
TIMERF 1,EMPTY
ELSE
TIMER=180
ENDIF

[TYPEDEF t_weapon_sword]
ON=@TargOn_Item
IF (<ARGO.CanSeeLos>) && (<ARGO.BASEID> == i_unholy_bone)
ARGO.TAG0.LEVEL --
	IF (!(<ARGO.TAG0.LEVEL>))
	ARGO.REMOVE
	ENDIF
Return 1
ENDIF
IF (<ARGO.CanSee>) && !STRCMP("addon","<STRSUB 2 5 <ARGO.BASEID>>")
 REF1=<UID.<ARGO.REGION.UID>.MORE2>
 IF (<REF1.IsOwner <SRC>>) || (<REF1.IsCoOwner <SRC>>)
  IF (<SERV.ITEMDEF.i_deed_<STRSUB 8 0 <ARGO.BASEID>>>)
   SERV.NEWITEM i_deed_<STRSUB 8 0 <ARGO.BASEID>>,1,<SRC.FINDLAYER.21>
  ENDIF
  SRC.FACE <ARGO.UID>
  ARGO.SOUND 011c
  ARGO.RemoveAddOn
  ARGO.REMOVE
  SRC.SYSMESSAGE @,,2 500461 //You destroy the item.
 ENDIF
 return 1
ENDIF

ON=@TargOn_Char
IF (<ARGO.OBODY> == c_armored_swamp_dragon)
SRC.SYSMESSAGELOC -1,1053031
ARGO.BODY=c_swamp_dragon
ARGO.OBODY=c_swamp_dragon
ARGO.COLOR=0
ARGO.TAG.BARDINGEFFECT=
ARGO.UPDATEX
ENDIF

//////////////////////////////////////////////////////////////////////////////////

[TYPEDEF t_door_locked]
ON=@Click
IF (<DEF.HOUSE_DOOR_ACCESS>)
 IF !(<SERV.FeatureAOS> & 04) || (<SRC.ACCOUNT.RESDISP> < 2)
  IF (<UID.<UID.<REGION.UID>.MORE2>.IsOwner <SRC>>)
   SDIALOG d_house_access
  ENDIF
 ENDIF
ENDIF

ON=@ContextMenuRequest
IF (<DEF.HOUSE_DOOR_ACCESS>)
 IF (<UID.<UID.<REGION.UID>.MORE2>.IsOwner <SRC>>)
  SRC.AddContextEntry 101,6203
 ENDIF
ENDIF

ON=@ContextMenuSelect
IF (<ARGN>==101)
 SDIALOG d_house_access
ENDIF

ON=@DClick
REF1=<UID.<REGION.UID>.MORE2>
LOCAL.RequiredAccess=<TAG0.Access>
IF !(<REF1.TAG0.Public>) && !(<TAG0.Access>)
 LOCAL.RequiredAccess=1
ENDIF
IF (<REF1.HousePlayerAccess <SRC>> >= <LOCAL.RequiredAccess>) || ((<TAG0.Access>==5) && (<SRC.GUILD> == <UID.<REF1.MORE2>.GUILD>))
 TIMER=0
 return 1
ENDIF


[TYPEDEF t_locked_down]
ON=@ClientToolTip
SRC.ADDCLILOC <QVAL (<TAG0.Access>==0)? 501643:501644>	//locked down & secure

ON=@ContextMenuRequest
IF (<TYPE> == t_container) && (<TYPE> != t_door_locked)
 IF (<UID.<UID.<REGION.UID>.MORE2>.HousePlayerAccess <SRC>> >= 3) && (<CanAccess>)
  SRC.AddContextEntry 101,6203
 ENDIF
ENDIF

ON=@ContextMenuSelect
IF (<ARGN> == 101)
 SDIALOG d_house_access
ENDIF

ON=@Click
IF (<TYPE> != t_door_locked)
 IF (<TAG0.Access>)
  MESSAGE @<COLOR> (Locked Down & Secure)
 ELSE
  MESSAGE @<COLOR> (Locked Down)
 ENDIF
ENDIF

ON=@DClick
IF (<TAG0.Access> == 5) && !(<UID.<UID.<REGION.UID>.MORE1>.GUILD>)
 TAG.Access=4
ENDIF
IF !(<CanAccess>)
 IF (<TYPE> != t_container)
  SRC.SYSMESSAGE @,,1 You are not allowed to access this.
 ELSE
  MESSAGE @,,1 That is secure.
 ENDIF
 return 1
ENDIF
IF (<IsWeapon>)
 SRC.SYSMESSAGE @,,1 The item is locked on the structure.
 return 1
ENDIF

ON=@DropOn_Self
IF (!(<CanAccess>)) && (<SRC.ISPLAYER>)
RETURN 1
ENDIF
IF !(<TAG0.Ref>)
 REF1=<ARGO.UID>
ELSE
 REF1=<TAG.Ref>
 TAG.Ref=
ENDIF
IF (<REF1.CAN>&CAN_I_PILE)
RETURN 0
ENDIF
REF2=<UID.<REGION.UID>.MORE2>
LOCAL.Items=1
IF (<REF1.TYPE> == t_container)
 LOCAL.Items += <REF1.FCOUNT>
ENDIF
IF (<TAG0.Access>)	//Secured
 IF (<REF2.House_AvaibleStorage> < <LOCAL.Items>)
  SRC.SYSMESSAGE @,,1 You reach the House Storage Limit.
  REF1.ATTR |= <DEF.attr_move_never>
  SRC.BOUNCE=<REF1.UID>
  REF1.TIMERF 1,ATTR=<HVAL <REF1.ATTR>&~<DEF.attr_move_never>>
  return 1
 ENDIF
 IF (<TYPE> == t_container)
 IF (<REF1.TYPE> == t_container)
  REF1.FixHouseSubcontainers 1
 ENDIF
 REF2.TAG0.SECURE_CONT += <LOCAL.Items>
 ENDIF
 return 0
ELSE			//Locked
 IF (<REF2.House_AvaibleLockdowns> < <LOCAL.Items>)
  SRC.SYSMESSAGE @,,1 You reach the House Storage Limit.
  REF1.ATTR |= <DEF.attr_move_never>
  SRC.TIMERF 1,BOUNCE=<REF1.UID>
  REF1.TIMERF 1,ATTR=<HVAL <REF1.ATTR>&~<DEF.attr_move_never>>
  return 1
 ENDIF
 IF (<TYPE> == t_container)
  IF (<REF1.TYPE> == t_container)
   REF1.FixHouseSubcontainers 1
  ENDIF
  REF2.TAG0.LOCKED_ITEMS += <LOCAL.Items>
 ENDIF
 return 0
ENDIF

ON=@PickUp_Self
IF !(<TAG0.Ref>)
 REF1=<ARGO.UID>
ELSE
 REF1=<TAG.Ref>
 TAG.Ref=
ENDIF
IF (<REF1.CAN>&CAN_I_PILE)
RETURN 0
ENDIF
REF2=<UID.<REGION.UID>.MORE2>
IF (<TAG0.Access>)	//Secured
 REF2.TAG0.SECURE_CONT --
 IF (<REF1.TYPE> == t_container)
  REF2.TAG0.SECURE_CONT -= <REF1.FCOUNT>
  REF1.FixHouseSubcontainers 0
 ENDIF 
 return 0
ELSE			//Locked
 REF2.TAG0.LOCKED_ITEMS --
 IF (<REF1.TYPE>==t_container)
  REF2.TAG0.LOCKED_ITEMS -= <REF1.FCOUNT>
  REF1.FixHouseSubcontainers 0
 ENDIF 
 return 0
ENDIF

ON=@Destroy
IF STRMATCH("t_multi*","<UID.<REGION.UID>.TYPE>")
 REF1=<UID.<REGION.UID>.MORE2>
 REF1.TAG0.LOCKED_ITEMS --
 IF (<TYPE> == t_container)
   IF (<TAG0.Access>)	//Secured
    REF1.TAG0.SECURE_CONT -= <FCOUNT>
   ELSE			//Locked
    REF1.TAG0.LOCKED_ITEMS -= <FCOUNT>
   ENDIF
 ENDIF
ENDIF

[TYPEDEF t_subcont]
ON=@DropOn_Self
IF (!(<CANACCESS>))
RETURN 1
ENDIF
IF (<TOPOBJ.UID> != <UID>)
TOPOBJ.TAG.Ref=<ARGO.UID>
TOPOBJ.TRIGGER @DropOn_Self
ENDIF

ON=@PickUp_Self
IF (!(<CANACCESS>))
RETURN 1
ENDIF
IF (<TOPOBJ.UID> != <UID>)
TOPOBJ.TAG.Ref=<ARGO.UID>
TOPOBJ.TRIGGER @PickUp_Self
ENDIF

[TYPEDEF t_telepad_house]
ON=@ContextMenuRequest
IF (<UID.<UID.<REGION.UID>.MORE2>.HousePlayerAccess <SRC>> >= 3) && (<CanAccess>)
 SRC.AddContextEntry 101,6203
ENDIF

ON=@ContextMenuSelect
IF (<ARGN>==101)
 SDIALOG d_house_access
ENDIF

ON=@Step
IF (<TAG0.Access>==5) && !(<UID.<UID.<REGION.UID>.MORE1>.GUILD>)
 TAG.Access=4
ENDIF
IF !(<CanAccess>)
 SRC.SYSMESSAGE @,,1 You are not allowed to access this.
 return 1
ENDIF


[FUNCTION update_rescount]
REF1=<UID.<REGION.UID>.MORE2>
IF (<TAG0.Access>)	//Secured
 REF1.TAG0.SECURE_CONT += <FCOUNT>
ELSE			//Locked
 REF1.TAG0.LOCKED_ITEMS += <FCOUNT>
ENDIF


//////////////////////////////////////////////////////////////////////////////////


[FUNCTION Notice]
IF (<ISPLAYER>)
  IF (<DEF.USE_NOTICE_SYSTEM>)
    TAG.NOTICE=<ARGS>
    EVENTS +e_notice
    IF (<ISONLINE>)
     TIMERF 1,DIALOG d_notice
    ENDIF
  ELSE
    IF (<ISONLINE>)
     SYSMESSAGE @,,1 <ARGS>
    ENDIF
  ENDIF
ENDIF


[EVENTS e_notice]
ON=@Login
SDIALOG d_notice


[DIALOG d_notice]
160,150
noclose

resizepic 0 0 5054 320 180
gumppictiled 10 10 300 20 2624
checkertrans 10 10 300 20
dhtmlgump 10 10 300 20 0 0 <DEF.L1>basefont color="#f70000"<DEF.R1><DEF.CENTER>NOTICE
gumppictiled 10 40 300 100 2624
checkertrans 10 40 300 100
gumppictiled 10 150 300 20 2624
checkertrans 10 150 300 20
button 10 150 4005 4007 1 0 0
dtext 40 150 1152 OKAY
dhtmlgump 10 40 300 100 0 1 <DEF.L1>basefont color="#ffc600"<DEF.R1><TAG0.NOTICE>

[DIALOG d_notice BUTTON]
ON=0
TAG.NOTICE=
EVENTS -e_notice


//////////////////////////////////////////////////////////////////////////////////


[ITEMDEF i_house_placement_tool]
ID=014f6
NAME=House Placement Tool
VALUE=600
DUPELIST=014f5

ON=@DClick
SDIALOG d_house_placement_tool
return 1

[DIALOG d_house_placement_tool]
50,50

page 0
IF !(<SRC.ISGM>) && (<DEF0.PLACEMENT_WAITING_PERIOD>) && (<SRC.TAG0.House.PlacementDelay> > <SERV.TIME>)
 LOCAL.X=330
 LOCAL.Y=220
ELSE
 LOCAL.X=250
 LOCAL.Y=125
ENDIF
resizepic 0 0 5054 <eval <LOCAL.X>+20> <eval <LOCAL.Y>+20>
gumppictiled 10 10 <dLOCAL.X> <dLOCAL.Y> 2624
checkertrans 10 10 <dLOCAL.X> <dLOCAL.Y>
dhtmlgump 10 10 <LOCAL.X> 20 0 0 <DEF.BFONT_white><DEF.CENTER>HOUSE PLACEMENT TOOL<DEF.CENTERE>
button 10 40 4005 4007 1 0 1
dtext 45 40 1152 Classic Houses
button 10 60 4005 4007 1 0 2
dtext 45 60 1152 2-Story Customizable Houses
button 10 80 4005 4007 1 0 3
dtext 45 80 1152 3-Story Customizable Houses
IF !(<SRC.ISGM>) && (<DEF0.PLACEMENT_WAITING_PERIOD>) && (<SRC.TAG0.House.PlacementDelay> > <SERV.TIME>)
 dhtmlgump 10 105 330 90 0 0 <DEF.BFONT_yellow>You are currently unable to place a new house or receive a house in trade because you have become the owner of a house within the last <dDEF0.PLACEMENT_WAITING_PERIOD> days.  You can test for house placement right now, but you cannot currently create a permanent house.
 LOCAL.Y=205
ELSE
 LOCAL.Y=110
ENDIF
button 10 <LOCAL.Y> 4017 4019 1 0 0
dtext 45 <LOCAL.Y> 1152 Close

[DIALOG d_house_placement_tool BUTTON]
ON=1
SDIALOG d_house_placement_tool_classic

ON=2
SDIALOG d_house_placement_tool_custom_2story

ON=3
SDIALOG d_house_placement_tool_custom_3story

[FUNCTION RenderPlacementToolDialogBackground]
resizepic 0 0 5054 520 420
gumppictiled 10 10 500 20 2624
checkertrans 10 10 500 20
dhtmlgump 10 10 500 20 0 0 <DEF.BFONT_white><DEF.CENTER>HOUSE PLACEMENT TOOL<DEF.CENTERE>
gumppictiled 10 40 500 20 2624
checkertrans 10 40 500 20
dtext 50 40 1152 House Description
dtext 275 40 1152 Storage
dtext 350 40 1152 Lockdowns
dtext 425 40 1152 Cost
gumppictiled 10 70 500 280 2624
checkertrans 10 70 500 280
gumppictiled 10 360 500 20 2624
checkertrans 10 360 500 20
dtext 10 360 1152 Bank Balance:
dtext 250 360 1152 <SRC.BANKBALANCE>
gumppictiled 10 390 500 20 2624
checkertrans 10 390 500 20
button 10 390 4017 4019 1 0 0
dtext 50 390 1152 Close

[FUNCTION RenderPlacementToolDialogPage]
IF (<LOCAL.Y> > 340)
 button 450 390 4005 4007 0 <eval <LOCAL.PAGE>+1> 0
 dtext 400 390 1152 Next
 LOCAL.PAGE ++
 page <LOCAL.PAGE>
 button 200 390 4014 4016 0 <eval <LOCAL.PAGE>-1> 0
 dtext 250 390 1152 Previous
 LOCAL.Y=70
ENDIF



[DIALOG d_house_placement_tool_classic]
50,50

page 0
RenderPlacementToolDialogBackground

page 1
LOCAL.PAGE=1
LOCAL.Y=70
FOR 1 20
 IF (<SERV.ITEMDEF.<DEF.house_classic_<dlocal._for>>>)
  LOCAL.STORAGE=<AreaStorage (<AREA <DEF.house_classic_<dlocal._for>>>)>
  button 10 <LOCAL.Y> 4005 4007 1 0 <local._for>
  dtext 50 <LOCAL.Y> 1152 <SERV.ITEMDEF.<DEF.house_classic_<dlocal._for>>.NAME>
  dtext 275 <LOCAL.Y> 1152 <dLOCAL.Storage>
  dtext 350 <LOCAL.Y> 1152 <eval <LOCAL.Storage>/2>
  dtext 425 <LOCAL.Y> 1152 <SERV.ITEMDEF.<DEF.house_classic_<dlocal._for>>.VALUE>
  LOCAL.Y += 20
  CALL RenderPlacementToolDialogPage
 ENDIF
ENDFOR

[DIALOG d_house_placement_tool_classic BUTTON]
ON=0
SDIALOG d_house_placement_tool

ON=1 20
SRC.f_house_placement <DEF.house_classic_<ARGN>>



[DIALOG d_house_placement_tool_custom_2story]
50,50

page 0
RenderPlacementToolDialogBackground

page 1
LOCAL.PAGE=1
LOCAL.Y=70
FOR 1 47
 IF (<SERV.ITEMDEF.<DEF.house_custom_2story_<dlocal._for>>>)
  LOCAL.STORAGE=<AreaStorage (<AREA <DEF.house_custom_2story_<dlocal._for>>>)>
  button 10 <LOCAL.Y> 4005 4007 1 0 <local._for>
  dtext 50 <LOCAL.Y> 1152 <SERV.ITEMDEF.<DEF.house_custom_2story_<dlocal._for>>.NAME>
  dtext 275 <LOCAL.Y> 1152 <dLOCAL.Storage>
  dtext 350 <LOCAL.Y> 1152 <eval <LOCAL.Storage>/2>
  dtext 425 <LOCAL.Y> 1152 <SERV.ITEMDEF.<DEF.house_custom_2story_<dlocal._for>>.VALUE>
  LOCAL.Y += 20
  CALL RenderPlacementToolDialogPage
 ENDIF
ENDFOR

[DIALOG d_house_placement_tool_custom_2story BUTTON]
ON=0
SDIALOG d_house_placement_tool

ON=1 47
SRC.f_house_placement <DEF.house_custom_2story_<ARGN>>



[DIALOG d_house_placement_tool_custom_3story]
50,50

page 0
RenderPlacementToolDialogBackground

page 1
LOCAL.PAGE=1
LOCAL.Y=70
FOR 1 55
 IF (<SERV.ITEMDEF.<DEF.house_custom_3story_<dlocal._for>>>)
  LOCAL.STORAGE=<AreaStorage (<AREA <DEF.house_custom_3story_<dlocal._for>>>)>
  button 10 <LOCAL.Y> 4005 4007 1 0 <local._for>
  dtext 50 <LOCAL.Y> 1152 <SERV.ITEMDEF.<DEF.house_custom_3story_<dlocal._for>>.NAME>
  dtext 275 <LOCAL.Y> 1152 <dLOCAL.Storage>
  dtext 350 <LOCAL.Y> 1152 <eval <LOCAL.Storage>/2>
  dtext 425 <LOCAL.Y> 1152 <SERV.ITEMDEF.<DEF.house_custom_3story_<dlocal._for>>.VALUE>
  LOCAL.Y += 20
  CALL RenderPlacementToolDialogPage
 ENDIF
ENDFOR

[DIALOG d_house_placement_tool_custom_3story BUTTON]
ON=0
SDIALOG d_house_placement_tool

ON=1 55
SRC.f_house_placement <DEF.house_custom_3story_<ARGN>>


////////////////////////////////////////


[FUNCTION f_house_placement]
SERV.NEWITEM i_gold
NEW.TYPE=t_deed
NEW.MORE1=<ARGS>
NEW.CONT <SRC.FINDLAYER.21>
NEW.REMOVEFROMVIEW
NEW.USE


[TYPEDEF t_deed]
ON=@DClick
IF (<CONT> != <SRC.FINDLAYER.21>)
  SRC.SYSMESSAGE @,,1 The item must be on your backpack.
  return 1
ELIF !(<SRC.ISGM>)
  IF STRMATCH("t_multi*","<SERV.ITEMDEF.<MORE1>.TYPE>")
   IF (<SRC.CHECK_ACCOUNT_TYPEDEF t_multi*> >= <DEF.MAX_ACCOUNT_HOUSES>)
    SRC.SYSMESSAGE @,,1 You already own <QVAL (<DEF.MAX_ACCOUNT_HOUSES>==1)? a house:<dDEF.MAX_ACCOUNT_HOUSES> houses>, you may not place another!
    TRIGGER @TargOn_Cancel
    return 1
   ENDIF
  ENDIF
ENDIF
IF (<DISPID>==i_gold)
 TIMERF 60,TRIGGER @TargOn_Cancel
ENDIF

ON=@TargOn_Ground
IF !(<SRC.ISGM>)
  IF !STRMATCH("*ship*","<BASEID>")
    IF (<SRC.TAG0.House.PlacementDelay> > <SERV.TIME>)
      SRC.SYSMESSAGE @,,1 Number of days until you can place another house: <eval (<SRC.TAG0.House.PlacementDelay>-<SERV.TIME>)/864000>
      return 1
    ELIF !(<DEF.PLACEMENT_ILSHENAR_FACET>) && (<SRC.TARGP.M>==2)
      SRC.SYSMESSAGE @,,1 Housing cannot be created in this area.
      TRIGGER @TargOn_Cancel
      return 1
    ENDIF
  ENDIF
  SRC.TIMERF 1,HouseIsPlaced <MORE1> <BASEID> <SRC.TARGP>
ENDIF

ON=@TargOn_Char
SRC.SYSMESSAGE @,,1 You must place your house on ground.
TRIGGER @TargOn_Cancel
return 1

ON=@TargOn_Item
SRC.SYSMESSAGE @,,1 You must place your house on ground.
TRIGGER @TargOn_Cancel
return 1

ON=@TargOn_Cancel
IF (<DISPID>==i_gold)
 SRC.SDIALOG d_house_placement_tool
 REMOVE
ENDIF


[FUNCTION HouseIsPlaced]
SERV.NEWITEM i_gold
NEW.P <STREAT <STREAT <ARGS>>>
NEW.REMOVEFROMVIEW
REF1=<NEW.REGION.UID>
IF (<REF1.DISPID>==<STRARG <ARGS>>)
 REF1.TAG.PLACEMENT=<STRARG <STREAT <ARGS>>>
ENDIF
NEW.REMOVE

//////////////////////////////////////////////////////////////////////////////////

[ITEMDEF i_house_interior_decorator]
ID=0fc1
NAME=Interior Decorator
VALUE=10000

ON=@ClientToolTip
IF (<TAG0.MODE>)
 SRC.ADDCLILOC <eval 1018322+<TAG0.MODE>>
ENDIF

ON=@Click
IF (<TAG0.MODE>==1)
 MESSAGE (turn)
ELIF (<TAG0.MODE>==2)
 MESSAGE (up)
ELIF (<TAG0.MODE>==3)
 MESSAGE (down)
ENDIF

ON=@DClick
REF1=<REGION.UID>
IF (<CONT.TOPOBJ> != <SRC>)
 SRC.SYSMESSAGE @,,1 That must be in your pack for you to use it.
 return 1
ELIF !(<SRC.IsOnHouse>) || (<UID.<REF1.MORE2>.HousePlayerAccess <SRC>> < 3)
 SRC.SYSMESSAGE @,,1 You must be in your house to do this.
 return 1
ELIF !(<TAG0.MODE>)
 SDIALOG d_house_interior_decorator
ELSE
 TAG.House=<REGION.UID>
 TARGET
ENDIF
return 1

ON=@TargOn_Char
TAG.House=
return 1

ON=@TargOn_Cancel
TAG.House=

ON=@TargOn_Item
IF (<ARGO.UID> == <UID>)
  TAG.House=
  TAG.Mode=
  SDIALOG d_house_interior_decorator
  return 1
ELSE
  IF (<SRC.REGION.UID> != <TAG0.HOUSE>) || !(<SRC.IsOnHouse>)
    SRC.SYSMESSAGE @,,1 You must be in your house to do this.
  ELIF (<ARGO.CONT>) || (<ARGO.REGION.UID> != <TAG0.HOUSE>) || !(<ARGO.IsOnHouse>)
    SRC.SYSMESSAGE @,,1 That is not in your house.
  ELIF !(<ARGO.IsStorage>)
    SRC.SYSMESSAGE @,,1 That is not locked down.
  ELIF (<ARGO.WEIGHT> > 100)
    SRC.SYSMESSAGE @,,1 That is too heavy.
  ELSE
    TAG.House=
    IF (<TAG0.Mode>==1)
      IF !(<ARGO.FLIP>)
       SRC.SYSMESSAGE @,,1 You cannot turn that.
      ELSE
       ARGO.FLIP
      ENDIF
      return 1
    ELIF (<TAG0.MODE>==2)
      IF (<ARGO.HouseFloor <ARGO.Z>> != <ARGO.HouseFloor <eval <ARGO.Z>+<ARGO.HEIGHT>+3>>)
       SRC.SYSMESSAGE @,,1 You cannot raise it up any higher.
      ELSE
       ARGO.NUDGEUP
      ENDIF
      return 1
    ELIF (<TAG0.MODE>==3)
      IF (<ARGO.HouseFloor <ARGO.Z>> != <ARGO.HouseFloor <eval <ARGO.Z>-1>>)
       SRC.SYSMESSAGE @,,1 You cannot lower it down any further.
      ELSE
       ARGO.NUDGEDOWN
      ENDIF
      return 1
    ENDIF
  ENDIF
  return 1
ENDIF


[DIALOG d_house_interior_decorator]
150,50

resizepic 0 0 2600 200 200
button 50 45 2152 2154 1 0 1
dhtmlgump 90 50 70 40 0 0 Turn
button 50 95 2152 2154 1 0 2
dhtmlgump 90 100 70 40 0 0 Up
button 50 145 2152 2154 1 0 3
dhtmlgump 90 150 70 40 0 0 Down

[DIALOG d_house_interior_decorator BUTTON]
ON=1 3
TAG.Mode=<ARGN>
DClick

//////////////////////////////////////////////////////////////////////////////////

[EVENTS e_house_customize]
ON=@SkillStart
SYSMESSAGE @,,1 You cannot do that while customizing a house.
return 1

ON=@SkillUseQuick
return 1

ON=@GetHit
return 1

ON=@Login
TRIGGER @HouseDesignExit

ON=@DClick
SYSMESSAGE @,,1 You cannot do that while customizing a house.
return 1

ON=@ItemDClick
SYSMESSAGE @,,1 You cannot do that while customizing a house.
return 1

ON=@HouseDesignCommit
LOCAL.CURCOST=(<ARGN2>-<ARGN1>)*<DEF.HOUSE_COMPONENT_PRICE>
LOCAL.OLDCOST=(<ARGO.HouseValue <ARGN1>>*<DEF.DEMOLISH_REFUND_PERCENT>)/100
LOCAL.NEWCOST=<LOCAL.OLDCOST>+<LOCAL.CURCOST>
ARGO.TAG.CUSTOMIZE.INFO=<LOCAL.OLDCOST>,<LOCAL.NEWCOST>,<LOCAL.CURCOST>
ARGO.SDIALOG d_house_customize_commit
return 1

ON=@HouseDesignExit
EVENTS -e_house_customize
DSPEECH -spk_house_customize
ARGO.F_InvisTeleporters

[DIALOG d_house_customize_commit]
50,50

ARGS=<TAG0.CUSTOMIZE.INFO>
resizepic 0 0 5054 320 320
gumppictiled 10 10 300 20 2624
gumppictiled 10 40 300 240 2624
gumppictiled 10 290 300 20 2624
checkertrans 10 10 300 300
dhtmlgump 10 10 300 20 0 0 <DEF.L1>basefont color="#fffC00"<DEF.R1><DEF.CENTER>COMMIT DESIGN
dhtmlgump 10 40 300 140 0 1 <DEF.L1>basefont color="#ff3ff"<DEF.R1>You are about to Commit your current house design.  In order to do so, you must pay the difference between the house's current value and the cost given on the house builder menu.  If the new cost of your house is less than its old value, you will receive a refund.
dhtmlgump 10 190 150 20 0 0 <DEF.L1>basefont color="#fffC00"<DEF.R1>Bank Balance:
dtext 170 190 55 <SRC.BANKBALANCE>
dhtmlgump 10 215 150 20 0 0 <DEF.L1>basefont color="#ff3ff"<DEF.R1>Old Value:
dtext 170 215 90 <dARGV[0]>
dhtmlgump 10 235 150 20 0 0 <DEF.L1>basefont color="#ff3ff"<DEF.R1>Cost To Commit:
dtext 170 235 90 <dARGV[1]>
dhtmlgump 10 260 150 20 0 0 <DEF.L1>basefont color="#f01C00"<DEF.R1>Your Cost:
dtext 170 260 40 <dARGV[2]>
button 10 290 4005 4007 1 0 1
dhtmlgump 45 290 80 20 0 0 <DEF.BFONT_WHITE>OKAY
button 170 290 4005 4007 1 0 0
dhtmlgump 205 290 80 20 0 0 <DEF.BFONT_WHITE>CANCEL

[DIALOG d_house_customize_commit BUTTON]
ON=0 1
IF (<ARGN>==1)
 ARGS=<TAG.CUSTOMIZE.INFO>
 LOCAL.OLDCOST = <dARGV[0]>
 LOCAL.NEWCOST = <dARGV[1]>
 LOCAL.CURCOST = <dARGV[2]>
 IF (<SRC.ISGM>)
   IF (<LOCAL.CURCOST> < 0)
    SRC.SYSMESSAGE @,,1 <eval <LOCAL.CURCOST>*-1> gold would have been deposited into your bank if you were not a GM.
   ELIF (<LOCAL.CURCOST> > 0)
    SRC.SYSMESSAGE @,,1 <dLOCAL.CURCOST> gold would have been withdrawn from your bank if you were not a GM.
   ENDIF
 ELSE
   IF (<SRC.BANKBALANCE> < <LOCAL.CURCOST>)
    SRC.SYSMESSAGE @,,1 You cannot afford this house design.
    return 1
   ENDIF
   SRC.SYSMESSAGE @,,1 Your new house design has been committed.
   IF (<LOCAL.CURCOST> == 0)
    SRC.SYSMESSAGE @,,1 As the new design costs the same as the previous one, no gold has been taken out of your account.
   ELIF (<LOCAL.CURCOST> < 0)
    LOCAL.CURCOST = <eval ((<LOCAL.CURCOST>*-1)*<DEF.DEMOLISH_REFUND_PERCENT>)/100>
    SRC.GOLD += <dLOCAL.CURCOST>
    SRC.SYSMESSAGE @,,1 As the new design is cheaper than the previous one, <dLOCAL.CURCOST> gold has been returned to you.
   ELSE
    SRC.GOLD -= <dLOCAL.CURCOST>
    SRC.SYSMESSAGE @,,1 <dLOCAL.CURCOST> gold has been taken out of your account to pay for the construction.
   ENDIF
 ENDIF
 COMMIT
 ENDCUSTOMIZE
	LIST.HouseCustomizationTeleporters.ADD=0
	FixTeleporters
	LOCAL.OLDNEW=<NEW>
		FOR 0 <EVAL <COMPONENTS>-1>
			IF (<ISTELEPORTER <DESIGN.<dLOCAL._FOR>.ID>>
			SERV.NEWITEM=<DESIGN.<dLOCAL._FOR>.ID>
			NEW.TYPE=T_TELEPAD
			NEW.P=<P>
			NEW.ATTR |= <DEF.Attr_Move_Never>
			NEW.MOVE=<DESIGN.<dLOCAL._FOR>.D>
			NEW.LINK=<UID>
			LIST.HouseCustomizationTeleporters.ADD=<NEW.UID>
			ENDIF
		ENDFOR
		IF (<LIST.HouseCustomizationTeleporters.COUNT> > 1)
		LIST.HouseCustomizationTeleporters.0.REMOVE
		F_LinkTeleporters
		ENDIF
	NEW=<LOCAL.OLDNEW>
	LIST.HouseCustomizationTeleporters.CLEAR
 FixCustomization
ENDIF
TAG.CUSTOMIZE.INFO=

[FUNCTION F_LinkTeleporters]
REF2=<REGION.UID>
FORITEMS 30
	IF (<LINK> == <REF2>)
		IF (<TYPE> == t_telepad)
			FOR 0 <EVAL <LIST.HouseCustomizationTeleporters.COUNT>-1>
			REF1=<LIST.HouseCustomizationTeleporters.<dLOCAL._FOR>>
				IF (<REF1.ID> == <ID>) && (<REF1> != <UID>)
				REF1.MOREP=<P>
				MOREP=<REF1.P>
				ENDIF
			ENDFOR
		ENDIF
	ENDIF
ENDFOR

[FUNCTION ISTELEPORTER]
FILE.MODE.READFLAG=1
IF (<FILE.OPEN Data/Teleporters.cfg>)
LOCAL.LINES=<FILE.FILELINES <FILE.FILEPATH>>
	FOR <dLOCAL.LINES>
		IF (<ARGN1> == <FILE.READLINE <dLOCAL._FOR>>)
		FILE.CLOSE
		RETURN 1
		ENDIF
	ENDFOR
FILE.CLOSE
RETURN 0
ENDIF
SERV.LOG File not found! (Teleporters.cfg)
RETURN

[FUNCTION F_InvisTeleporters]
REF1=<REGION.UID>
FORITEMS 30
 IF (<LINK> == <REF1>)
   IF (<TYPE> == t_telepad)
	IF !(<ATTR>&ATTR_INVIS)
	ATTR |= <DEF.ATTR_INVIS>
	REMOVEFROMVIEW
	ELSE
	ATTR &= ~<DEF.ATTR_INVIS>
	UPDATE
	ENDIF
   ENDIF
 ENDIF
ENDFOR

[FUNCTION FixTeleporters]
REF1=<REGION.UID>
FORITEMS 30
 IF (<LINK> == <REF1>)
   IF (<TYPE> == t_telepad)
    REMOVE
   ENDIF
 ENDIF
ENDFOR

[FUNCTION FixCustomization]
REF1=<REGION.UID>
FORITEMS 30
 IF (<LINK> == <REF1>)
   IF (<TYPE> == t_door)
    TYPE=t_door_locked
   ELIF (<TYPE> == t_telepad)
    EVENTS=+t_telepad_house
   ENDIF
 ENDIF
ENDFOR

[SPEECH spk_house_customize]
ON=*
SRC.SYSMESSAGE @,,1 You cannot speak while customizing your house.
return 1

[EOF]