////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//********       MADE BY SaCi         
//******** MSN rodrigothyr@hotmail.com   
//******** E-mail: RodrigoGm@Sercomtel.Com.Br
//******** DON'T REMOVE THIS, TKS   
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// REQUIREMENTS
//	* Sphere February 09 2007, or newer
//	* Client 4.0.0 or above
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Instaling the script:
// First Step: 
//		Add this code in C:\Sphere\scripts\sphere_speech.scp
//		below ON=TRANSFER in line 56 in default script.
//			IF (<TAG0.SALARY>)
//			RETURN 1
//			ENDIF
//
// Second Step:
//		Add this code in C:\Sphere\Sphere.ini below the line [Sphere]
//			PACKET149=f_hue_picker
//
// Third Step:
//		Add this event to all you players E_VENDORPLAYER, the way you think that is better
//		I sugest to add the line "Events +E_VENDORPLAYER" in sphere_skill below [SKILLCLASS 0] section
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Configurations: 
[DEFNAME VENDORPLAYER]
AOS_TOOL_POPUS		1	// If your Aos tooltips and popus are off or on (0/1) 
HOUSEVENDOR		1	// If you can't create vendor in your house (0/1)
AREAVENDOR		no	// If you don't have a shop area set "no", If you have set the name of this area like "Britain"
AMOUNTVENDOR		15	// If there ins't limit of vendors to create set "0", else set the limit of it
VENDORBUYING		1	// If the features of vendor buying are on or off (0/1)
GETMONEYFROM		1	// 1 = Get money from bag and bank | 0 = Get money only from bag

// Don't change this below
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// New script references
MALESTYLE		i_hair_short,i_hair_long,i_hair_ponytail,i_hair_mohawk,i_hair_pageboy,i_hair_afro,i_hair_receding,i_hair_2_pigtails,i_hair_krisna,i_beard_long,i_beard_short,i_beard_goatee,i_beard_mustache,i_beard_short_med,i_beard_long_med,i_beard_vandyke
fixe_random_male_tops		{ i_doublet 1 i_tunic 1 i_robe 1 }
fixe_random_female_pants	{ i_pants_short 1 i_pants_long 1 i_kilt 1 i_skirt_long 1 }
BFONT_SHOPNAME	<basefont color="#ff8880">
BFONT_MBLUE	<basefont color="#888FFF">
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Translate areae
// Speech & Sysmessages & Text 
//Sysmessages
SYS_OBSERVATION		"Obs.:
SYS_NOTDROPON		You can only drop itens in Not-For-Sale container.
SYS_NOCHANGESEX		You can't change the sex of your vendor so fast.
SYS_DESCSOBIG		Your description was so big, it wasn't set.
SYS_SHOPRENAME		Your Shop has been renamed.
SYS_NOTENOUGHMONEY	You don't have gold enough in your bag to buy this item
SYS_PAYAMOUNT		Enter the amount of money do you want to pay for each item:
SYS_BUYINGAMOUT		Enter the buying amount limit for this item:
SYS_AMOUNTGOLD		Enter the amount of gold you wish to withdraw (ESC = CANCEL):
SYS_ITEMREFERENCE	Select an item like reference:
SYS_ALLSLOTS		All slots are in use.
SYS_SLOTEMPTY		Slot empty:
SYS_DATACHANGED		The data has changed
SYS_MESSAGE		Wrong information
SYS_MUCHITEM		doesn't want this amount of item
SYS_NOITEMENOGOUH	You don't have this amount of item in your bag

//Vendor speech
SAY_VENDORNOHOLDMONEY_1 I'm sorry, but I'm only holding
SAY_VENDORNOHOLDMONEY_2	gold for you.

SAY_HOWMUCHGOLD_1	How much of the
SAY_HOWMUCHGOLD_2	that I'm holding would you like?

SAY_WITHOUMONEY_1	Excuse, I don't have enough money now to buy this amount of
SAY_WITHOUMONEY_2	Can you come back here later?

SAY_TOHEAVY		Excuse, it's so heavy to me! I can't hold

//Dialog
DLG_DISMISSVENDOR	Dismiss Vendor
DLG_COLLECTGOLD		Collect Gold
DLG_LISTSTUFF		List of buying stuff
DLG_LISTBUYING		LIST OF BUYING 
DLG_ADDITEMTOLIST	ADD ITEM TO LIST 
DLG_CLOSE		CLOSE
DLG_ITEMNAME		ITEM NAME
DLG_PRICE		PRICE
DLG_AMOUNT		AMOUNT

DLG_VENDORTEXT_1	Hi
DLG_VENDORTEXT_2	, my name is
DLG_VENDORTEXT_3	I saw that you have some
DLG_VENDORTEXT_4	with you, and I'd like to buy!
DLG_VENDORTEXT_5	Would you like to sell me your
DLG_VENDORTEXT_6	I can pay
DLG_VENDORTEXT_7	golds for each one
DLG_VENDORTEXT_8	I need
DLG_VENDORTEXT_9	, and I have enough gold to buy
DLG_VENDORTEXT_10	all
DLG_VENDORTEXT_11	I need from you.
DLG_VENDORTEXT_12	from you
DLG_VENDORTEXT_13	Hun.... and I can hold

//Tag values
SET_BOUGHTVENDOR	Item bought by the vendor to it's owner.
SET_SHOPNONAME		Shop Not Yet Named
SET_VENDORNAME		's Vendor
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
//////////////	ITEMS
///////////////////////////////////////////////////////////////////////////////

[ITEMDEF I_DEED_VENDOR_POD] 
NAME=Contract Of Employment
ID=i_deed
TYPE=t_normal
VALUE=1500

ON=@Create
COLOR=0

ON=@DCLICK
IF !(<SRC.ISGM>)
	IF (<TOPOBJ.UID>!=<SRC>)
		SRC.SYSMESSAGE @,,2 1042001 // That must be in your pack for you to use it.
		RETURN 1
	ENDIF
	IF (<DEF.AMOUNTVENDOR>!=0) && (<SRC.TAG0.VENDORS> >= <DEF.AMOUNTVENDOR>)
		SRC.SYSMESSAGE @,3,1 You reach the limit of vendors
		RETURN 1
	ENDIF
IF ((<DEF.HOUSEVENDOR>==1) && !(STRMATCH(NO,<DEF.AREAVENDOR>))
	IF !(0<UID.<SRC.REGION.UID>.MORE1>) && !(STRMATCH(<SRC.REGION.NAME>,<DEF.AREAVENDOR>))
		SRC.SYSMESSAGE @,,2 503250 // Vendors are unable to be created there
		RETURN 1 
	ENDIF
	REF1 <SRC.UID>
	FORCHARS 0
		IF (<ID>==C_VENDOR_PLAYER)
			REF1.SYSMESSAGE @,,2 1010647 //You may not place vendors at this location while other beings occupy it.
			RETURN 1
		ENDIF
	ENDFOR
	IF (STRMATCH(<SRC.REGION.NAME>,<DEF.AREAVENDOR>))
	ELIF !(0<UID.<SRC.REGION.UID>.MORE1>==<SRC>)
		SRC.SYSMESSAGE @,,2 1062423 // Only the house owner can directly place vendors.  Please ask the house owner to offer you a vendor contract so that you may place a vendor in this house.
		RETURN 1 
	ENDIF
ELIF (<DEF.HOUSEVENDOR>==0) && !(STRMATCH(NO,<DEF.AREAVENDOR>))
	IF !(STRMATCH(<SRC.REGION.NAME>,<DEF.AREAVENDOR>))
		SRC.SYSMESSAGE @,,2 503250 // Vendors are unable to be created there
		RETURN 1
	ELSE
		REF1 <SRC.UID>
		FORCHARS 0
			IF (<ID>==C_VENDOR_PLAYER)
				REF1.SYSMESSAGE @,,2 1010647 //You may not place vendors at this location while other beings occupy it.
				RETURN 1
			ENDIF
		ENDFOR
	ENDIF
ELIF (<DEF.HOUSEVENDOR>==1) && (STRMATCH(NO,<DEF.AREAVENDOR>))
	REF1 <SRC.UID>
	FORCHARS 0
		IF (<ID>==C_VENDOR_PLAYER)
			REF1.SYSMESSAGE @,,2 1010647 //You may not place vendors at this location while other beings occupy it.
			RETURN 1
		ENDIF
	ENDFOR
	IF !(0<UID.<SRC.REGION.UID>.MORE1>)
		SRC.SYSMESSAGE @,,2 503240 // Vendors can only be placed in houses.
		RETURN 1
	ENDIF
	IF !(0<UID.<SRC.REGION.UID>.MORE1>==<SRC>)
		SRC.SYSMESSAGE @,,2 1062423 // Only the house owner can directly place vendors.  Please ask the house owner to offer you a vendor contract so that you may place a vendor in this house.
		RETURN 1 
	ENDIF
ENDIF
ENDIF
SERV.NEWNPC C_VENDOR_PLAYER
NEW.P <SRC.P>
NEW.UPDATEX
NEW.TAG.OWNER <SRC>
NEW.TAG.NAMESHOP <DEF.SET_SHOPNONAME>
NEW.TAG.CREATED <SERV.RTIME.FORMAT %d>
NEW.TITLE <SRC.NAME><DEF.SET_VENDORNAME>
IF (<SRC.ISGM>)
	NEW.TAG.MADEBYGM 1
ENDIF
REF1 <NEW.UID>
SERV.NEWITEM i_memory
NEW.LINK=<SRC.UID>
NEW.COLOR=<DEF.MEMORY_IPET>
NEW.CONT=<REF1>
SERV.NEWITEM I_GETSALARY
NEW.CONT=<REF1>
NEW.TIMER 3600
SRC.FIX
SRC.TAG0.VENDORS ++
SRC.SYSMESSAGE @,,2 503246
REMOVE
RETURN 1

[itemdef I_GETSALARY] 
ID=i_memory
TYPE=t_eq_script
NAME=SALARY MEMORY

ON=@CREATE
COLOR 456

ON=@TIMER
CONT.F_CHARGEPERDAY
IF (<SERV.RTIME.FORMAT %d>!=<CONT.DTAG.CREATED>)
	IF (<CONT.DTAG0.GOLDHOLD> >= <CONT.TAG0.SALARY>)
		CONT.TAG0.GOLDHOLD -= <CONT.TAG0.SALARY>
		CONT.TAG.CREATED <SERV.RTIME.FORMAT %d>
	ELSE
		CONT.SENDITENSTOOWNER
		REMOVE
	ENDIF
ENDIF
TIMER 3600
RETURN 1

///////////////////////////////////////////////////////////////////////////////
//////////////	EVENTS
///////////////////////////////////////////////////////////////////////////////
// Vendor speech
[SPEECH VENDORS] 
ON=*BUY*		
IF (<DEF.AOS_TOOL_POPUS>!=1)
	IF (<DISTANCE><4)
		IF !(<TOPOBJ.TAG.OWNER>==<SRC.UID>)
			REF1 <SRC.CTAG.BUYING>
			IF (<REF1.TOPOBJ.UID>==<UID>)
				IF !(STRMATCH(<REF1.TAG0.PRICE>,notforsell))
					SRC.SDIALOG d_SELLCONFIRM
					RETURN 1
				ENDIF
			ENDIF
		ELSE
			TOPOBJ.SAY @,,2 503212 // You own this shop, just take what you want.
		ENDIF
	ENDIF
ENDIF

ON=*SELL*
IF (<DEF.VENDORBUYING>==1)
	IF (<DISTANCE><4)
			IF !(<TOPOBJ.TAG.OWNER>==<SRC.UID>)
				DIALOG d_SELLVENDORPLYAER
			ENDIF
	ENDIF
ENDIF


//Items events
[TYPEDEF T_ITENSOSELLING] 
ON=@CLIENTTOOLTIP
SRC.ADDCLILOC <QVAL (STRMATCH(<TAG.PRICE>,notforsell)) ?  1043307 : <QVAL (<DTAG0.PRICE>==0) ? 1043306 : 1043304,<DTAG.PRICE>>> // Price: Not for sale. // Price: FREE! // Price: ~1_COST~
IF !(<ISEMPTY <TAG.DESCRIPTION>>)
	SRC.ADDCLILOC 1043305,<TAG.DESCRIPTION> // <br>Seller's Description:<br>"~1_DESC~"
ENDIF

ON=@CLICK
IF (<DEF.AOS_TOOL_POPUS>!=1)
	MESSAGE @47,3,1 (<NAME>)
	MESSAGE @,,2 <QVAL (STRMATCH(<TAG.PRICE>,notforsell)) ?  1043307 : <QVAL (<DTAG0.PRICE>==0) ? 1043306 : 1043304,<DTAG.PRICE>>> // Price: Not for sale. // Price: FREE! // Price: ~1_COST~
	IF !(STRMATCH(<TAG0.PRICE>,notforsell))
		SRC.CTAG.BUYING <UID>
		SRC.SYSMESSAGE @,,2 503197 // To purchase items say "vendor buy".
	ENDIF
	IF !(<ISEMPTY <TAG.DESCRIPTION>>)
		MESSAGE @1100,3,1 <DEF.SYS_OBSERVATION> <TAG.DESCRIPTION>" 
	ENDIF	
	RETURN 1
ENDIF

ON=@EQUIPTEST
TAG.BAGBACK <TOPOBJ.UID>
TRIGGER @Dropon_Item
RETURN 1

ON=@CONTEXTMENUREQUEST
TRY <QVAL(<TOPOBJ.TAG.OWNER>==<SRC.UID>)? TOPOBJ.SAY @,,2 503212 : <QVAL (STRMATCH(<TAG.PRICE>,notforsell))? SRC.SYSMESSAGE @,,2 503202 : SRC.AddContextEntry 687,3006103,020,32767 >> // You own this shop, just take what you want. // This item is not for sale. // BUY

ON=@PICKUP_PACK
IF (<TOPOBJ.TAG.OWNER>!=<SRC.UID>)
	SRC.SYSMESSAGE @,,2 500169
	RETURN 1
ENDIF
TAG.BAGBACK <TOPOBJ.UID>

ON=@DROPON_ITEM
IF (<CONT>)
	IF (<TAG0.BAGBACK>)
		IF (<ISNUM <ARGO.TAG.PRICE>>)
			REF1 <TAG.BAGBACK>
			SRC.SYSMESSAGE @,3,1 <DEF.SYS_NOTDROPON>
			CONT <REF1.FINDLAYER.21>
		ENDIF
		IF (<ARGO.TOPOBJ.UID>!=<TAG.BAGBACK>)
			IF (<ARGO.TOPOBJ.TAG0.SALARY>)
				CONT <SRC.FINDLAYER.21>
				F_REMOVESELLINGGODS
				FIX
			ELSE
				F_REMOVESELLINGGODS
				FIX
			ENDIF
		ENDIF
	ENDIF
ENDIF

ON=@STACKON
SERV.LOG <ACT.NAME> <NAME>

ON=@DROPON_GROUND
F_REMOVESELLINGGODS

ON=@TIMER
RETURN 1

//Events npc
[EVENTS E_VENDOR]
ON=@CONTEXTMENUREQUEST
RETURN 1

ON=@ClientToolTip
SRC.ADDCLILOC 1062449,<TAG.NAMESHOP>

ON=@CLICK
MESSAGE @035,,1 <NAME>
IF (<DEF.AOS_TOOL_POPUS>!=1)
	MESSAGE @,,2 1062449,<TAG.NAMESHOP>
ENDIF
RETURN 1

ON=@DCLICK
FOOD 1000
FACE <SRC.UID>
IF !(<TAG0.CAN>)
	IF !(<TAG0.MADEBYGM>)
		REF1 <TAG.OWNER>
		IF (<DEF.AMOUNTVENDOR>!=0) && (<REF1.DTAG0.VENDORS>><DEF.AMOUNTVENDOR>)
			SENDITENSTOOWNER
			REMOVE
			RETURN 1 
		ELIF ((<DEF.HOUSEVENDOR>==1) && !(STRMATCH(NO,<DEF.AREAVENDOR>)) 
			IF !(0<UID.<SRC.REGION.UID>.MORE1>)&& !(STRMATCH(<SRC.REGION.NAME>,<DEF.AREAVENDOR>))
				SENDITENSTOOWNER
				REMOVE
				RETURN 1 
			ENDIF
		ELIF (<DEF.HOUSEVENDOR>==0) && !(STRMATCH(NO,<DEF.AREAVENDOR>)) 
			IF !(STRMATCH(<SRC.REGION.NAME>,<DEF.AREAVENDOR>))
				SENDITENSTOOWNER
				REMOVE
				RETURN 1
			ENDIF
		ELIF (<DEF.HOUSEVENDOR>==1) && (STRMATCH(NO,<DEF.AREAVENDOR>)) 
			IF !(0<UID.<REGION.UID>.MORE1>==<TAG.OWNER>) && !(<TAG0.MADEBYGM>)
				SENDITENSTOOWNER
				REMOVE
				RETURN 1 
			ENDIF
		ENDIF
	ENDIF

	IF (<SRC>==<TAG.OWNER>)  
		F_CHARGEPERDAY
		SDIALOG d_VENDOROSI 1
		RETURN 1
	ELSE
		TRY UID.<FINDLAYER(21).UID>.OPEN
		SRC.SYSMESSAGE @,,2 503208
		RETURN 1
	ENDIF
ENDIF
TAG.CAN=

ON=@RECEIVEITEM
IF ((!(<ISMYPET>)) || (<ARGO.BASEID> != i_gold))
RETURN 1
ENDIF
IF (<EVAL (<TAG0.GOLDHOLD>+<ARGO.AMOUNT>)> > 10000000)
	SRC.SYSMESSAGE @,,2 1062493  // Your vendor has sufficient funds for operation and cannot accept this gold.
	RETURN 1
ENDIF
SAY @,,2 503210 // I'll take that to fund my services.
TAG0.GOLDHOLD += <ARGO.AMOUNT>
ARGO.CONSUME <ARGO.AMOUNT>
RETURN 1

on=@HITTRY
RETURN 1

ON=@ATTACK
RETURN 1

ON=@USERWARMODE
flags &= ~statf_war
RETURN 1

on=@SPELLEFFECT
RETURN 1

ON=@CALLGUARDS
RETURN 1


///////////////////////////////////////////////////////////////////////////////
//////////////	FUNCTIONS
///////////////////////////////////////////////////////////////////////////////

[FUNCTION F_BODYVENDORCHANGE]
IF (<TAG0.WAIT>)
	SRC.SYSMESSAGE @,3,1 <DEF.SYS_NOCHANGESEX>
	DIALOG d_VENDOROSI 2
	RETURN 1
ENDIF
BODY <QVAL (<ARGS>==1)? C_MAN : C_WOMAN>
NAME=#NAMES_HUMANFEMALE
FINDLAYER.LAYER_BEARD.REMOVE
TAG.LASTBEARD
DIALOG d_VENDOROSI 2
TIMERF 3,TAG.WAIT
TAG.WAIT 1
FIX
WEARNPCVENDOR

[FUNCTION F_REMOVESELLINGGODS]
IF (STRMATCH(<TYPE>,T_CONTAINER))
	FORCONT <UID> 9999
		TAG.PRICE
		TAG.BAGBACK
		TAG.DESCRIPTION
		EVENTS -T_ITENSOSELLING
	ENDFOR
ENDIF
TAG.PRICE
TAG.BAGBACK
TAG.DESCRIPTION
EVENTS -T_ITENSOSELLING

[FUNCTION F_SETPRICE]
REF1 <CTAG.REF1>
IF (<ISEMPTY <ARGS>>)
		REF1.TAG.PRICE=notforsell
IF (STRMATCH(T_CONTAINER*,<REF1.TYPE>))
SYSMESSAGE @946,3,1 Set the container description. (ESC = No description)
PROMPTCONSOLE F_SETITEMDESC
ENDIF
ELSE
	IF !(<ISNUM <STRARG <ARGS>>>)
		REF1.TAG.PRICE 999
	ELIF (<EVAL (STRLEN(<STRARG <ARGS>>))> > 8)
		SYSMESSAGE @946,3,1 Price string too high!
	ELIF (<EVAL <STRARG <ARGS>>> > 10000000)
		SYSMESSAGE @946,3,1 That would exceed your vendors account limit (10 million gold).
		REF1.TAG.PRICE 10000000
	ELSE
		REF1.TAG.PRICE <STRARG <ARGS>>
	ENDIF
REF1.EVENTS +T_ITENSOSELLING
F_SETITEMDESC <STREAT <ARGS>>
ENDIF
REF1.FIX

[FUNCTION F_SETITEMDESC]
REF45=<CTAG.REF1>
	IF !(<ISEMPTY <ARGS>>)
		LOCAL.DESCRIPTION <ARGS>
		IF !(<EVAL STRLEN(<LOCAL.DESCRIPTION>)> > 70)
			REF45.TAG.DESCRIPTION <LOCAL.DESCRIPTION>
		ELSE
			SYSMESSAGE @,3,1 <DEF.SYS_DESCSOBIG>
		ENDIF
	ENDIF
REF45.FIX

[FUNCTION SENDITENSTOOWNER]
REF1 <TAG.OWNER>
REF1.NEWGOLD <TAG.GOLDHOLD>
REF1.TAG.VENDORS --
FORCONT <FINDLAYER.21> 100
	CONT <REF1.FINDLAYER.29>
	F_REMOVESELLINGGODS
ENDFOR

[FUNCTION F_CHARGEPERDAY]
LOCAL.HOWMUCH 0
FOR 1 10 
	IF (<TAG0.ITEMNAME<DLOCAL._FOR>>)
		LOCAL.HOWMUCH += 25
	ENDIF
ENDFOR
FORCONT <FINDLAYER.21>
	IF !(<ISEMPTY <TAG.PRICE>>) && (<ISNUM <TAG0.PRICE>>)
		LOCAL.HOWMUCH += <TAG0.PRICE>
	ENDIF
ENDFOR
IF (<LOCAL.HOWMUCH>)
	TAG.SALARY <EVAL (20+(<LOCAL.HOWMUCH>/250))>
ENDIF

[FUNCTION WEARNPCVENDOR]
FOR 0 24 
	IF (<FINDLAYER.<LOCAL._FOR>>)
		IF (<LOCAL._FOR>!=11) && (<LOCAL._FOR>!=15) && (<LOCAL._FOR>!=16) && (<LOCAL._FOR>!=21)
			FINDLAYER.<LOCAL._FOR>.REMOVE
		ENDIF
	ENDIF
ENDFOR
IF (<BODY>==C_MAN)
	NEWLOOT=random_male_hair
	NEW.COLOR colors_hair
	TAG.LASTHAIR <NEW.UID>
	NEWLOOT=random_facial_hair
	NEW.COLOR colors_hair
	TAG.LASTBEARD <NEW.UID>
	NEWLOOT=random_male_pants
	NEW.COLOR colors_all
	NEWLOOT=fixe_random_male_tops
	NEW.COLOR colors_all
ELSE
	NEWLOOT=random_female_hair
	COLOR colors_hair
	TAG.LASTHAIR <NEW.UID>
	NEWLOOT=random_female_tops
	NEW.COLOR colors_all
	NEWLOOT=fixe_random_female_pants
	NEW.COLOR colors_all
ENDIF
NEWLOOT=random_hats
NEW.COLOR colors_all
DORAND 2
	NEWLOOT=random_boots
	NEWLOOT=random_footwear
ENDDO
NEW.COLOR colors_all
IF <R3>
	NEWLOOT=I_CAPE 
	NEW.COLOR colors_alL
ENDIF
NEWLOOT={ 3520 1 3717 1 3720 1 3778 1 3933 1 3940 1 4020 1 3936 1 5113 1 3920 1 5126 1 5186 1 3939 1 5118 1 3834 1}

[FUNCTION F_GETGOLDBACK]
IF (<ISNUM <ARGS>>) 
	IF (<ARGS>>0) && (<ARGS> <= <UID.<CTAG.VENDORGOLD>.TAG.GOLDHOLD>)
		NEWGOLD <ARGS>
		TRY UID.<CTAG.VENDORGOLD>.TAG.GOLDHOLD <EVAL <UID.<CTAG.VENDORGOLD>.TAG.GOLDHOLD> - <ARGS>>
	ELSE
		TRY UID.<CTAG.VENDORGOLD>.SAY @,3,1 <DEF.SAY_VENDORNOHOLDMONEY_1> <UID.<CTAG.VENDORGOLD>.DTAG.GOLDHOLD> <DEF.SAY_VENDORNOHOLDMONEY_2>
	ENDIF
ENDIF

[FUNCTION F_HAIRVENDOR]
NEWITEM <ARGV[<EVAL <ARGV[0]>+1>]>
EQUIP <NEW.UID>

[FUNCTION F_RENAMESHOP]
LOCAL.ARGS <ARGS>
CALL F_CHECKERRENAME 1

[FUNCTION F_RENAMEVENDOR]
LOCAL.ARGS <ARGS>
CALL F_CHECKERRENAME 2

[FUNCTION F_CHECKERRENAME]
IF (<ISEMPTY <LOCAL.ARGS>>) || (<ISNUM <LOCAL.ARGS>>) || (<EVAL STRLEN(<LOCAL.ARGS>)> > 20) || (<EVAL STRLEN(<LOCAL.ARGS>)> < 4) || (STRMATCH(*<ASC [[]>*,<ASC <LOCAL.ARGS>>)) || (STRMATCH(*<ASC ]>*,<ASC <LOCAL.ARGS>>)) || (STRMATCH(*<ASC [(]>*,<ASC <LOCAL.ARGS>>)) || (STRMATCH(*<ASC ->*,<ASC <LOCAL.ARGS>>)) || (STRMATCH(*<ASC [}`>?´;:^%$*¨!<#._~|=+&/æ{]>*,<ASC <LOCAL.ARGS>>)) || (STRMATCH(*<ASC @>*,<ASC <LOCAL.ARGS>>))
	SYSMESSAGE @,,2 3000611  //Unacceptable Name
	RETURN 1 
ENDIF
TRY UID.<SRC.CTAG.VENDOR>.<QVAL (<ARGS>==1)? TAG.NAMESHOP : NAME> <LOCAL.ARGS>
TRY UID.<SRC.CTAG.VENDOR>.UPDATE
SYSMESSAGE <QVAL (<ARGS>==1)? @,3,1 <DEF.SYS_SHOPRENAME> : @,,2 1062496 > 

[FUNCTION F_GETITEMINFO]
REF1 <ARGV[0]>
IF (<ARGO.ISITEM>) && (<ARGO.TOPOBJ>==<UID>)
	CTAG.VENDORSETITEM <ARGV[0]>
	CTAG.SLOT <ARGV[1]>
	REF1 <ARGV[0]>
	TRY REF1.TAG.ITEMNAME<ARGV[1]> <ARGO.BASEID>
	SRC.SYSMESSAGE @,3,1 <DEF.SYS_PAYAMOUNT>
	SRC.PROMPTCONSOLE F_SETPRICEBUYING
ELSE
	SRC.SYSMESSAGE @,,2 1042001 // That must be in your pack for you to use it.
	REF1.SDIALOG d_VENDOROSI 3
ENDIF

[FUNCTION F_SETPRICEBUYING]
IF ((<ISEMPTY <STRARG <ARGS>>>) || !(<ISNUM <STRARG <ARGS>>>))
	TRY UID.<CTAG.VENDORSETITEM>.TAG.ITEMVALUE<DCTAG.SLOT> = 999
	SYSMESSAGE @,3,1 <DEF.SYS_BUYINGAMOUT>
	PROMPTCONSOLE F_SETAMOUNTLIMIT
	RETURN 1
ENDIF
IF  (<EVAL <STRARG <ARGS>>> < 100000) && (<EVAL <STRARG <ARGS>>> > 0)
	TRY UID.<CTAG.VENDORSETITEM>.TAG.ITEMVALUE<DCTAG.SLOT> <STRARG <ARGS>>
ELSE
	TRY UID.<CTAG.VENDORSETITEM>.TAG.ITEMVALUE<DCTAG.SLOT> = 999
ENDIF
	SYSMESSAGE @,3,1 <DEF.SYS_BUYINGAMOUT>
	PROMPTCONSOLE F_SETAMOUNTLIMIT


[FUNCTION F_SETAMOUNTLIMIT]
REF1 <CTAG.VENDORSETITEM>
IF (<ISEMPTY <STRARG <ARGS>>>) || !(<ISNUM <STRARG <ARGS>>>)
	TRY UID.<CTAG.VENDORSETITEM>.TAG.ITEMAMOUNT<DCTAG.SLOT> 999
	SYSMESSAGE @,,2 500927 //Adding item...
	REF1.SDIALOG d_VENDOROSI 3
	RETURN 1
ENDIF
IF (<EVAL <STRARG <ARGS>>> < 100000) &&  (<EVAL <STRARG <ARGS>>> > 0)
	TRY UID.<CTAG.VENDORSETITEM>.TAG.ITEMAMOUNT<DCTAG.SLOT> <STRARG <ARGS>>
	SYSMESSAGE @,,2 500927 //Adding item...
	REF1.SDIALOG d_VENDOROSI 3
ELSE
	TRY UID.<CTAG.VENDORSETITEM>.TAG.ITEMAMOUNT<DCTAG.SLOT> 999
	SYSMESSAGE @,,2 500927 //Adding item...
	REF1.SDIALOG d_VENDOROSI 3
ENDIF

//FUNCTIONS huepicker AND f_hue_picker BY EPILA tks mother fucker :D
// FIXED BY SACI
[FUNCTION HUEPICKER]
TRY UID.<ARGV[1]>.SENDPACKET 095 D<ARGV[0]> W0000 W0FAB
TRY UID.<ARGV[1]>.CTAG.HUEPICKER=<ARGV[0]>

[FUNCTION F_HUE_PICKER]
IF <UID.<LOCAL.CHAR>.CTAG.HUEPICKER>
	LOCAL.COR <LOCAL.7><LOCAL.8>
	LOCAL.ITEM <UID.<LOCAL.CHAR>.CTAG0.HUEPICKER>
	UID.<LOCAL.ITEM>.COLOR <LOCAL.COR>
	UID.<LOCAL.CHAR>.CTAG.HUEPICKER
ENDIF

///////////////////////////////////////////////////////////////////////////////
//////////////	NPC
///////////////////////////////////////////////////////////////////////////////

[CHARDEF C_VENDOR_PLAYER]
NAME=#NAMES_HUMANMALE
ID=C_MAN
DESIRES=i_gold
CAN=MT_USEHANDS|MT_EQUIP|MT_FIRE_IMMUNE|MT_NONMOVER
TSPEECH=VENDORS
ARMOR=100

on=@create
NEED=i_gold
TAG.GOLDHOLD=100
TAG.SALARY=50
SERV.NEWITEM I_BACKPACK
EQUIP <NEW.UID>
SERV.NEWITEM I_GETSALARY
EQUIP <NEW.UID>
COLOR=colors_skin
STR=1
INT=0
DEX=0
FAME=0
KARMA=0
FLAGS |= statf_invul
ALLSKILLS=0.0
EQUIPHALO
MODMAXWEIGHT=20100
EVENTS=+E_VENDOR
WEARNPCVENDOR


///////////////////////////////////////////////////////////////////////////////
//////////////	DIALOGS
///////////////////////////////////////////////////////////////////////////////

[DIALOG d_SELLCONFIRM]
100, 200 
PAGE 0
REF1 <CTAG.BUYING>
RESIZEPIC 100 10 5054 300 150 
GUMPPICTILED 110 20 280 130 2624
CHECKERTRANS 110 20 280 130
XMFHTMLGUMPCOLOR 125 20 250 24 1019070 0 0 32767 // You have agreed to purchase:
IF (<ISEMPTY <REF1.TAG.DESCRIPTION>>)
XMFHTMLGUMPCOLOR 125 45 250 24 1019072 0 0 32767 // an item without a description
ELSE
DTEXT 125 45 47 <STRSUB 0 33 <REF1.TAG.DESCRIPTION>>
ENDIF
XMFHTMLGUMPCOLOR 125 70 250 24 1019071 0 0 32767 // for the amount of:
DTEXT 125 95 47 <REF1.DTAG.PRICE>
BUTTON 250 130 4005 4007 1 0 0 
XMFHTMLGUMPCOLOR 282 130 100 24 1011012 0 0 32767 // CANCEL
BUTTON 120 130 4005 4007 1 0 1
XMFHTMLGUMPCOLOR 152 130 100 24 1011036 0 0 32767 // OKAY

[DIALOG d_SELLCONFIRM BUTTON]
ON=1
REF1 <CTAG.BUYING>
REF2 <REF1.TOPOBJ>
BOUNCE <FINDLAYER.layer_dragging>
IF !(<ISEMPTY <REF1.TAG.PRICE>>)
	IF (<DEF.GETMONEYFROM>==1)
		IF (<EVAL <RESCOUNT I_GOLD>+<FINDLAYER.29.RESCOUNT I_GOLD>> >= <REF1.DTAG.PRICE>)
			IF (<FINDLAYER.29.RESCOUNT I_GOLD> >= <REF1.DTAG.PRICE>)
				FINDLAYER.29.CONTCONSUME I_GOLD <REF1.DTAG.PRICE>
			ELSE	
				LOCAL.AMOUNT=<EVAL <REF1.DTAG.PRICE>-<FINDLAYER.29.RESCOUNT I_GOLD>>
				FINDLAYER.29.CONTCONSUME I_GOLD <REF1.DTAG.PRICE>
				FINDLAYER.21.CONTCONSUME I_GOLD <LOCAL.AMOUNT>
			ENDIF
			REF2.TAG0.GOLDHOLD += <REF1.DTAG.PRICE>
			SYSMESSAGE @,,2 503201 // You take the item.
			REF1.F_REMOVESELLINGGODS
			BOUNCE <REF1>
		ELSE
			SYSMESSAGE @,,2 503205 //You cannot afford this item.
		ENDIF
	ELSE
		IF (<RESTEST <REF1.DTAG.PRICE> I_GOLD>)
			FINDLAYER.21.CONTCONSUME I_GOLD <REF1.DTAG.PRICE>
			REF2.TAG0.GOLDHOLD += <REF1.DTAG.PRICE>
			SYSMESSAGE @,,2 503201 // You take the item.
			REF1.F_REMOVESELLINGGODS
			BOUNCE <REF1>
		ELSE
			SYSMESSAGE @,3,1 <DEF.SYS_NOTENOUGHMONEY>
		ENDIF
	ENDIF
ENDIF

ON=0
SYSMESSAGE @,,2 503207

[DIALOG d_VENDOROSI]
50,150
PAGE 1
RESIZEPIC 25 10 5054 530 180
GUMPPICTILED 35 20 510 160 2624
CHECKERTRANS 35 20 510 160
GUMPPIC 10 0 <EVAL 028DC>
GUMPPIC 537 175 <EVAL 028DC>
GUMPPIC 10 175 <EVAL 028DC>
GUMPPIC 537 0 <EVAL 028DC>
IF (<EVAL <TAG0.GOLDHOLD>/<TAG0.SALARY>>==0)
XMFHTMLGUMPCOLOR 40 35 260 20 1038320 0 0 32767  // Gold needed for 1 day of vendor salary:
DHTMLGUMP 300 35 290 220 0 0 <DEF.BFONT_LRED><EVAL <TAG0.SALARY>-<TAG0.GOLDHOLD>>
ELSE
XMFHTMLGUMPCOLOR 40 35 260 20 1038318 0 0 32767  // # of days Vendor salary is paid for: 
DHTMLGUMP 300 35 290 220 0 0 <DEF.BFONT_WHITE><EVAL <TAG0.GOLDHOLD>/<TAG0.SALARY>> 
ENDIF
XMFHTMLGUMPCOLOR 40 58 260 20 1038324 0 0 32767  // My charge per real world day is: 
DHTMLGUMP 300 58 290 220 0 0 <DEF.BFONT_WHITE><DTAG0.SALARY>  
XMFHTMLGUMPCOLOR 40 82 260 20 1038322 0 0 32767  // Gold held in my account: 
DHTMLGUMP 300 82 290 220 0 0 <DEF.BFONT_WHITE><DTAG0.GOLDHOLD>
XMFHTMLGUMPCOLOR 40 108 260 20 1062509 0 0 32767 // Shop Name:
DHTMLGUMP 140 106 290 220 0 0 <DEF.BFONT_SHOPNAME><TAG.NAMESHOP>
XMFHTMLGUMPCOLOR 408 21 120 20 1019068 0 0 32767  // See goods
XMFHTMLGUMPCOLOR 408 41 120 20 1019069 0 0 32767  // Customize
XMFHTMLGUMPCOLOR 408 61 120 20 1062434 0 0 32767  // Rename Shop
XMFHTMLGUMPCOLOR 408 81 120 20 3006217 0 0 32767  // Rename Vendor
XMFHTMLGUMPCOLOR 408 101 120 20 3006123 0 0 32767  // Open Paperdoll
FOR 1 8
BUTTON 390 <EVAL (20*<DLOCAL._FOR>) +4> 015E1 015E5 <QVAL (<DLOCAL._FOR>==2)? 0 2 : 1 0 <dLOCAL._FOR>>
ENDFOR
DHTMLGUMP 408 141 290 220 0 0 <DEF.BFONT_WHITE><DEF.DLG_DISMISSVENDOR>
DHTMLGUMP 408 121 290 220 0 0 <DEF.BFONT_WHITE><DEF.DLG_COLLECTGOLD>
XMFHTMLGUMPCOLOR 408 161 120 20 1011012 0 0 32767 // CANCEL
IF (<DEF0.VENDORBUYING>==1)
DHTMLGUMP 58 135 290 220 0 0 <DEF.BFONT_WHITE><DEF.DLG_LISTSTUFF>
BUTTON 40 137 015E1 015E5 0 3
ENDIF 

PAGE 2
50, 50
RESIZEPIC 0 0 013BE 370 370  
GUMPPICTILED 10 10 350 20 2624
GUMPPICTILED 10 40 350 20 2624
GUMPPICTILED 10 70 350 260 2624  
GUMPPICTILED 10 340 350 20 2624 
CHECKERTRANS 10 10 350 350 
XMFHTMLGUMPCOLOR 10 12 350 18 1011356 0 0 32767 // <center>VENDOR CUSTOMIZATION MENU</center>
XMFHTMLGUMPCOLOR 10 42 150 18 1062459 0 0 16927 // <CENTER>HAIR</CENTER
XMFHTMLGUMPCOLOR 160 42 210 18 1062460 0 0 16927 // <CENTER>BEARD</CENTER>
ADDBUTTONSVENDOR <DEF.MALESTYLE>
BUTTON 10 250 0FA5 0FA7 1 0 98
DHTMLGUMP 45 252 290 220 0 0 <DEF.BFONT_WHITE>Color
BUTTON 160 230 0FA5 0FA7 1 0 97
DHTMLGUMP 195 232 290 220 0 0 <DEF.BFONT_WHITE>Color
BUTTON 160 210 0FB1 0FB3 1 0 99
DHTMLGUMP 195 212 290 220 0 0 <DEF.BFONT_WHITE>Remove
XMFHTMLGUMPCOLOR 195 287 160 18 1015327 0 0 <QVAL (<BODY>==C_WOMAN)? 32767 : 16927 > // Male
XMFHTMLGUMPCOLOR 195 307 160 18 1015328 0 0 <QVAL (<BODY>==C_MAN)? 32767 : 16927>  // Female
BUTTON 160 <QVAL (<BODY>==C_WOMAN)? 285 0FA5 0FA7 1 0 50 : 305 0FA5 0FA7 1 0 51 >
BUTTON 10 340 0FA5 0FA7 1 0 60
XMFHTMLGUMPCOLOR 45 342 305 18 1060675 0 0 32767  // CLOSE

PAGE 3 
0,0
RESIZEPIC 0 0 013BE 370 360 
GUMPPICTILED 10 70 350 248 2624
GUMPPICTILED 10 10 350 20 2624
GUMPPICTILED 10 40 350 20 2624
GUMPPICTILED 10 330 350 20 2624
CHECKERTRANS 10 10 350 340 
DHTMLGUMP 30 12 290 220 0 0 <DEF.BFONT_WHITE><DEF.CENTER><DEF.DLG_LISTBUYING>
BUTTON 10 330 0FA5 0FA7 1 0 10
DHTMLGUMP 45 332 305 18 0 0 <DEF.BFONT_WHITE><DEF.DLG_ADDITEMTOLIST>
BUTTON 280 330 0FA5 0FA7 0 1
DHTMLGUMP 315 332 305 18 0 0 <DEF.BFONT_WHITE><DEF.DLG_CLOSE>
DHTMLGUMP 20 42 290 220 0 0 <DEF.BFONT_MBLUE><DEF.DLG_ITEMNAME>
DHTMLGUMP 220 42 290 220 0 0 <DEF.BFONT_MBLUE><DEF.DLG_PRICE> 
DHTMLGUMP 300 42 290 220 0 0 <DEF.BFONT_MBLUE><DEF.DLG_AMOUNT>
FOR 1 10 
IF (<TAG0.ITEMNAME<DLOCAL._FOR>>)
BUTTON 10 <EVAL 45+(25*<DLOCAL._FOR>)> 0FB4 0FB6 1 0 <EVAL <LOCAL._FOR>+300> 
DHTMLGUMP 35 <EVAL 45+(25*<DLOCAL._FOR>)> 290 220 0 0 <DEF.BFONT_WHITE> <SERV.ITEMDEF.<TAG.ITEMNAME<DLOCAL._FOR>>.NAME>
DHTMLGUMP 220 <EVAL 45+(25*<DLOCAL._FOR>)> 290 220 0 0 <DEF.BFONT_WHITE> <DTAG.ITEMVALUE<DLOCAL._FOR>>
DHTMLGUMP 300 <EVAL 45+(25*<DLOCAL._FOR>)> 290 220 0 0 <DEF.BFONT_WHITE> <DTAG.ITEMAMOUNT<DLOCAL._FOR>>
ENDIF
ENDFOR

[FUNCTION ADDBUTTONSVENDOR]
FOR 0 <EVAL <ARGV>-8>
DHTMLGUMP 45 <EVAL 72+(20*<DLOCAL._FOR>)> 290 220 0 0 <DEF.BFONT_WHITE><STRTOUPPER <STRSUB 0 1 <SERV.ITEMDEF.<ARGV[<DLOCAL._FOR>]>.NAME>>><STRSUB 1 <QVAL (STRMATCH(*hair*,<SERV.ITEMDEF.<ARGV[<DLOCAL._FOR>]>.NAME>))?<EVAL <STRPOS 4 h <SERV.ITEMDEF.<ARGV[<DLOCAL._FOR>]>.NAME>>-1> : 0> <SERV.ITEMDEF.<ARGV[<DLOCAL._FOR>]>.NAME>>
BUTTON 10 <EVAL 70+(20*<DLOCAL._FOR>)> 0FA5 0FA7 1 0 <EVAL 100+<DLOCAL._FOR>> 
IF <DLOCAL._FOR><7
DHTMLGUMP 195 <EVAL 72+(20*<DLOCAL._FOR>)> 290 220 0 0 <DEF.BFONT_WHITE><STRTOUPPER <STRSUB 0 1 <SERV.ITEMDEF.<ARGV[<EVAL <DLOCAL._FOR>+9>]>.NAME>>><STRSUB 1 <QVAL (STRMATCH(*beard*,<SERV.ITEMDEF.<ARGV[<EVAL <DLOCAL._FOR>+9>]>.NAME>))?<EVAL <STRPOS 4 b <SERV.ITEMDEF.<ARGV[<EVAL <DLOCAL._FOR>+9>]>.NAME>>-1> : 0> <SERV.ITEMDEF.<ARGV[<EVAL <DLOCAL._FOR>+9>]>.NAME>>
BUTTON 160 <EVAL 70+(20*<DLOCAL._FOR>)> 0FA5 0FA7 1 0 <EVAL 200+<DLOCAL._FOR>> 
ENDIF
ENDFOR

[DIALOG d_VENDOROSI BUTTON]
ON=1
TRY UID.<FINDLAYER(21).UID>.OPEN
SRC.SYSMESSAGE @,,2 1010642

ON=3
SRC.SYSMESSAGE @,,2 1062433
SRC.CTAG.VENDOR <UID>
SRC.PROMPTCONSOLE F_RENAMESHOP

ON=4
SRC.SYSMESSAGE @,,2 1062494
SRC.CTAG.VENDOR <UID>
SRC.PROMPTCONSOLE F_RENAMEVENDOR

ON=5
TAG.CAN 1
SRC.DCLICK <UID>
DIALOG d_VENDOROSI 1

ON=6
IF (<DTAG.GOLDHOLD>>0)
	SAY @,3,1 <DEF.SAY_HOWMUCHGOLD_1> <DTAG.GOLDHOLD> <DEF.SAY_HOWMUCHGOLD_2>
	SRC.SYSMESSAGE @,3,1 <DEF.SYS_AMOUNTGOLD>
	SRC.PROMPTCONSOLE F_GETGOLDBACK
	SRC.CTAG.VENDORGOLD <UID>
ELSE
	SRC.SYSMESSAGE @,,2 503215
ENDIF

ON=7
IF (<FINDLAYER.21.COUNT>>0)
	SAY @,,2 1038325
ELSE
	SRC.NEWGOLD <TAG.GOLDHOLD>
	SRC.TAG.VENDORS --
	REMOVE
ENDIF

ON=200 210 
IF (<BODY>==C_MAN)
	FINDLAYER.LAYER_BEARD.REMOVE
	F_HAIRVENDOR <EVAL <ARGN>-191>,<DEF.MALESTYLE>
	TAG.LASTBEARD <NEW.UID>
ENDIF
DIALOG d_VENDOROSI 2

ON=100 110
FINDLAYER.LAYER_HAIR.REMOVE
F_HAIRVENDOR <EVAL <ARGN>-100>,<DEF.MALESTYLE>
TAG.LASTHAIR <NEW.UID>
DIALOG d_VENDOROSI 2

ON=97
IF (<TAG0.LASTBEARD>)
	HUEPICKER <TAG.LASTBEARD>,<SRC.UID>
ELSE
	DIALOG d_VENDOROSI 2
ENDIF

ON=98
IF !(<FINDLAYER.LAYER_HAIR.BASEID>==I_HAIR_KRISNA) && (<FINDLAYER.LAYER_HAIR.UID>)
	HUEPICKER <TAG.LASTHAIR>,<SRC.UID>
ELSE
	DIALOG d_VENDOROSI 2
ENDIF

ON=99
FINDLAYER.LAYER_BEARD.REMOVE
TAG.LASTBEARD
DIALOG d_VENDOROSI 2

ON=50
F_BODYVENDORCHANGE 1

ON=51
F_BODYVENDORCHANGE 2

ON=60
DIALOG d_VENDOROSI 1

ON=10
FOR 1 10 
	IF !(<TAG0.ITEMNAME<DLOCAL._FOR>>)
		SRC.SYSMESSAGE @,3,1 <DEF.SYS_ITEMREFERENCE>
		TARGETF F_GETITEMINFO <UID>,<DLOCAL._FOR>
		RETURN 1
	ENDIF
ENDFOR 
SRC.SYSMESSAGE @,3,1 <DEF.SYS_ALLSLOTS>
DIALOG d_VENDOROSI 3

ON=300 310
TRY TAG.ITEMNAME<EVAL <ARGN>-300>=
TRY TAG.ITEMVALUE<EVAL <ARGN>-300>=
TRY TAG.ITEMAMOUNT<EVAL <ARGN>-300>=
SRC.SYSMESSAGE @,3,1 <DEF.SYS_SLOTEMPTY> <EVAL <ARGN>-300> 
DIALOG d_VENDOROSI 3

[DIALOG d_SELLVENDORPLYAER]
100,100
RESIZEPIC 0 0 013BE 370 360  
GUMPPICTILED 10 70 350 248 2624
GUMPPICTILED 10 10 350 20 2624
GUMPPICTILED 10 40 350 20 2624
GUMPPICTILED 10 330 350 20 2624
CHECKERTRANS 10 10 350 340 
DHTMLGUMP 30 12 290 220 0 0 <DEF.BFONT_WHITE><DEF.CENTER><DEF.DLG_LISTBUYING>
BUTTON 280 330 0FA5 0FA7 1 0 0
DHTMLGUMP 315 332 305 18 0 0 <DEF.BFONT_WHITE><DEF.DLG_CLOSE>
DHTMLGUMP 20 42 290 220 0 0 <DEF.BFONT_MBLUE><DEF.DLG_ITEMNAME>
DHTMLGUMP 220 42 290 220 0 0 <DEF.BFONT_MBLUE><DEF.DLG_PRICE> 
DHTMLGUMP 300 42 290 220 0 0 <DEF.BFONT_MBLUE><DEF.DLG_AMOUNT>
FOR 1 10 
IF (<TAG0.ITEMNAME<DLOCAL._FOR>>)
IF (<SRC.RESTEST 1 <TAG.ITEMNAME<DLOCAL._FOR>>>)
BUTTON 10 <EVAL 45+(25*<DLOCAL._FOR>)> 0FA5 0FA7 1 0 <DLOCAL._FOR>
ENDIF
DHTMLGUMP 35 <EVAL 45+(25*<DLOCAL._FOR>)> 290 220 0 0 <QVAL <SRC.RESTEST 1 <TAG.ITEMNAME<DLOCAL._FOR>>>?<DEF.BFONT_WHITE>:<DEF.BFONT_GRAY>> <SERV.ITEMDEF.<TAG.ITEMNAME<DLOCAL._FOR>>.NAME>
DHTMLGUMP 220 <EVAL 45+(25*<DLOCAL._FOR>)> 290 220 0 0 <QVAL <SRC.RESTEST 1 <TAG.ITEMNAME<DLOCAL._FOR>>>?<DEF.BFONT_WHITE>:<DEF.BFONT_GRAY>> <DTAG.ITEMVALUE<DLOCAL._FOR>>
DHTMLGUMP 300 <EVAL 45+(25*<DLOCAL._FOR>)> 290 220 0 0 <QVAL <SRC.RESTEST 1 <TAG.ITEMNAME<DLOCAL._FOR>>>?<DEF.BFONT_WHITE>:<DEF.BFONT_GRAY>> <DTAG.ITEMAMOUNT<DLOCAL._FOR>>
ENDIF
ENDFOR

[DIALOG d_SELLVENDORPLYAER BUTTON]
ON=1 10
IF (<WEIGHT> > 20110)
		SAY @,,2 503211 // I CAN'T CARRY ANYMORE
		RETURN 1
ENDIF
IF !(<ISEMPTY <TAG.ITEMNAME<ARGN>>>)
	TRY SRC.CTAG.ITEMVALUE <TAG0.ITEMVALUE<ARGN>>
	TRY SRC.CTAG.ITEMNAME <TAG0.ITEMNAME<ARGN>>
	TRY SRC.CTAG.ITEMAMOUNT <TAG0.ITEMAMOUNT<ARGN>>
	TRY SRC.CTAG.SLOTUSED <ARGN>
	DIALOG d_SELLVENDORCONFIRM
ENDIF

[DIALOG d_SELLVENDORCONFIRM]
100, 200 
PAGE 0
RESIZEPIC 100 10 5054 300 160
GUMPPICTILED 110 20 280 80 2624
GUMPPICTILED 110 110 280 20 2624
GUMPPICTILED 110 140 280 20 2624
CHECKERTRANS 110 20 280 140
REF1=<SRC.FINDID.<SRC.CTAG.ITEMNAME>.UID>
LOCAL.TRUEWEIGHT=<Eval <REF1.WEIGHT>/<REF1.AMOUNT>>
DHTMLGUMP 110 20 280 80 0 1 <DEF.BFONT_WHITE><DEF.DLG_VENDORTEXT_1> <SRC.NAME><DEF.DLG_VENDORTEXT_2> <name>! <DEF.BR><DEF.DLG_VENDORTEXT_3> <DEF.BFONT_LGREEN><SERV.ITEMDEF.<SRC.CTAG.ITEMNAME>.NAME><DEF.BFONT_WHITE> <DEF.DLG_VENDORTEXT_4>!<DEF.BR><DEF.DLG_VENDORTEXT_5> <DEF.BFONT_LGREEN><SERV.ITEMDEF.<SRC.CTAG.ITEMNAME>.NAME><DEF.BFONT_WHITE>? <DEF.BR><DEF.DLG_VENDORTEXT_6> <DEF.BFONT_LGREEN><SRC.DCTAG.ITEMVALUE><DEF.BFONT_WHITE> <DEF.DLG_VENDORTEXT_7>. <DEF.DLG_VENDORTEXT_8> <DEF.BFONT_LGREEN><SRC.DCTAG.ITEMAMOUNT> <SERV.ITEMDEF.<SRC.CTAG.ITEMNAME>.NAME><DEF.BFONT_WHITE><DEF.DLG_VENDORTEXT_9> <DEF.BFONT_LGREEN> <QVAL (<EVAL <SRC.CTAG0.ITEMAMOUNT>*<SRC.CTAG0.ITEMVALUE>> < <EVAL <TAG0.GOLDHOLD>-<TAG.SALARY>>)?<DEF.DLG_VENDORTEXT_10> <SERV.ITEMDEF.<SRC.CTAG.ITEMNAME>.NAME> <DEF.DLG_VENDORTEXT_11><DEF.BFONT_WHITE>. : <EVAL ((<TAG0.GOLDHOLD>-<TAG.SALARY>)/<SRC.CTAG.ITEMVALUE>)> <SERV.ITEMDEF.<SRC.CTAG.ITEMNAME>.NAME><DEF.BFONT_WHITE> <DEF.DLG_VENDORTEXT_12>.><DEF.BFONT_WHITE><DEF.DLG_VENDORTEXT_13> <DEF.BFONT_LGREEN><EVAL (((<MAXWEIGHT>-<WEIGHT>)/<LOCAL.TRUEWEIGHT>)/10)> <SERV.ITEMDEF.<SRC.CTAG.ITEMNAME>.NAME><DEF.BFONT_WHITE>.
BUTTON 250 140 4005 4007 1 0 1 
XMFHTMLGUMPCOLOR 282 140 100 24 1011012 0 0 32767 // CANCEL
BUTTON 120 140 4005 4007 1 0 2
XMFHTMLGUMPCOLOR 152 140 100 24 1011036 0 0 32767 // OKAY
DHTMLGUMP 110 110 280 80 0 0 <DEF.BFONT_MBLUE>SELLING AMOUNT: 
IF (<SRC.RESCOUNT <SRC.CTAG.ITEMNAME>> > <SRC.DCTAG.ITEMAMOUNT>) //QVAL WITH PROBLEM, NEXT VERSION OF SPHERE I DO THIS CHECK BETTER
DTEXTENTRY 225 109 300 99 47 1 <QVAL (<EVAL <SRC.CTAG.ITEMAMOUNT>*<SRC.CTAG.ITEMVALUE>> < <EVAL <TAG0.GOLDHOLD>-<TAG.SALARY>>)? <SRC.DCTAG.ITEMAMOUNT> : <EVAL (<TAG0.GOLDHOLD>-<TAG.SALARY>)/<SRC.CTAG.ITEMVALUE>)>>
ELSE
DTEXTENTRY 225 109 300 99 47 1 <SRC.RESCOUNT <SRC.CTAG.ITEMNAME>> 
ENDIF

[DIALOG d_SELLVENDORCONFIRM BUTTON]
ON=1
DIALOG d_SELLVENDORPLYAER

ON=2
IF (<DISTANCE>>3)
	SRC.SYSMESSAGE @,,2 500251 // To far away
	RETURN 1
ENDIF
IF (<ISEMPTY <TAG.ITEMNAME<SRC.DCTAG.SLOTUSED>>>) || !(STRMATCH(<TAG.ITEMNAME<SRC.DCTAG.SLOTUSED>>,<SRC.CTAG.ITEMNAME>))
	SRC.SYSMESSAGE @,3,1 <DEF.SYS_DATACHANGED>
	RETURN 1
ENDIF
IF (<ISEMPTY <ARGTXT[1]>>) || !(<ISNUM <ARGTXT[1]>>)
	SRC.SYSMESSAGE @,3,1 <DEF.SYS_MESSAGE>
	RETURN 1 
ENDIF
IF (<ARGTXT[1]> > <SRC.DCTAG.ITEMAMOUNT>)
	SRC.SYSMESSAGE @,3,1 <NAME> <DEF.SYS_MUCHITEM>
	RETURN 1
ENDIF
IF !(<SRC.RESTEST <ARGTXT[1]> <SRC.CTAG.ITEMNAME>>)
	SRC.SYSMESSAGE @,3,1 <DEF.SYS_NOITEMENOGOUH>
	RETURN 1
ENDIF
F_CHARGEPERDAY
IF (<EVAL (<ARGTXT[1]>*<SRC.CTAG.ITEMVALUE>)+<TAG.SALARY>> > <TAG0.GOLDHOLD>)
	SAY @,3,1 <DEF.SAY_WITHOUMONEY_1> <SERV.ITEMDEF.<SRC.CTAG.ITEMNAME>.NAME>. <DEF.SAY_WITHOUMONEY_2>
	RETURN 1
ENDIF
IF (<EVAL (<SERV.ITEMDEF.<SRC.CTAG.ITEMNAME>.WEIGHT>*<ARGTXT[1]>)+<WEIGHT>> > 4110)
	SAY @,3,1 <DEF.SAY_TOHEAVY> <EVAL (4110-<WEIGHT>)/<SERV.ITEMDEF.<SRC.CTAG.ITEMNAME>.WEIGHT>> <SERV.ITEMDEF.<SRC.CTAG.ITEMNAME>.NAME>.
	RETURN 1
ENDIF
TAG.GOLDHOLD -= <EVAL <SRC.CTAG.ITEMVALUE>*<ARGTXT[1]>>
SRC.NEWGOLD <EVAL <SRC.CTAG.ITEMVALUE>*<ARGTXT[1]>>
NEW <SRC.FINDLAYER.21.UID>
TRY TAG.ITEMAMOUNT<SRC.DCTAG.SLOTUSED> = <EVAL <TAG.ITEMAMOUNT<SRC.DCTAG.SLOTUSED>>-<ARGTXT[1]>>
IF (<TAG.ITEMAMOUNT<SRC.DCTAG.SLOTUSED>>==0)
	TRY TAG.ITEMNAME<SRC.DCTAG.SLOTUSED>=
ENDIF
IF (<SERV.ITEMDEF.<SRC.CTAG.ITEMNAME>.CAN>&CAN_I_PILE)
	SRC.FINDLAYER.21.CONTCONSUME <ARGTXT[1]> <SRC.CTAG.ITEMNAME>
	SERV.NEWITEM I_KRYSS,1,<FINDLAYER.21.UID>
	NEW.ID <SRC.CTAG.ITEMNAME>
	NEW.AMOUNT <ARGTXT[1]>
	NEW.EVENTS +T_ITENSOSELLING
	NEW.TAG.PRICE=notforsell
	NEW.TAG.DESCRIPTION=<DEF.SET_BOUGHTVENDOR>
	NEW.FIX
ELSE
	LOCAL.ITEM <SRC.CTAG.ITEMNAME>
	LOCAL.PLACE <FINDLAYER.21.UID>
	LOCAL.TANTO 0
	FORCONT <SRC.FINDLAYER.21>
		IF !(<ARGTXT[1]>==<LOCAL.TANTO>)
			IF (<BASEID>=<LOCAL.ITEM>)
				CONT <LOCAL.PLACE>
				EVENTS +T_ITENSOSELLING
				TAG.PRICE=notforsell
				TAG.DESCRIPTION=<DEF.SET_BOUGHTVENDOR>
				LOCAL.TANTO ++
			ENDIF
		ENDIF
	ENDFOR
ENDIF

[EOF]