;Event Controller - Open Event

If GetUserAccess(#USERID) < 5
	Goto END
EndIf

MSG=Lower(GetUserMessage(#USERID))

If MSG="reset"
	SetUserFlag(0,10,0)
	SetUserFlag(0,11,0)
	SendMessageToUser(#USERID,"Resetted!", #MSG_CRITICAL)
	GoTo END
EndIf

If GetUserFlag(0,10)<>0
	SendMessageToUser(#USERID,"There is already an event in progress!", #MSG_CRITICAL)
	Goto End
Else
	If MSG="kingsarena"
		SetUserFlag(0,10,-1)
		Timer(279,100,0,0,0)
		GoTo END
	EndIf
	EVENT=0
	If #MAPID=500
		EVENT=1
	ElseIf MSG="water race"
		EVENT=1
	EndIf 
	If #MAPID=452
		EVENT=2
	ElseIf MSG="forest race"
		EVENT=2
	EndIf 
	If #MAPID=550
		EVENT=3
	ElseIf MSG="death dungeon"
		EVENT=3
	EndIf 
	If #MAPID=552
		EVENT=4
	ElseIf MSG="four corners"
		EVENT=4
	EndIf 
	If #MAPID=464
		EVENT=5
	ElseIf MSG="scavenger hunt"
		EVENT=5
	EndIf 
	If #MAPID=548
		EVENT=6
	ElseIf MSG="cyber says"
		EVENT=6
	EndIf 
	If #MAPID=580
		EVENT=7
	ElseIf MSG="urban race"
		EVENT=7
	EndIf 
	If #MAPID=655
		EVENT=8
	ElseIf MSG="dance master"
		EVENT=8
	EndIf 
	If #MAPID=830
		EVENT=9
	ElseIf MSG="desert race"
		EVENT=9
	EndIf 
	If #MAPID=1188
		EVENT=10
	ElseIf MSG="fortress hunt"
		EVENT=10
	EndIf 
	
	If EVENT=1
		SetUserFlag(0,10,1)
		SetUserFlag(0,11,0)
		EventName="Water Race"
		EventStartMap=500
		Script=148
		Goto EventStart
	Endif
	If EVENT=2
		SetUserFlag(0,10,2)
		SetUserFlag(0,11,0)
		EventName="Forest Race"
		EventStartMap=452
		Script=179
		Goto EventStart
	Endif
	If EVENT=3
		SetUserFlag(0,10,3)
		SetUserFlag(0,11,0)
		EventName="Death Dungeon"
		EventStartMap=550
		Script=180
		Goto EventStart
	Endif
	If EVENT=4
		SetUserFlag(0,10,4)
		SetUserFlag(0,11,0)
		EventName="Four Corners"
		EventStartMap=552
		Script=182
		Goto EventStart
	Endif
	If EVENT=5
		SetUserFlag(0,10,5)
		SetUserFlag(0,11,0)
		EventName="Scavenger Hunt"
		EventStartMap=464
		Script=211
		Goto EventStart
	Endif	
	If EVENT=6
		SetUserFlag(0,10,6)
		SetUserFlag(0,11,0)
		EventName="Cyber Says"
		EventStartMap=548
		Script=739
		;Script=242
		Goto EventStart
	Endif
	If EVENT=7
		SetUserFlag(0,10,7)
		SetUserFlag(0,11,0)
		EventName="Urban Race"
		EventStartMap=580
		Script=253
		Goto EventStart
	Endif
	If EVENT=8
		SetUserFlag(0,10,8)
		SetUserFlag(0,11,0)
		EventName="Dance Master"
		EventStartMap=655
		Script=271
		Goto EventStart
	Endif
	If EVENT=9
		SetUserFlag(0,10,9)
		SetUserFlag(0,11,0)
		EventName="Desert Race"
		EventStartMap=830
		Script=362
		Goto EventStart
	Endif
	If EVENT=10
		SetUserFlag(0,10,10)
		SetUserFlag(0,11,0)
		EventName="Fortress Hunt"
		EventStartMap=1188
		Script=572
		Goto EventStart
	Endif

	SendMessageToUser(#USERID,"You must be in an event starting location!", #MSG_CRITICAL)
	Goto End
Endif

Label EventStart
TimeNormal=0

MSG="1"

If MSG="4"
	TimeToStart=80
	TimeUnit="minutes"
	TimeCountdown=4800000
Elseif MSG="3"
	TimeToStart=3
	TimeUnit="minutes"
	TimeCountdown=180000
Elseif MSG="2"
	TimeToStart=2
	TimeUnit="minutes"
	TimeCountdown=120000
Elseif MSG="1"
	TimeToStart=1
	TimeUnit="minute"
	TimeCountdown=60000
Else
	TimeToStart=5
	TimeUnit="minutes"
	TimeNormal=1
	TimeCountdown=300000
Endif

SendMessageToAll("The "+EventName+" will start in "+TimeToStart+" "+TimeUnit+"! Please report to the Event Center to participate.", #MSG_SERVER)

If TimeNormal=1
	Timer(149,240000,EventName,1,0)
	Timer(149,270000,EventName,2,0)
	Timer(149,290000,EventName,3,0)
	Timer(149,300000,EventName,4,0)
Else
	If TimeCountDown>60000
		Timer(149,TimeCountDown-60000,EventName,1,0)
	Endif
	Timer(149,TimeCountDown-30000,EventName,2,0)
	Timer(149,TimeCountDown-10000,EventName,3,0)
	Timer(149,TimeCountDown,EventName,4,0)
Endif

Timer(Script,TimeCountDown,EventStartMap,0,0)

If Script=180
	Goto EventStartDeathDungeon
Endif
If Script=182
	Goto EventStartFourCorners
Endif
;If Script=242
	;Goto EventStartCyberSays
;Endif

Goto End








Label EventStartDeathDungeon
Timer(180,TimeCountDown+30000,EventStartMap,4,0)
Timer(180,TimeCountDown+60000,EventStartMap,3,0)
Timer(180,TimeCountDown+90000,EventStartMap,2,0)
Timer(180,TimeCountDown+120000,EventStartMap,1,0)
Timer(180,TimeCountDown+150000,EventStartMap,0,0)
Goto End

Label EventStartFourCorners
;Timer(182,TimeCountDown+30000,EventStartMap,1,0)
;Timer(182,TimeCountDown+60000,EventStartMap,2,0)
;;Timer(182,TimeCountDown+90000,EventStartMap,3,0)
;Timer(182,TimeCountDown+120000,EventStartMap,4,0)
;Timer(182,TimeCountDown+150000,EventStartMap,5,0)
;Timer(182,TimeCountDown+180000,EventStartMap,6,0)
;Timer(182,TimeCountDown+210000,EventStartMap,7,0)
;Timer(182,TimeCountDown+240000,EventStartMap,8,0)
;Timer(182,TimeCountDown+270000,EventStartMap,9,0)
;Timer(182,TimeCountDown+300000,EventStartMap,10,0)
Goto End

Label EventStartCyberSays
Value=Random(1,5)
Timer(245,TimeCountDown+5000,Value,0,0)
Timer(243,TimeCountDown+12000,Value,0,0)
Value=Random(6,10)
Timer(245,TimeCountDown+15000,Value,0,0)
Timer(243,TimeCountDown+22000,Value,0,0)
Value=Random(11,15)
Timer(245,TimeCountDown+25000,Value,0,0)
Timer(243,TimeCountDown+32000,Value,0,0)
Value=Random(16,20)
Timer(245,TimeCountDown+35000,Value,0,0)
Timer(243,TimeCountDown+42000,Value,0,0)
Value=Random(21,25)
Timer(245,TimeCountDown+45000,Value,0,0)
Timer(243,TimeCountDown+52000,Value,0,0)
Value=Random(26,30)
Timer(245,TimeCountDown+55000,Value,0,0)
Timer(243,TimeCountDown+62000,Value,0,0)
Value=Random(31,35)
Timer(245,TimeCountDown+65000,Value,0,0)
Timer(243,TimeCountDown+72000,Value,0,0)
Value=Random(36,40)
Timer(245,TimeCountDown+75000,Value,0,0)
Timer(243,TimeCountDown+82000,Value,0,0)
Value=Random(41,45)
Timer(245,TimeCountDown+85000,Value,0,0)
Timer(243,TimeCountDown+92000,Value,0,0)
Value=Random(46,50)
Timer(245,TimeCountDown+95000,Value,0,0)
Timer(244,TimeCountDown+102000,Value,10,0)
Goto End

Label End