;'Dance Master Event' starting script

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

SetUserFlag(0,45,PlayerCount)

If PlayerCount < 3
	SendMessageToAll("Not enough players to compete, event canceled.",#MSG_SERVER)
	
	Y=3
	While Y < 10
		X=3
		While X < 18
			UserID=GetUserAtXY(655,X,Y)
			If UserID > 0
				WarpUser(UserID,509,10,11)
			EndIf
			X=X+1
		Wend
		Y=Y+1
	Wend
	SetUserFlag(0,10,0)
	SetUserFlag(0,11,0)
	SetUserFlag(0,45,0)
	GoTo END
EndIf

DanceMaster=Random(0,PlayerCount-1)

PlayerCount=0
Y=3
While Y < 10
	X=3
	While X < 18
		UserID=GetUserAtXY(655,X,Y)
		If UserID > 0
			If PlayerCount = DanceMaster
				SendMessageToMap(655,GetUserName(UserID)+" has been chosen to be Dance Master.",#MSG_SERVER)
				SendMessageToMap(655,"Follow the movements of Dance master "+GetUserName(UserID)+".",#MSG_SERVER) 
				WarpUser(UserID,655,10,4)
				DanceMaster=UserID
				X=18
				Y=10
			EndIf
			PlayerCount=PlayerCount+1
		EndIf
		X=X+1
	Wend
	Y=Y+1
Wend

Timer(273,9000,10,1,DanceMaster)
Timer(273,10000,10,0,DanceMaster)

Label END

Continue = 1