
;Param1 = userID
;Param2 = monsterID
;Param3 = number of spawns

UserID = #PARAM1
MonsterID = #PARAM2

If IsOnline(UserID) = 0
	;Timer(23,300000,#PARAM1,#PARAM2,0)
	GoTo END
EndIf

If GetMapType(GetUserMap(UserID)) = #MAPTYPE_FRIENDLY
	Timer(23,60000,#PARAM1,#PARAM2,#PARAM3-1)
	GoTo END
EndIf

SendMessageToAll(GetUserName(UserID)+" is being attacked by monsters!",#MSG_CRITICAL)

UserMap = GetUserMap(UserID)
UserX = GetUserX(UserID)
UserY = GetUserY(UserID)

SpawnMonster(UserMap, MonsterID, UserX+1, UserY)
SpawnMonster(UserMap, MonsterID, UserX-1, UserY)
SpawnMonster(UserMap, MonsterID, UserX, UserY+1)
SpawnMonster(UserMap, MonsterID, UserX, UserY-1)

If Floor(#PARAM2 % 5) = 1
	SpawnMonster(UserMap, MonsterID, UserX+1, UserY+1)
	SpawnMonster(UserMap, MonsterID, UserX-1, UserY+1)
	SpawnMonster(UserMap, MonsterID, UserX+1, UserY-1)
	SpawnMonster(UserMap, MonsterID, UserX-1, UserY-1)
EndIf

i = 7
While i < 15
	i = i + 1
	SetMonsterTarget(UserMap,i,UserID)
Wend

If #PARAM3 < 1
	SendMessageToUser(UserID,"You have defeated all the monsters for now... but they shall return!",#MSG_EMOTE)
	GoTo END
Else
	Timer(23,60000,#PARAM1,#PARAM2,#PARAM3-1)
EndIf

Label END

Continue = 1