;Arena of the Kings

;GoTo END

If #PARAM1 = 0
	SendMessageToAll("The Arena of the Kings sends a call out to warriors and heroes! If you wish to try your might, type 'King' and wait until you are warped.",#MSG_SERVER)
		
		Timer(279,15000,-1,0,0)
		Timer(279,15000,-1,1,0)
		Timer(279,15000,-1,2,0)
		Timer(279,15000,-1,3,0)
		Timer(279,25000,-1,0,0)
		Timer(279,25000,-1,1,0)
		Timer(279,25000,-1,2,0)
		Timer(279,25000,-1,3,0)
		Timer(279,30000,-2,0,0)
		
		i=0
		While i < 16
			DamageMonster(998,i,9999)
			i=i+1
		Wend
	GoTo END
EndIf
If #PARAM1 = -1
	i=#PARAM2*1000
	LoopLimit= 1000 + #PARAM2 * 1000
	While i < LoopLimit
		i=i+1
		If IsOnline(i) = 1
			MSG=GetUserMessage(i)
			MSG=Lower(MSG)
			If MSG="king"
				WarpUser(i,998,10,10)
			EndIf
		EndIf
	Wend
	GoTo END
EndIf

Y=6
While Y < 19
	X=2
	While X < 19
		If GetMonsterAtXY(998,X,Y) <> -1
			Timer(279,10000,#PARAM1,#PARAM2,0)
			GoTo END
		EndIf
		X=X+1
	Wend
	Y=Y+1
Wend

Y=6
While Y < 19
	X=2
	While X < 19
		If GetUserAtXY(998,X,Y) > 0
			GoTo Continue
		EndIf
		X=X+1
	Wend
	Y=Y+1
Wend

SendMessageToAll("The Arena of the Kings is filled with naught but corpses. All players have failed.",#MSG_SERVER)
SetUserFlag(0,10,0)
GoTo END
Label Continue

If #PARAM2 < 10
	Timer(279,10000,#PARAM1,#PARAM2+1,0)
	Waves = 10 - #PARAM2
	SendMessageToMap(998,Waves+" waves remaining...",#MSG_SERVER)
Else
	SendMessageToAll("The Arena of the Kings has ended.",#MSG_SERVER)
	SetUserFlag(0,10,0)
	
	Players=""
	
	Y=6
	While Y < 19
		X=2
		While X < 19
			UserID = GetUserAtXY(998,X,Y)
			If UserID > 0
				SendMessageToUser(UserID,"You have been challenged in the Arena, and came out victorious!",#MSG_SERVER)
				
				Item = Random(0,15)
				If Item = 0
					GiveItem(UserID,228)
				ElseIf Item = 1
					GiveItem(UserID,237)
				ElseIf Item = 2
					GiveItem(UserID,197)
				ElseIf Item = 3
					GiveItem(UserID,196)
				ElseIf Item = 4
					GiveItem(UserID,217)
				ElseIf Item = 5
					GiveItem(UserID,219)
				ElseIf Item = 6
					GiveItem(UserID,220)
				ElseIf Item = 7
					GiveItem(UserID,221)
				ElseIf Item = 8
					GiveItem(UserID,222)
				ElseIf Item = 9
					GiveItem(UserID,223)
				ElseIf Item = 10
					GiveItem(UserID,137)
				ElseIf Item = 11
					GiveItem(UserID,129)
				ElseIf Item = 12
					GiveItem(UserID,174)
				ElseIf Item = 13
					GiveItem(UserID,202)
				ElseIf Item = 14
					GiveItem(UserID,118)
				Else
					GiveItem(UserID,238)
				EndIf
				
				
				If IsInvFull(UserID) = 1
					SendMessageToUser(UserID,"Your inventory is full.",#MSG_CRITICAL)
				Else
					SendMessageToUser(UserID,"Your reward has been placed in your inventory.",#MSG_TELL)
				EndIf
				
				;Regulus Scroll
				GiveItem(UserID,207)
				
				WarpUser(UserID,9,10,10)
				Players=Players+GetUserName(UserID)+", "
			EndIf
			X=X+1
		Wend
		Y=Y+1
	Wend
	
	SendMessageToAll(Players+"emerged victorious.",#MSG_SERVER)
	
	GoTo END
EndIf

SpawnMonster(998,200+#PARAM2,13,7)
SpawnMonster(998,200+#PARAM2,7,7)
SpawnMonster(998,200+#PARAM2,10,7)
SpawnMonster(998,200+#PARAM2,13,10)
SpawnMonster(998,200+#PARAM2,13,13)
SpawnMonster(998,200+#PARAM2,10,13)
SpawnMonster(998,200+#PARAM2,10,7)
SpawnMonster(998,200+#PARAM2,10,10)

Label END

Continue = 1