;'Bandit attack' - timed call script

UserID = #PARAM1
Stats = #PARAM2
TimesCalled = #PARAM3

MAP = GetUserMap(UserID)
X = GetUserX(UserID)
Y = GetUserY(UserID)

If IsOnline(UserID) = 0
	GoTo END
EndIf

If TimesCalled > 10
	GoTo END
EndIf

GoAgain = Random(0,2)

If GetMapType(MAP) <> #MAPTYPE_FRIENDLY
	If Stats > 25
		SendMessageToMap(MAP,"Bandits attack!",#MSG_CRITICAL)
		i=0
		Max = Random(2,5)
		While i < Max
			SpawnMonster(MAP,78,X+Random(2,4),Y+Random(2,4))
			i=i+1
		Wend
	ElseIf Stats > 40
		SendMessageToMap(MAP,"Bandits attack!",#MSG_CRITICAL)
		i=0
		Max = Random(2,5)
		While i < Max
			SpawnMonster(MAP,79,X+Random(2,4),Y+Random(2,4))
			i=i+1
		Wend
	ElseIf Stats > 45
		SendMessageToMap(MAP,"Bandits attack!",#MSG_CRITICAL)
		i=0
		Max = Random(2,5)
		While i < Max
			SpawnMonster(MAP,80,X+Random(2,4),Y+Random(2,4))
			i=i+1
		Wend
	EndIf
EndIf

If GoAgain > 0
	TimeModifyer = Random(3,7)
	Timer(252,15000*TimeModifyer,UserID,Stats,TimesCalled+1)
EndIf

i = 8
While i < 16
	SetMonsterTarget(MAP,i,#PARAM1)
	i=i+1
Wend

Label END

Continue = 1