;'Dance Master Event' looping script

If #PARAM1 = 0
	If #PARAM2 = 0
		Timer(272,3000,0,0,#PARAM3)
	EndIf
	GoTo END
EndIf

If #PARAM2 = 1
	DanceMaster=#PARAM3
	DirText=""

	Direction = GetUserDirection(DanceMaster)
	If Direction = #DIR_UP 
		DirText="up"
	ElseIf Direction = #DIR_DOWN
		DirText="down"
	ElseIf Direction = #DIR_LEFT
		DirText="left"
	ElseIf Direction = #DIR_RIGHT
		DirText="right"
	EndIf
	
	SetUserFlag(0,11,Direction)
	
	SendMessageToMap(655,GetUserName(DanceMaster)+" is facing "+DirText+".",#MSG_TELL)
	Timer(273,5000,#PARAM1-1,#PARAM2,#PARAM3)
Else
	Y=3
	While Y < 10
		X=3
		While X < 18
			UserID=GetUserAtXY(655,X,Y)
			If UserID > 0
				If UserID <> #PARAM3
					If GetUserDirection(UserID) <> GetUserFlag(0,11)
						SendMessageToUser(UserID,"You have lost the event.",#MSG_EMOTE)
						WarpUser(UserID,509,10,11)
						SendMessageToMap(655,GetUserName(UserID)+" failed to keep the rythm.",#MSG_SERVER)
					EndIf
				EndIf
			EndIf
			X=X+1
		Wend
		Y=Y+1
	Wend

	PlayerCount=0

	Y=3
	While Y < 10
		X=3
		While X < 18
			UserID=GetUserAtXY(655,X,Y)
			If UserID > 0
				PlayerCount=PlayerCount+1
			EndIf
			X=X+1
		Wend
		Y=Y+1
	Wend

	If PlayerCount > 1	
		Timer(273,5000,#PARAM1-1,#PARAM2,#PARAM3)
	Else
		Timer(272,3000,0,0,#PARAM3)
		SetUserFlag(0,10,0)
		SetUserFlag(0,11,0)
		SetUserFlag(0,45,0)
		GoTo END
	EndIf
EndIf

Label END

Continue = 1
