;'Sprite Change Item' equip script

ITEM=GetUserInvItem(#USERID,GetUserEquippedAccessory(#USERID))

Sprite=GetItemFlag4(ITEM)
BreakChance=GetItemFlag3(ITEM)
TimedReset=GetItemFlag2(ITEM)

If GetUserFlag(#USERID,1) <> 0
	SendMessageToUser(#USERID,"The "+GetItemName(ITEM)+" failed to function.",#MSG_SERVER)
	GoTo END
EndIf

If BreakChance > 1
	If Random(0,BreakChance) = 0
		SendMessageToUser(#USERID,"Your "+GetItemName(ITEM)+" has broken!",#MSG_CRITICAL)
		TakeItem(#USERID,ITEM)
		Items=0
		While HasItem(#USERID, ITEM) = 1
			Items=Items+1
			TakeItem(#USERID, ITEM)
		Wend
		While Items > 0
			Items=Items-1
			GiveItem(#USERID, ITEM)
		Wend
		GoTo END
	EndIf
ElseIf BreakChance = 1
	TakeItem(#USERID, ITEM)
EndIf

SetUserFlag(#USERID,1,GetUserSprite(#USERID))

SendMessageToUser(#USERID,"You are wrapped in illusions.",#MSG_SERVER)

SetUserSprite(#USERID,Sprite)
SetUserDisplayName(#USERID," ")

WarpUser(#USERID,#MAPID,#XPOS,#YPOS)

If TimedReset > 0
	Timer(269,TimedReset,#USERID,0,0)
EndIf

Label END

Continue = 1