/* Jail Map Coord's parsing*/
map_cors_present(maporigin[3])
{
	if(file_exists(g_filename))
	{
		new readdata[64]
		get_mapname(g_currentmap, 31)
		new map[32], x[16], y[16], z[16], len
		for(new i = 0; i < file_size(g_filename,1) && read_file(g_filename, i, readdata, 63, len); i++)
		{
			if(equali("", readdata))
				continue

			parse(readdata, map, 31, x, 15, y, 15, z, 15)
			if(equal(map, g_currentmap))
			{
				maporigin[0] = str_to_num(x)
				maporigin[1] = str_to_num(y)
				maporigin[2] = str_to_num(z)
				g_CoordLineNum = i
				return PLUGIN_HANDLED
			}
		}
	}
	return PLUGIN_CONTINUE
}

public atac_activate(id)
{
	new sOrigin[3]
	sOrigin[0] = 130
	sOrigin[1] = 130
	sOrigin[2] = 130
	jailsave(id, sOrigin)
}

jailsave(id, origin[])
{
	if(!g_map_cors_pre)
	{
		g_CoordLineNum = check_EOF(g_filename)
		g_map_cors_pre = 1
	}
	for(new i = 0; i < 3; i++)
	{
		g_map_cors_origin[i] = origin[i]
	}
	log_amx("%i", g_CoordLineNum)
	new coord[64]
	format(coord, 63, "%s %i %i %i", g_currentmap, origin[0], origin[1], origin[2])
	write_file(g_filename, coord, g_CoordLineNum)
	client_print(id, print_chat, "[ATAC] Jail Coordinated Saved")

	if(noendblankline)
	{
		noendblankline--
		set_task(0.1, "fix_endof")
	}
}

public fix_endof()
{
	g_CoordLineNum--
}

check_dir(g_Dir[])
{
	if(!dir_exists(g_Dir))
		mkdir(g_Dir)
}

check_EOF(filename[])
{
	if(file_exists(filename))
	{
		new readdata[64], len, data[64]
		new EOF = file_size(filename,1)
		read_file(g_filename, EOF-1, readdata, 63, len)
		{
			parse(readdata, data, 63)
			if(equali("", data))
			{
				return EOF-1
			}
			else if(!equali("", data))
			{
				noendblankline = 1
				return EOF+1
			}
		}
	}
	return PLUGIN_CONTINUE
}