It may help you to implement some sort of level protocol function. A few weeks ago I did something similar - you can see the function below - but there may be some bugs (in engine_gettaskinfo(), the protocol function or my game) because it sometimes leads to errors. You can however use it as a basis for your own project and if you remove the first while(e_res) loop there won't be errors.

Click to reveal..
Code:
void level_protocol()
{
	var p_file,e_count = 0,e_res = 1;
	STRING* str_tmp;
	char* funcname;
	ENTITY* ent;
	
	sys_marker("LP1");
	str_tmp = str_create("");
	str_cpy(str_tmp,level_name);
	str_trunc(str_tmp,4);
	if(key_l) str_cat(str_tmp,"_protocol_forced.txt");
	else str_cat(str_tmp,"_protocol.txt");
	p_file = file_open_write(str_tmp);
	if(!p_file)
	{
		error("level_protocol: could not open file!");
		return;
	}
	
	sys_marker("LP2");
	file_str_write(p_file,"Functions:");
	while(e_res)
	{
		sys_marker("L2A");
		if(!engine_gettaskinfo(e_count,&funcname,&ent)) break;
		sys_marker("L2B");
		file_str_write(p_file,"\nFunction: ");
		file_var_write(p_file,e_count);
		file_str_write(p_file,"\n-name: ");
		sys_marker("L2C");
		if(funcname) file_str_write(p_file,funcname);
		sys_marker("L2D");
		file_str_write(p_file,"\n-me entity: ");
		if(ent) file_var_write(p_file,ent->link.index);
		e_count++;
	}
	sys_marker("LP3");
	file_str_write(p_file,"\nEntities:");
	e_count = 0;
	for(you = ent_next(NULL); you; you = ent_next(you))
	{
		e_count++;
		file_str_write(p_file,"\nEntity: ");
		file_var_write(p_file,e_count);
		file_str_write(p_file,"\n-filename: ");
		str_for_entfile(str_tmp,you);
		file_str_write(p_file,str_tmp);
		file_str_write(p_file,"\n-link id: ");
		file_var_write(p_file,you->link.index);
		file_str_write(p_file,"\n-link name: ");
		if(you->link.name) file_str_write(p_file,you->link.name);
		file_str_write(p_file,str_printf(NULL,"\n-pos: (%d,%d,%d)",(int)your.x,(int)your.y,(int)your.z));
		file_str_write(p_file,str_printf(NULL,"\n-pan: (%d,%d,%d)",(int)your.pan,(int)your.tilt,(int)your.roll));
		file_str_write(p_file,str_printf(NULL,"\n-scale: (%d,%d,%d)",(int)your.scale_x,(int)your.scale_y,(int)your.scale_z));
		file_str_write(p_file,str_printf(NULL,"\n-flags: (%d,%d,%d)",(int)your.eflags,(int)your.flags2,(int)your.emask));
	}
	sys_marker("LP4");
	file_str_write(p_file,"\nEntities in total: ");
	file_var_write(p_file,e_count);
	file_str_write(p_file,"\nLoading errors: ");
	file_var_write(p_file,last_error);
	file_close(p_file);
	sys_marker(NULL);
	ptr_remove(str_tmp);
}
...
on_l = level_protocol;
on_level_load = level_protocol;



"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends